Changeset 6835


Ignore:
Timestamp:
08/20/10 14:05:06 (9 years ago)
Author:
melissa
Message:

A few changes to how pixels and dimension information are found.

I'm not 100% convinced that the pixel offsets are correct in general, but dimension detection is certainly more sane now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/in/BioRadGelReader.java

    r6799 r6835  
    4545  // -- Constants -- 
    4646 
     47  private static final int MAGIC_BYTES = 0xafaf; 
     48 
    4749  private static final long PIXEL_OFFSET = 59654; 
    48   private static final long BIG_ENDIAN_OFFSET = 348; 
    49   private static final long LITTLE_ENDIAN_OFFSET = 268; 
     50  private static final long START_OFFSET = 160; 
     51  private static final long BASE_OFFSET = 352; 
    5052 
    5153  // -- Fields -- 
    5254 
    5355  private long offset; 
     56  private long diff; 
    5457 
    5558  // -- Constructor -- 
     
    6871    final int blockLen = 2; 
    6972    if (!FormatTools.validStream(stream, blockLen, false)) return false; 
    70     return (stream.readShort() & 0xffff) == 0xafaf; 
     73    return (stream.readShort() & 0xffff) == MAGIC_BYTES; 
    7174  } 
    7275 
     
    8184    int planeSize = FormatTools.getPlaneSize(this); 
    8285 
    83     if (offset > PIXEL_OFFSET) { 
    84       in.seek(offset + 1285); 
    85     } 
    86     else if (PIXEL_OFFSET + planeSize <= in.length()) { 
    87       in.seek(PIXEL_OFFSET); 
     86    if (PIXEL_OFFSET + planeSize < in.length()) { 
     87      if (diff < 0) { 
     88        in.seek(0x379d1); 
     89      } 
     90      else in.seek(PIXEL_OFFSET); 
    8891    } 
    8992    else in.seek(in.length() - planeSize); 
     
    115118    } 
    116119 
    117     long headerOffset = 
    118       in.isLittleEndian() ? LITTLE_ENDIAN_OFFSET : BIG_ENDIAN_OFFSET; 
    119  
    120     in.seek(headerOffset); 
    121     int skip = in.readInt() - 28; 
    122     headerOffset = BIG_ENDIAN_OFFSET; 
     120    in.seek(START_OFFSET); 
     121 
     122    boolean codeFound = false; 
     123    int skip = 0; 
     124 
     125    while (!codeFound) { 
     126      short code = in.readShort(); 
     127      if (code == 0x81) codeFound = true; 
     128      short length = in.readShort(); 
     129 
     130      in.skipBytes(2 + 2 * length); 
     131      if (codeFound) { 
     132        skip = (in.readShort() & 0xffff) - 32; 
     133      } 
     134      else { 
     135        if (length == 1) in.skipBytes(12); 
     136        else if (length == 2) in.skipBytes(10); 
     137      } 
     138    } 
     139 
     140    long baseFP = in.getFilePointer(); 
     141    diff = BASE_OFFSET - baseFP; 
     142    skip += diff; 
    123143 
    124144    double physicalWidth = 0d, physicalHeight = 0d; 
    125145    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) { 
    126       in.seek(headerOffset + skip - 8187); 
    127       String scannerName = in.readCString(); 
    128       in.skipBytes(8); 
    129       in.readCString(); 
    130       in.skipBytes(8); 
    131       String imageArea = in.readCString(); 
    132  
    133       scannerName = scannerName.substring(scannerName.indexOf(":") + 1).trim(); 
    134       addGlobalMeta("Scanner name", scannerName); 
    135  
    136       imageArea = imageArea.substring(imageArea.indexOf(":") + 1).trim(); 
    137       int xIndex = imageArea.indexOf("x"); 
    138       if (xIndex > 0) { 
    139         String width = imageArea.substring(1, imageArea.indexOf(" ")); 
    140         String height = 
    141           imageArea.substring(xIndex + 1, imageArea.indexOf(" ", xIndex + 2)); 
    142         physicalWidth = Double.parseDouble(width.trim()) * 1000; 
    143         physicalHeight = Double.parseDouble(height.trim()) * 1000; 
    144       } 
    145     } 
    146  
    147     in.seek(headerOffset + skip - 273); 
    148     String date = in.readCString(); 
     146      if (baseFP + skip - 8187 > 0) { 
     147        in.seek(baseFP + skip - 8187); 
     148        String scannerName = in.readCString(); 
     149        in.skipBytes(8); 
     150        in.readCString(); 
     151        in.skipBytes(8); 
     152        String imageArea = in.readCString(); 
     153 
     154        imageArea = imageArea.substring(imageArea.indexOf(":") + 1).trim(); 
     155        int xIndex = imageArea.indexOf("x"); 
     156        if (xIndex > 0) { 
     157          int space = imageArea.indexOf(" "); 
     158          if (space >= 0) { 
     159            String width = imageArea.substring(1, space); 
     160            int nextSpace = imageArea.indexOf(" ", xIndex + 2); 
     161            if (nextSpace > xIndex) { 
     162              String height = imageArea.substring(xIndex + 1, nextSpace); 
     163              physicalWidth = Double.parseDouble(width.trim()) * 1000; 
     164              physicalHeight = Double.parseDouble(height.trim()) * 1000; 
     165            } 
     166          } 
     167        } 
     168      } 
     169    } 
     170 
     171    in.seek(baseFP + skip - 298); 
     172    String date = in.readString(17); 
    149173    date = DateTools.formatDate(date, "dd-MMM-yyyy HH:mm"); 
    150  
    151     in.seek(headerOffset + skip); 
     174    in.skipBytes(73); 
     175    String scannerName = in.readCString(); 
     176    addGlobalMeta("Scanner name", scannerName); 
     177 
     178    in.seek(baseFP + skip); 
    152179 
    153180    core[0].sizeX = in.readShort() & 0xffff; 
Note: See TracChangeset for help on using the changeset viewer.