Changeset 6023


Ignore:
Timestamp:
03/11/10 16:52:20 (10 years ago)
Author:
melissa
Message:

Added a few more TiffSaver tests, and fixed bugs that prevented them from passing. See #466.

Location:
branches/cleanup/components/bio-formats
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/TiffSaver.java

    r6021 r6023  
    3131 
    3232import loci.common.ByteArrayHandle; 
     33import loci.common.DataTools; 
    3334import loci.common.RandomAccessInputStream; 
    3435import loci.common.RandomAccessOutputStream; 
     
    465466 
    466467    long offset = bigTiff ? 8 : 4; // offset to the IFD 
    467     long num = 0; // number of directory entries 
    468468 
    469469    int bytesPerEntry = bigTiff ? 
     
    480480    raf.seek(offsets[ifd]); 
    481481 
     482    // get the number of directory entries 
     483    long num = bigTiff ? raf.readLong() : raf.readUnsignedShort(); 
     484 
    482485    // search directory entries for proper tag 
    483486    for (int i=0; i<num; i++) { 
     487      raf.seek(offsets[ifd] + (bigTiff ? 8 : 2) + bytesPerEntry * i); 
     488 
    484489      TiffIFDEntry entry = parser.readTiffIFDEntry(); 
    485490      if (entry.getTag() == tag) { 
    486491        // write new value to buffers 
    487492        ByteArrayHandle ifdBuf = new ByteArrayHandle(bytesPerEntry); 
     493        RandomAccessOutputStream ifdOut = new RandomAccessOutputStream(ifdBuf); 
    488494        ByteArrayHandle extraBuf = new ByteArrayHandle(); 
    489495        RandomAccessOutputStream extraOut = 
    490496          new RandomAccessOutputStream(extraBuf); 
    491497        extraOut.order(little); 
    492         writeIFDValue(extraOut, entry.getValueOffset(), tag, value); 
     498        TiffSaver saver = new TiffSaver(ifdOut); 
     499        saver.setLittleEndian(isLittleEndian()); 
     500        saver.writeIFDValue(extraOut, entry.getValueOffset(), tag, value); 
    493501        ifdBuf.seek(0); 
    494502        extraBuf.seek(0); 
     
    536544        } 
    537545 
    538         long filePointer = raf.getFilePointer(); 
    539         raf.close(); 
    540  
    541546        // overwrite old entry 
    542         out.seek(filePointer - (bigTiff ? 18 : 10)); // jump back 
     547        out.seek(offsets[ifd] + (bigTiff ? 8 : 2) + bytesPerEntry * i + 2); 
    543548        out.writeShort(newType); 
    544549        writeIntValue(out, newCount); 
  • branches/cleanup/components/bio-formats/test/loci/formats/utests/tiff/TiffSaverTest.java

    r6020 r6023  
    5757  private TiffParser tiffParser; 
    5858 
     59  private IFD ifd; 
     60 
    5961  private static final int INITIAL_CAPACITY = 1024 * 1024;  // 1MB 
    6062 
     
    6668    tiffSaver = new TiffSaver(out); 
    6769    tiffParser = new TiffParser(in); 
     70 
     71    ifd = new IFD(); 
     72    ifd.putIFDValue(IFD.IMAGE_WIDTH, 512); 
     73    ifd.putIFDValue(IFD.IMAGE_DESCRIPTION, "comment"); 
    6874  } 
    6975 
     
    111117  } 
    112118 
     119  @Test 
     120  public void testOverwriteIFDValue() throws FormatException, IOException { 
     121    out.seek(0); 
     122    tiffSaver.setBigTiff(false); 
     123    tiffSaver.writeHeader(); 
     124    tiffSaver.writeIFD(ifd, 0); 
     125 
     126    tiffSaver.overwriteIFDValue(in, 0, IFD.IMAGE_WIDTH, 1024); 
     127    assertEquals(1024, tiffParser.getFirstIFD().getImageWidth()); 
     128  } 
     129 
     130  @Test 
     131  public void testOverwriteComment() throws FormatException, IOException { 
     132    out.seek(0); 
     133    tiffSaver.writeHeader(); 
     134    tiffSaver.writeIFD(ifd, 0); 
     135    tiffSaver.overwriteComment(in, "new comment"); 
     136    assertTrue("new comment".equals(tiffParser.getComment())); 
     137  } 
     138 
    113139} 
Note: See TracChangeset for help on using the changeset viewer.