Changeset 5619


Ignore:
Timestamp:
10/19/09 15:38:00 (10 years ago)
Author:
melissa
Message:

Fixed:

  • ZVI XML validation problems
  • LSM 4+ GB problems (modified from a patch submitted by Johannes Schindelin)
  • Various problems with the TestNG writer test.
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/components/bio-formats/src/loci/formats/in/ZeissLSMReader.java

    r5545 r5619  
    353353      s.order(isLittleEndian()); 
    354354      s.seek(0); 
    355       ifdsList.set(i, new TiffParser(s).getIFDs()); 
     355      ifdsList.set(i, new TiffParser(s).getIFDs(true)); 
    356356      s.close(); 
    357357    } 
    358  
    359     // go through the IFD hashtable arrays and 
    360     // remove anything with NEW_SUBFILE_TYPE = 1 
    361     // NEW_SUBFILE_TYPE = 1 indicates that the IFD 
    362     // contains a thumbnail image 
    363358 
    364359    status("Removing thumbnails"); 
     
    369364    for (int series=0; series<ifdsList.size(); series++) { 
    370365      IFDList ifds = ifdsList.get(series); 
    371       IFDList newIFDs = new IFDList(); 
    372366      for (int i=0; i<ifds.size(); i++) { 
    373367        IFD ifd = ifds.get(i); 
    374         long subFileType = ifd.getIFDLongValue(IFD.NEW_SUBFILE_TYPE, false, 0); 
    375  
    376         if (subFileType == 0) { 
    377           // check that predictor is set to 1 if anything other 
    378           // than LZW compression is used 
    379           if (ifd.getCompression() != TiffCompression.LZW) { 
    380             ifd.put(new Integer(IFD.PREDICTOR), new Integer(1)); 
    381           } 
    382           newIFDs.add(ifd); 
    383         } 
    384       } 
    385       ifdsList.set(series, newIFDs); 
    386       ifds = newIFDs; 
     368 
     369        // check that predictor is set to 1 if anything other 
     370        // than LZW compression is used 
     371        if (ifd.getCompression() != TiffCompression.LZW) { 
     372          ifd.put(new Integer(IFD.PREDICTOR), new Integer(1)); 
     373        } 
     374      } 
    387375 
    388376      // fix the offsets for > 4 GB files 
    389377      for (int i=1; i<ifds.size(); i++) { 
    390         long thisOffset = ifds.get(i).getStripOffsets()[0] & 0xffffffffL; 
    391         long prevOffset = ifds.get(i - 1).getStripOffsets()[0]; 
    392         if (prevOffset < 0) prevOffset &= 0xffffffffL; 
    393  
    394         if (prevOffset > thisOffset) { 
    395           thisOffset += 0xffffffffL; 
    396           ifds.get(i).put(new Integer(IFD.STRIP_OFFSETS), new Long(thisOffset)); 
     378        long[] stripOffsets = ifds.get(i).getStripOffsets(); 
     379        long[] previousStripOffsets = ifds.get(i - 1).getStripOffsets(); 
     380        boolean neededAdjustment = false; 
     381        for (int j=0; j<stripOffsets.length; j++) { 
     382          if (stripOffsets[j] < previousStripOffsets[j]) { 
     383            stripOffsets[j] = (previousStripOffsets[j] & ~0xffffffffL) | 
     384              (stripOffsets[j] & 0xffffffffL); 
     385            if (stripOffsets[j] < previousStripOffsets[j]) { 
     386              stripOffsets[j] += 0x100000000L; 
     387            } 
     388            neededAdjustment = true; 
     389          } 
     390          if (neededAdjustment) { 
     391            ifds.get(i).putIFDValue(IFD.STRIP_OFFSETS, stripOffsets); 
     392          } 
    397393        } 
    398394      } 
  • branches/4.1/components/bio-formats/src/loci/formats/in/ZeissZVIReader.java

    r5618 r5619  
    825825        else if (key.startsWith("Objective ID")) { 
    826826          store.setObjectiveID("Objective:" + value, 0, 0); 
     827          store.setObjectiveCorrection("Unknown", 0, 0); 
     828          store.setObjectiveImmersion("Unknown", 0, 0); 
    827829        } 
    828830        else if (key.startsWith("Objective N.A.")) { 
  • branches/4.1/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r5518 r5619  
    119119   */ 
    120120  public IFDList getIFDs() throws IOException { 
     121    return getIFDs(false); 
     122  } 
     123 
     124  /** 
     125   * Gets all IFDs within the TIFF file, or null 
     126   * if the input source is not a valid TIFF file. 
     127   * If 'skipThumbnails' is set to true, thumbnail IFDs will not be returned. 
     128   */ 
     129  public IFDList getIFDs(boolean skipThumbnails) throws IOException { 
    121130    // check TIFF header 
    122131    Boolean result = checkHeader(); 
     
    131140    // each IFD must have at least one directory entry, which means that 
    132141    // each IFD must be at least 2 + 12 + 4 = 18 bytes in length 
    133     long ifdMax = (in.length() - 8) / 18; 
     142    long ifdMax = (in.length() - 8) / (bigTiff ? 22 : 18); 
    134143 
    135144    // read in IFDs 
     
    137146    for (long ifdNum=0; ifdNum<ifdMax; ifdNum++) { 
    138147      IFD ifd = getIFD(ifdNum, offset, bigTiff); 
    139       if (ifd == null || ifd.size() <= 1) break; 
    140       ifds.add(ifd); 
    141       offset = bigTiff ? in.readLong() : (long) (in.readInt() & 0xffffffffL); 
     148      if (ifd == null || ifd.size() <= 2) break; 
     149      Number subfile = (Number) ifd.getIFDValue(IFD.NEW_SUBFILE_TYPE); 
     150      int subfileType = subfile == null ? 0 : subfile.intValue(); 
     151      if (!skipThumbnails || subfileType == 0) { 
     152        ifds.add(ifd); 
     153      } 
     154      else ifd = null; 
     155      offset = getNextOffset(bigTiff, offset); 
    142156      if (offset <= 0 || offset >= in.length()) { 
    143157        if (offset != 0) { 
     
    218232 
    219233      // Parse the entry's "ValueOffset" 
    220       long valueOffset = bigTiff ? in.readLong() : in.readInt(); 
     234      long valueOffset = getNextOffset(bigTiff, offset); 
    221235 
    222236      return new TiffIFDEntry(entryTag, entryType, valueCount, valueOffset); 
     
    287301 
    288302      if (count > threshhold / bpe) { 
    289         long pointer = bigTiff ? in.readLong() : 
    290           (long) (in.readInt() & 0xffffffffL); 
     303        long pointer = getNextOffset(bigTiff, 
     304          offset + baseOffset + bytesPerEntry * i); 
    291305        LogTools.debug("getIFDs: seeking to offset: " + pointer); 
    292306        in.seek(pointer); 
     
    485499    int tileNumber = (int) (row * numTileCols + col); 
    486500    byte[] tile = new byte[(int) stripByteCounts[tileNumber]]; 
    487     in.seek(stripOffsets[tileNumber] & 0xffffffffL); 
     501    in.seek(stripOffsets[tileNumber]); 
    488502    in.read(tile); 
    489503 
     
    877891  } 
    878892 
     893  /** 
     894   * Read a file offset. 
     895   * For bigTiff, a 64-bit number is read.  For other Tiffs, a 32-bit number 
     896   * is read and possibly adjusted for a possible carry-over from the previous 
     897   * offset. 
     898   */ 
     899  long getNextOffset(boolean bigTiff, long previous) throws IOException { 
     900    if (bigTiff) { 
     901      return in.readLong(); 
     902    } 
     903    long offset = (previous & ~0xffffffffL) | (in.readInt() & 0xffffffffL); 
     904    if (offset < previous) { 
     905      offset += 0x100000000L; 
     906    } 
     907    return offset; 
     908  } 
    879909} 
  • branches/4.1/components/test-suite/src/loci/tests/testng/FormatWriterTest.java

    r5617 r5619  
    9595    reader = new BufferedImageReader(); 
    9696    convertedReader = new BufferedImageReader(); 
    97     reader.setMetadataStore(MetadataTools.createOMEXMLMetadata()); 
    9897    try { 
    9998      reader.setId(id); 
     
    101100    catch (FormatException e) { LogTools.trace(e); } 
    102101    catch (IOException e) { LogTools.trace(e); } 
    103     config.setId(id); 
    104102  } 
    105103 
     
    163161    String msg = null; 
    164162    try { 
     163      reader.close(); 
     164      reader.setMetadataStore(MetadataTools.createOMEXMLMetadata()); 
     165      reader.setId(id); 
     166 
    165167      int type = reader.getPixelType(); 
    166168      if (!writer.isSupportedType(type)) { 
     
    170172      } 
    171173 
    172       /* debug */ System.out.println("id = " + id); 
     174      config.setId(id); 
    173175 
    174176      String prefix = id.substring(id.lastIndexOf(File.separator) + 1, 
     
    185187      writer.close(); 
    186188      writer.setMetadataRetrieve((MetadataRetrieve) meta); 
    187       /* debug */ System.out.println("metadata says there are " + meta.getImageCount() + " series"); 
    188189 
    189190      // convert the input file 
     
    210211      boolean seriesMatch = 
    211212        convertedReader.getSeriesCount() == config.getNumSeries(); 
     213 
     214      boolean expectRGB = config.isRGB(); 
     215      int expectedCount = 
     216        config.getZ() * config.getT() * (expectRGB ? 1 : config.getC()); 
     217      boolean imageMatch = convertedReader.getImageCount() == expectedCount; 
     218 
    212219      if (!seriesMatch && writer.canDoStacks()) { 
    213         success = false; 
    214         msg = "Series counts do not match (found " + 
    215           convertedReader.getSeriesCount() + ", expected " + 
    216           config.getNumSeries() + ")"; 
     220        int totalImages = 0; 
     221        for (int i=0; i<reader.getSeriesCount(); i++) { 
     222          reader.setSeries(i); 
     223          totalImages += reader.getImageCount(); 
     224        } 
     225        reader.setSeries(0); 
     226        if (convertedReader.getImageCount() != totalImages) { 
     227          success = false; 
     228          msg = "Series counts do not match (found " + 
     229            convertedReader.getSeriesCount() + ", expected " + 
     230            config.getNumSeries() + ")"; 
     231        } 
     232        else imageMatch = true; 
    217233      } 
    218234      if (success) { 
    219235        for (int series=0; series<seriesCount; series++) { 
     236          if (series >= convertedReader.getSeriesCount()) { 
     237            break; 
     238          } 
    220239          convertedReader.setSeries(series); 
    221240          config.setSeries(series); 
     
    223242          int expectedX = config.getX(); 
    224243          int expectedY = config.getY(); 
    225           boolean expectRGB = config.isRGB(); 
     244          expectRGB = config.isRGB(); 
    226245          if (TestTools.shortClassName(writer).equals("OMEXMLWriter")) { 
    227246            expectRGB = false; 
     
    232251 
    233252          int expectedPixelType = config.getPixelType(); 
    234           int expectedCount = 
     253          expectedCount = 
    235254            config.getZ() * config.getT() * (expectRGB ? 1 : config.getC()); 
    236255 
     
    250269          if (msg == null) msg = checkMismatch(x, expectedX, series, "X"); 
    251270          if (msg == null) msg = checkMismatch(y, expectedY, series, "Y"); 
    252           if (msg == null && writer.canDoStacks()) { 
     271          if (msg == null && writer.canDoStacks() && !imageMatch) { 
    253272            msg = checkMismatch(count, expectedCount, series, "Image count"); 
    254273          } 
  • trunk/components/bio-formats/src/loci/formats/in/ZeissLSMReader.java

    r5545 r5619  
    353353      s.order(isLittleEndian()); 
    354354      s.seek(0); 
    355       ifdsList.set(i, new TiffParser(s).getIFDs()); 
     355      ifdsList.set(i, new TiffParser(s).getIFDs(true)); 
    356356      s.close(); 
    357357    } 
    358  
    359     // go through the IFD hashtable arrays and 
    360     // remove anything with NEW_SUBFILE_TYPE = 1 
    361     // NEW_SUBFILE_TYPE = 1 indicates that the IFD 
    362     // contains a thumbnail image 
    363358 
    364359    status("Removing thumbnails"); 
     
    369364    for (int series=0; series<ifdsList.size(); series++) { 
    370365      IFDList ifds = ifdsList.get(series); 
    371       IFDList newIFDs = new IFDList(); 
    372366      for (int i=0; i<ifds.size(); i++) { 
    373367        IFD ifd = ifds.get(i); 
    374         long subFileType = ifd.getIFDLongValue(IFD.NEW_SUBFILE_TYPE, false, 0); 
    375  
    376         if (subFileType == 0) { 
    377           // check that predictor is set to 1 if anything other 
    378           // than LZW compression is used 
    379           if (ifd.getCompression() != TiffCompression.LZW) { 
    380             ifd.put(new Integer(IFD.PREDICTOR), new Integer(1)); 
    381           } 
    382           newIFDs.add(ifd); 
    383         } 
    384       } 
    385       ifdsList.set(series, newIFDs); 
    386       ifds = newIFDs; 
     368 
     369        // check that predictor is set to 1 if anything other 
     370        // than LZW compression is used 
     371        if (ifd.getCompression() != TiffCompression.LZW) { 
     372          ifd.put(new Integer(IFD.PREDICTOR), new Integer(1)); 
     373        } 
     374      } 
    387375 
    388376      // fix the offsets for > 4 GB files 
    389377      for (int i=1; i<ifds.size(); i++) { 
    390         long thisOffset = ifds.get(i).getStripOffsets()[0] & 0xffffffffL; 
    391         long prevOffset = ifds.get(i - 1).getStripOffsets()[0]; 
    392         if (prevOffset < 0) prevOffset &= 0xffffffffL; 
    393  
    394         if (prevOffset > thisOffset) { 
    395           thisOffset += 0xffffffffL; 
    396           ifds.get(i).put(new Integer(IFD.STRIP_OFFSETS), new Long(thisOffset)); 
     378        long[] stripOffsets = ifds.get(i).getStripOffsets(); 
     379        long[] previousStripOffsets = ifds.get(i - 1).getStripOffsets(); 
     380        boolean neededAdjustment = false; 
     381        for (int j=0; j<stripOffsets.length; j++) { 
     382          if (stripOffsets[j] < previousStripOffsets[j]) { 
     383            stripOffsets[j] = (previousStripOffsets[j] & ~0xffffffffL) | 
     384              (stripOffsets[j] & 0xffffffffL); 
     385            if (stripOffsets[j] < previousStripOffsets[j]) { 
     386              stripOffsets[j] += 0x100000000L; 
     387            } 
     388            neededAdjustment = true; 
     389          } 
     390          if (neededAdjustment) { 
     391            ifds.get(i).putIFDValue(IFD.STRIP_OFFSETS, stripOffsets); 
     392          } 
    397393        } 
    398394      } 
  • trunk/components/bio-formats/src/loci/formats/in/ZeissZVIReader.java

    r5618 r5619  
    825825        else if (key.startsWith("Objective ID")) { 
    826826          store.setObjectiveID("Objective:" + value, 0, 0); 
     827          store.setObjectiveCorrection("Unknown", 0, 0); 
     828          store.setObjectiveImmersion("Unknown", 0, 0); 
    827829        } 
    828830        else if (key.startsWith("Objective N.A.")) { 
  • trunk/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r5518 r5619  
    119119   */ 
    120120  public IFDList getIFDs() throws IOException { 
     121    return getIFDs(false); 
     122  } 
     123 
     124  /** 
     125   * Gets all IFDs within the TIFF file, or null 
     126   * if the input source is not a valid TIFF file. 
     127   * If 'skipThumbnails' is set to true, thumbnail IFDs will not be returned. 
     128   */ 
     129  public IFDList getIFDs(boolean skipThumbnails) throws IOException { 
    121130    // check TIFF header 
    122131    Boolean result = checkHeader(); 
     
    131140    // each IFD must have at least one directory entry, which means that 
    132141    // each IFD must be at least 2 + 12 + 4 = 18 bytes in length 
    133     long ifdMax = (in.length() - 8) / 18; 
     142    long ifdMax = (in.length() - 8) / (bigTiff ? 22 : 18); 
    134143 
    135144    // read in IFDs 
     
    137146    for (long ifdNum=0; ifdNum<ifdMax; ifdNum++) { 
    138147      IFD ifd = getIFD(ifdNum, offset, bigTiff); 
    139       if (ifd == null || ifd.size() <= 1) break; 
    140       ifds.add(ifd); 
    141       offset = bigTiff ? in.readLong() : (long) (in.readInt() & 0xffffffffL); 
     148      if (ifd == null || ifd.size() <= 2) break; 
     149      Number subfile = (Number) ifd.getIFDValue(IFD.NEW_SUBFILE_TYPE); 
     150      int subfileType = subfile == null ? 0 : subfile.intValue(); 
     151      if (!skipThumbnails || subfileType == 0) { 
     152        ifds.add(ifd); 
     153      } 
     154      else ifd = null; 
     155      offset = getNextOffset(bigTiff, offset); 
    142156      if (offset <= 0 || offset >= in.length()) { 
    143157        if (offset != 0) { 
     
    218232 
    219233      // Parse the entry's "ValueOffset" 
    220       long valueOffset = bigTiff ? in.readLong() : in.readInt(); 
     234      long valueOffset = getNextOffset(bigTiff, offset); 
    221235 
    222236      return new TiffIFDEntry(entryTag, entryType, valueCount, valueOffset); 
     
    287301 
    288302      if (count > threshhold / bpe) { 
    289         long pointer = bigTiff ? in.readLong() : 
    290           (long) (in.readInt() & 0xffffffffL); 
     303        long pointer = getNextOffset(bigTiff, 
     304          offset + baseOffset + bytesPerEntry * i); 
    291305        LogTools.debug("getIFDs: seeking to offset: " + pointer); 
    292306        in.seek(pointer); 
     
    485499    int tileNumber = (int) (row * numTileCols + col); 
    486500    byte[] tile = new byte[(int) stripByteCounts[tileNumber]]; 
    487     in.seek(stripOffsets[tileNumber] & 0xffffffffL); 
     501    in.seek(stripOffsets[tileNumber]); 
    488502    in.read(tile); 
    489503 
     
    877891  } 
    878892 
     893  /** 
     894   * Read a file offset. 
     895   * For bigTiff, a 64-bit number is read.  For other Tiffs, a 32-bit number 
     896   * is read and possibly adjusted for a possible carry-over from the previous 
     897   * offset. 
     898   */ 
     899  long getNextOffset(boolean bigTiff, long previous) throws IOException { 
     900    if (bigTiff) { 
     901      return in.readLong(); 
     902    } 
     903    long offset = (previous & ~0xffffffffL) | (in.readInt() & 0xffffffffL); 
     904    if (offset < previous) { 
     905      offset += 0x100000000L; 
     906    } 
     907    return offset; 
     908  } 
    879909} 
  • trunk/components/test-suite/src/loci/tests/testng/FormatWriterTest.java

    r5614 r5619  
    9595    reader = new BufferedImageReader(); 
    9696    convertedReader = new BufferedImageReader(); 
    97     reader.setMetadataStore(MetadataTools.createOMEXMLMetadata()); 
    9897    try { 
    9998      reader.setId(id); 
     
    101100    catch (FormatException e) { LogTools.trace(e); } 
    102101    catch (IOException e) { LogTools.trace(e); } 
    103     config.setId(id); 
    104102  } 
    105103 
     
    163161    String msg = null; 
    164162    try { 
     163      reader.close(); 
     164      reader.setMetadataStore(MetadataTools.createOMEXMLMetadata()); 
     165      reader.setId(id); 
     166 
    165167      int type = reader.getPixelType(); 
    166168      if (!writer.isSupportedType(type)) { 
     
    170172      } 
    171173 
    172       /* debug */ System.out.println("id = " + id); 
     174      config.setId(id); 
    173175 
    174176      String prefix = id.substring(id.lastIndexOf(File.separator) + 1, 
     
    185187      writer.close(); 
    186188      writer.setMetadataRetrieve((MetadataRetrieve) meta); 
    187       /* debug */ System.out.println("metadata says there are " + meta.getImageCount() + " series"); 
    188189 
    189190      // convert the input file 
     
    210211      boolean seriesMatch = 
    211212        convertedReader.getSeriesCount() == config.getNumSeries(); 
     213 
     214      boolean expectRGB = config.isRGB(); 
     215      int expectedCount = 
     216        config.getZ() * config.getT() * (expectRGB ? 1 : config.getC()); 
     217      boolean imageMatch = convertedReader.getImageCount() == expectedCount; 
     218 
    212219      if (!seriesMatch && writer.canDoStacks()) { 
    213         success = false; 
    214         msg = "Series counts do not match (found " + 
    215           convertedReader.getSeriesCount() + ", expected " + 
    216           config.getNumSeries() + ")"; 
     220        int totalImages = 0; 
     221        for (int i=0; i<reader.getSeriesCount(); i++) { 
     222          reader.setSeries(i); 
     223          totalImages += reader.getImageCount(); 
     224        } 
     225        reader.setSeries(0); 
     226        if (convertedReader.getImageCount() != totalImages) { 
     227          success = false; 
     228          msg = "Series counts do not match (found " + 
     229            convertedReader.getSeriesCount() + ", expected " + 
     230            config.getNumSeries() + ")"; 
     231        } 
     232        else imageMatch = true; 
    217233      } 
    218234      if (success) { 
    219235        for (int series=0; series<seriesCount; series++) { 
     236          if (series >= convertedReader.getSeriesCount()) { 
     237            break; 
     238          } 
    220239          convertedReader.setSeries(series); 
    221240          config.setSeries(series); 
     
    223242          int expectedX = config.getX(); 
    224243          int expectedY = config.getY(); 
    225           boolean expectRGB = config.isRGB(); 
     244          expectRGB = config.isRGB(); 
    226245          if (TestTools.shortClassName(writer).equals("OMEXMLWriter")) { 
    227246            expectRGB = false; 
     
    232251 
    233252          int expectedPixelType = config.getPixelType(); 
    234           int expectedCount = 
     253          expectedCount = 
    235254            config.getZ() * config.getT() * (expectRGB ? 1 : config.getC()); 
    236255 
     
    250269          if (msg == null) msg = checkMismatch(x, expectedX, series, "X"); 
    251270          if (msg == null) msg = checkMismatch(y, expectedY, series, "Y"); 
    252           if (msg == null && writer.canDoStacks()) { 
     271          if (msg == null && writer.canDoStacks() && !imageMatch) { 
    253272            msg = checkMismatch(count, expectedCount, series, "Image count"); 
    254273          } 
Note: See TracChangeset for help on using the changeset viewer.