Changeset 6018 for branches/cleanup


Ignore:
Timestamp:
03/10/10 14:11:05 (10 years ago)
Author:
melissa
Message:

TiffParser.getFirstOffset() no longer assumes that TiffParser.checkHeader() has been called first.

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

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/bio-formats/src/loci/formats/in/FlexReader.java

    r5988 r6018  
    10191019          // TiffParser.getIFDOffsets() could be used instead, but is 
    10201020          // substantially slower. 
    1021           tp.checkHeader(); 
    10221021          offsets[row][col][0] = tp.getFirstOffset(); 
    10231022          if (offsets[row][col].length > 1) { 
  • branches/cleanup/components/bio-formats/src/loci/formats/out/TiffWriter.java

    r5958 r6018  
    136136        // compute the offset to the last IFD 
    137137        TiffParser tiffParser = new TiffParser(tmp); 
    138         tiffParser.checkHeader(); 
    139138        long offset = tiffParser.getFirstOffset(); 
    140139        long ifdMax = (tmp.length() - 8) / 18; 
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r5988 r6018  
    218218  public long[] getIFDOffsets() throws IOException { 
    219219    // check TIFF header 
    220     Boolean result = checkHeader(); 
    221     if (result == null) return null; 
    222  
    223220    int bytesPerEntry = bigTiff ? TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : 
    224221      TiffConstants.BYTES_PER_ENTRY; 
     
    247244   */ 
    248245  public IFD getFirstIFD() throws IOException { 
    249     // check TIFF header 
    250     Boolean result = checkHeader(); 
    251     if (result == null) return null; 
    252  
    253246    long offset = getFirstOffset(); 
    254247    return getIFD(offset); 
     
    266259  //        loci.formats.in.MetamorphReader. 
    267260  public TiffIFDEntry getFirstIFDEntry(int tag) throws IOException { 
    268     // First lets re-position the file pointer by checking the TIFF header 
    269     Boolean result = checkHeader(); 
    270     if (result == null) return null; 
    271  
    272261    // Get the offset of the first IFD 
    273262    long offset = getFirstOffset(); 
     263    if (offset < 0) return null; 
    274264 
    275265    // The following loosely resembles the logic of getIFD()... 
     
    293283  /** 
    294284   * Gets offset to the first IFD, or -1 if stream is not TIFF. 
    295    * Assumes the stream is positioned properly (checkHeader just called). 
    296285   */ 
    297286  public long getFirstOffset() throws IOException { 
     287    Boolean header = checkHeader(); 
     288    if (header == null) return -1; 
    298289    if (bigTiff) in.skipBytes(4); 
    299290    return getNextOffset(0); 
     
    302293  /** Gets the IFD stored at the given offset.  */ 
    303294  public IFD getIFD(long offset) throws IOException { 
     295    if (offset < 0) return null; 
    304296    IFD ifd = new IFD(); 
    305297 
  • branches/cleanup/components/bio-formats/test/loci/formats/utests/tiff/TiffParserTest.java

    r6014 r6018  
    7070  @Test 
    7171  public void testFirstOffset() throws IOException { 
    72     // TODO: Must be called first 
    73     assertTrue(tiffParser.checkHeader()); 
    7472    assertEquals(8, tiffParser.getFirstOffset()); 
    7573  } 
     
    7775  @Test 
    7876  public void testGetPhotoInterp() throws IOException, FormatException { 
    79     // TODO: Must be called first 
    80     assertTrue(tiffParser.checkHeader()); 
    8177    assertEquals(PhotoInterp.RGB, 
    8278                 tiffParser.getFirstIFD().getPhotometricInterpretation()); 
     
    8581  @Test 
    8682  public void testGetImageLength() throws IOException, FormatException { 
    87     // TODO: Must be called first 
    88     assertTrue(tiffParser.checkHeader()); 
    8983    assertEquals(mock.getImageLength(), 
    9084                 tiffParser.getFirstIFD().getImageLength()); 
     
    9387  @Test 
    9488  public void testGetImageWidth() throws IOException, FormatException { 
    95     // TODO: Must be called first 
    96     assertTrue(tiffParser.checkHeader()); 
    97     assertEquals(mock.getImageWidth(), 
    98                  tiffParser.getFirstIFD().getImageWidth()); 
     89    assertEquals(mock.getImageWidth(), tiffParser.getFirstIFD().getImageWidth()); 
    9990  } 
    10091 
    10192  @Test 
    10293  public void testGetBitsPerSample() throws IOException, FormatException { 
    103     // TODO: Must be called first 
    104     assertTrue(tiffParser.checkHeader()); 
    10594    int[] bitsPerSample = tiffParser.getFirstIFD().getBitsPerSample(); 
    10695    assertNotNull(bitsPerSample); 
     
    119108  @Test 
    120109  public void testGetSamplesPerPixel() throws IOException, FormatException { 
    121     // TODO: Must be called first 
    122     assertTrue(tiffParser.checkHeader()); 
    123110    assertEquals(mock.getSamplesPerPixel(), 
    124111                 tiffParser.getFirstIFD().getSamplesPerPixel()); 
     
    127114  @Test 
    128115  public void testGetStripOffsets() throws IOException, FormatException { 
    129     // TODO: Must be called first 
    130     assertTrue(tiffParser.checkHeader()); 
    131116    long[] stripOffsets = tiffParser.getFirstIFD().getStripOffsets(); 
    132117    assertNotNull(stripOffsets); 
     
    145130  @Test 
    146131  public void testGetRowsPerStrip() throws IOException, FormatException { 
    147     // TODO: Must be called first 
    148     assertTrue(tiffParser.checkHeader()); 
    149132    long[] rowsPerStrip = tiffParser.getFirstIFD().getRowsPerStrip(); 
    150133    assertNotNull(rowsPerStrip); 
     
    163146  @Test 
    164147  public void testGetXResolution() throws IOException, FormatException { 
    165     // TODO: Must be called first 
    166     assertTrue(tiffParser.checkHeader()); 
    167148    int tag = IFD.X_RESOLUTION; 
    168149    assertTrue(mock.getXResolution().equals( 
     
    172153  @Test 
    173154  public void testGetYResolution() throws IOException, FormatException { 
    174     // TODO: Must be called first 
    175     assertTrue(tiffParser.checkHeader()); 
    176155    int tag = IFD.Y_RESOLUTION; 
    177156    assertTrue(mock.getYResolution().equals( 
     
    181160  @Test 
    182161  public void testGetResolutionUnit() throws IOException, FormatException { 
    183     // TODO: Must be called first 
    184     assertTrue(tiffParser.checkHeader()); 
    185162    int tag = IFD.RESOLUTION_UNIT; 
    186163    assertEquals(mock.getResolutionUnit(), 
Note: See TracChangeset for help on using the changeset viewer.