Changeset 7500


Ignore:
Timestamp:
01/11/11 12:39:59 (9 years ago)
Author:
melissa
Message:

Search more thoroughly for image descriptions.

Image descriptions are no longer required to use the same marker.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2/components/bio-formats/src/loci/formats/in/TillVisionReader.java

    r7279 r7500  
    6262  private static final byte[] MARKER_0 = new byte[] {(byte) 0x80, 3, 0}; 
    6363  private static final byte[] MARKER_1 = new byte[] {(byte) 0x81, 3, 0}; 
     64  private static final byte[] MARKER_2 = 
     65    new byte[] {0x43, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x03, 0x00}; 
    6466 
    6567  private static final String[] DATE_FORMATS = new String[] { 
     
    240242        } 
    241243 
    242         byte[] marker = getMarker(s); 
    243         if (marker == null) { 
    244           throw new FormatException("Could not find known marker."); 
    245         } 
    246         LOGGER.debug("Marker: {}, {}, {}", 
    247           new Object[] {marker[0], marker[1], marker[2]}); 
    248244        s.seek(0); 
    249245 
     
    251247          LOGGER.debug("  Looking for image at {}", s.getFilePointer()); 
    252248          s.order(false); 
    253           int nextOffset = findNextOffset(s, marker); 
     249          int nextOffset = findNextOffset(s); 
    254250          if (nextOffset < 0 || nextOffset >= s.length()) break; 
    255251          s.seek(nextOffset); 
     
    258254          if (len <= 0) continue; 
    259255          imageNames.add(s.readString(len)); 
     256          if (s.getFilePointer() + 8 >= s.length()) break; 
    260257          s.skipBytes(6); 
    261258          s.order(true); 
     
    481478  } 
    482479 
    483   private byte[] getMarker(RandomAccessInputStream s) throws IOException { 
    484     s.seek(0); 
    485     int offset = findNextOffset(s, MARKER_0); 
    486     if (offset != -1) return MARKER_0; 
    487     s.seek(0); 
    488     offset = findNextOffset(s, MARKER_1); 
    489     return offset == -1 ? null : MARKER_1; 
     480  private int findNextOffset(RandomAccessInputStream s) throws IOException { 
     481    long fp = s.getFilePointer(); 
     482    int offset0 = findNextOffset(s, MARKER_0); 
     483    s.seek(fp); 
     484    int offset1 = findNextOffset(s, MARKER_1); 
     485    s.seek(fp); 
     486    int offset2 = findNextOffset(s, MARKER_2); 
     487 
     488    if (offset0 < 0) offset0 = Integer.MAX_VALUE; 
     489    if (offset1 < 0) offset1 = Integer.MAX_VALUE; 
     490    if (offset2 < 0) offset2 = Integer.MAX_VALUE; 
     491 
     492    if (offset0 < offset1 && offset0 < offset2) { 
     493      return offset0; 
     494    } 
     495    if (offset1 < offset0 && offset1 < offset2) { 
     496      return offset1; 
     497    } 
     498    if (offset2 < offset1 && offset2 < offset0) { 
     499      return offset2; 
     500    } 
     501    return -1; 
    490502  } 
    491503 
  • trunk/components/bio-formats/src/loci/formats/in/TillVisionReader.java

    r7125 r7500  
    6262  private static final byte[] MARKER_0 = new byte[] {(byte) 0x80, 3, 0}; 
    6363  private static final byte[] MARKER_1 = new byte[] {(byte) 0x81, 3, 0}; 
     64  private static final byte[] MARKER_2 = 
     65    new byte[] {0x43, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x03, 0x00}; 
    6466 
    6567  private static final String[] DATE_FORMATS = new String[] { 
     
    240242        } 
    241243 
    242         byte[] marker = getMarker(s); 
    243         if (marker == null) { 
    244           throw new FormatException("Could not find known marker."); 
    245         } 
    246         LOGGER.debug("Marker: {}, {}, {}", 
    247           new Object[] {marker[0], marker[1], marker[2]}); 
    248244        s.seek(0); 
    249245 
     
    251247          LOGGER.debug("  Looking for image at {}", s.getFilePointer()); 
    252248          s.order(false); 
    253           int nextOffset = findNextOffset(s, marker); 
     249          int nextOffset = findNextOffset(s); 
    254250          if (nextOffset < 0 || nextOffset >= s.length()) break; 
    255251          s.seek(nextOffset); 
     
    258254          if (len <= 0) continue; 
    259255          imageNames.add(s.readString(len)); 
     256          if (s.getFilePointer() + 8 >= s.length()) break; 
    260257          s.skipBytes(6); 
    261258          s.order(true); 
     
    481478  } 
    482479 
    483   private byte[] getMarker(RandomAccessInputStream s) throws IOException { 
    484     s.seek(0); 
    485     int offset = findNextOffset(s, MARKER_0); 
    486     if (offset != -1) return MARKER_0; 
    487     s.seek(0); 
    488     offset = findNextOffset(s, MARKER_1); 
    489     return offset == -1 ? null : MARKER_1; 
     480  private int findNextOffset(RandomAccessInputStream s) throws IOException { 
     481    long fp = s.getFilePointer(); 
     482    int offset0 = findNextOffset(s, MARKER_0); 
     483    s.seek(fp); 
     484    int offset1 = findNextOffset(s, MARKER_1); 
     485    s.seek(fp); 
     486    int offset2 = findNextOffset(s, MARKER_2); 
     487 
     488    if (offset0 < 0) offset0 = Integer.MAX_VALUE; 
     489    if (offset1 < 0) offset1 = Integer.MAX_VALUE; 
     490    if (offset2 < 0) offset2 = Integer.MAX_VALUE; 
     491 
     492    if (offset0 < offset1 && offset0 < offset2) { 
     493      return offset0; 
     494    } 
     495    if (offset1 < offset0 && offset1 < offset2) { 
     496      return offset1; 
     497    } 
     498    if (offset2 < offset1 && offset2 < offset0) { 
     499      return offset2; 
     500    } 
     501    return -1; 
    490502  } 
    491503 
Note: See TracChangeset for help on using the changeset viewer.