Changeset 6976


Ignore:
Timestamp:
09/23/10 10:36:08 (9 years ago)
Author:
melissa
Message:

Several fixes for writing BigTIFFs and multi-series OME-TIFFs. Closes #554.

Location:
trunk/components/bio-formats/src/loci/formats
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/out/OMETiffWriter.java

    r6881 r6976  
    8181  private OMEXMLMetadata omeMeta; 
    8282  private OMEXMLService service; 
     83  private HashMap<String, Integer> ifdCounts = new HashMap<String, Integer>(); 
    8384 
    8485  // -- Constructor -- 
     
    139140        omeMeta = null; 
    140141        service = null; 
     142        ifdCounts.clear(); 
    141143      } 
    142144    } 
     
    303305    sizeC /= samplesPerPixel.getValue(); 
    304306 
    305     HashMap<String, Integer> ifdCounts = new HashMap<String, Integer>(); 
    306  
    307307    for (int plane=0; plane<imageCount; plane++) { 
    308308      int[] zct = FormatTools.getZCTCoords(dimensionOrder, 
  • trunk/components/bio-formats/src/loci/formats/out/TiffWriter.java

    r6881 r6976  
    6161  protected boolean isBigTiff; 
    6262 
     63  /** Whether or not we are writing planes sequentially. */ 
     64  protected boolean sequential; 
     65 
    6366  /** The TiffSaver that will do most of the writing. */ 
    6467  protected TiffSaver tiffSaver; 
     
    116119 
    117120    tiffSaver = new TiffSaver(out); 
     121    tiffSaver.setWritingSequentially(sequential); 
    118122    tiffSaver.setLittleEndian(littleEndian); 
    119123    tiffSaver.setBigTiff(isBigTiff); 
     
    180184    ifd.putIFDValue(IFD.PLANAR_CONFIGURATION, interleaved ? 1 : 2); 
    181185    RandomAccessInputStream in = new RandomAccessInputStream(currentId); 
     186    in.order(littleEndian); 
    182187    tiffSaver.setInputStream(in); 
    183     tiffSaver.writeImage(buf, ifd, no, type, x, y, w, h, 
    184       no == getPlaneCount() - 1); 
     188 
     189    int index = no; 
     190    int realSeries = getSeries(); 
     191    for (int i=0; i<realSeries; i++) { 
     192      setSeries(i); 
     193      index += getPlaneCount(); 
     194    } 
     195    setSeries(realSeries); 
     196 
     197    tiffSaver.writeImage(buf, ifd, index, type, x, y, w, h, 
     198      no == getPlaneCount() - 1 && getSeries() == retrieve.getImageCount() - 1); 
    185199    tiffSaver.setInputStream(null); 
    186200    in.close(); 
     
    238252  } 
    239253 
     254  /** 
     255   * Sets whether or not we know that planes will be written sequentially. 
     256   * If planes are written sequentially and this flag is set, then performance 
     257   * will be slightly improved. 
     258   */ 
     259  public void setWriteSequentially(boolean sequential) { 
     260    this.sequential = sequential; 
     261  } 
     262 
    240263} 
  • trunk/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r6881 r6976  
    8888    this.in = in; 
    8989    doCaching = true; 
     90    isValidHeader(); 
    9091  } 
    9192 
  • trunk/components/bio-formats/src/loci/formats/tiff/TiffSaver.java

    r6881 r6976  
    6868  /** Whether or not to write BigTIFF data. */ 
    6969  private boolean bigTiff = false; 
     70  private boolean sequentialWrite = false; 
    7071 
    7172  // -- Constructors -- 
     
    8586 
    8687  // -- TiffSaver methods -- 
     88 
     89  /** 
     90   * Sets whether or not we know that the planes will be written sequentially. 
     91   * If we are writing planes sequentially and set this flag, then performance 
     92   * is slightly improved. 
     93   */ 
     94  public void setWritingSequentially(boolean sequential) { 
     95    sequentialWrite = sequential; 
     96  } 
    8797 
    8898  /** Sets the input stream. */ 
     
    250260    } 
    251261 
    252     TiffParser parser = new TiffParser(in); 
    253     long[] ifdOffsets = parser.getIFDOffsets(); 
    254     if (no < ifdOffsets.length) { 
    255       out.seek(ifdOffsets[no]); 
    256       ifd = parser.getIFD(ifdOffsets[no]); 
     262    if (!sequentialWrite) { 
     263      TiffParser parser = new TiffParser(in); 
     264      long[] ifdOffsets = parser.getIFDOffsets(); 
     265      if (no < ifdOffsets.length) { 
     266        out.seek(ifdOffsets[no]); 
     267        ifd = parser.getIFD(ifdOffsets[no]); 
     268      } 
    257269    } 
    258270 
     
    323335      writeIFDValue(extraStream, ifdBytes + fp, key.intValue(), value); 
    324336    } 
     337    if (bigTiff) out.seek(out.getFilePointer() - 8); 
    325338    writeIntValue(out, nextOffset); 
    326339    out.write(extra.getBytes(), 0, (int) extra.length()); 
  • trunk/components/bio-formats/src/loci/formats/tools/ImageConverter.java

    r6881 r6976  
    218218    if (writer instanceof TiffWriter) { 
    219219      ((TiffWriter) writer).setBigTiff(bigtiff); 
     220      ((TiffWriter) writer).setWriteSequentially(true); 
    220221    } 
    221222    else if (writer instanceof ImageWriter) { 
     
    223224      if (w instanceof TiffWriter) { 
    224225        ((TiffWriter) w).setBigTiff(bigtiff); 
     226        ((TiffWriter) w).setWriteSequentially(true); 
    225227      } 
    226228    } 
Note: See TracChangeset for help on using the changeset viewer.