Changeset 6127


Ignore:
Timestamp:
04/14/10 16:47:47 (10 years ago)
Author:
melissa
Message:

Updated a few more readers to respect MetadataOptions.

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

Legend:

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

    r6055 r6127  
    2525 
    2626import java.io.IOException; 
    27 import java.util.StringTokenizer; 
     27import java.util.Arrays; 
    2828 
    2929import loci.common.RandomAccessInputStream; 
     
    9595    String tz = null, tc = null, tt = null; 
    9696    if (comment != null) { 
    97       StringTokenizer st = new StringTokenizer(comment, "\n"); 
    98       while (st.hasMoreTokens()) { 
    99         String line = st.nextToken(); 
     97      String[] lines = comment.split("\n"); 
     98      for (String line : lines) { 
    10099        int equals = line.indexOf("="); 
    101100        if (equals < 0) continue; 
     
    119118    } 
    120119 
    121     if (tz == null) tz = "1"; 
    122     if (tc == null) tc = "1"; 
    123     if (tt == null) tt = "1"; 
    124  
    125120    core[0].sizeT = 1; 
    126121    if (getSizeZ() == 0) core[0].sizeZ = 1; 
    127122    if (getSizeC() == 0) core[0].sizeC = 1; 
    128123 
    129     core[0].sizeZ *= Integer.parseInt(tz); 
    130     core[0].sizeC *= Integer.parseInt(tc); 
    131     core[0].sizeT *= Integer.parseInt(tt); 
     124    if (tz != null) core[0].sizeZ *= Integer.parseInt(tz); 
     125    if (tc != null) core[0].sizeC *= Integer.parseInt(tc); 
     126    if (tt != null) core[0].sizeT *= Integer.parseInt(tt); 
    132127 
    133128    if (getSizeZ() * getSizeC() * getSizeT() < getImageCount()) { 
     
    143138 
    144139    for (int i=0; i<ifds.size(); i++) { 
     140      Arrays.fill(coords[i], -1); 
    145141      comment = ifds.get(i).getComment(); 
    146142      comment = comment.replaceAll("\r\n", "\n"); 
    147143      comment = comment.replaceAll("\r", "\n"); 
    148       StringTokenizer st = new StringTokenizer(comment, "\n"); 
    149144      String channelName = null; 
    150       while (st.hasMoreTokens()) { 
    151         String line = st.nextToken(); 
     145      String[] lines = comment.split("\n"); 
     146      for (String line : lines) { 
    152147        int equals = line.indexOf("="); 
    153148        if (equals < 0) continue; 
     
    172167          if (cNames[ndx] == null) cNames[ndx] = channelName; 
    173168        } 
    174       } 
    175     } 
    176     // determine average time per plane 
    177  
    178     long sum = 0; 
    179     for (int i=1; i<stamps.length; i++) { 
    180       long diff = stamps[i] - stamps[i - 1]; 
    181       if (diff > 0) sum += diff; 
    182     } 
    183     pixelSizeT = (int) (sum / getSizeT()); 
     169 
     170        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.ALL && 
     171          coords[i][0] >= 0 && coords[i][1] >= 0 && coords[i][2] >= 0) 
     172        { 
     173          break; 
     174        } 
     175      } 
     176    } 
     177 
     178    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.ALL) { 
     179      // determine average time per plane 
     180 
     181      long sum = 0; 
     182      for (int i=1; i<stamps.length; i++) { 
     183        long diff = stamps[i] - stamps[i - 1]; 
     184        if (diff > 0) sum += diff; 
     185      } 
     186      pixelSizeT = (int) (sum / getSizeT()); 
     187    } 
    184188 
    185189    // determine dimension order 
     
    215219    MetadataTools.populatePixels(store, this); 
    216220 
    217     store.setDimensionsPhysicalSizeX(pixelSizeX, 0, 0); 
    218     store.setDimensionsPhysicalSizeY(pixelSizeY, 0, 0); 
    219     store.setDimensionsPhysicalSizeZ(pixelSizeZ, 0, 0); 
    220     store.setDimensionsTimeIncrement(pixelSizeT / 1000000.0, 0, 0); 
     221    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.ALL) { 
     222      store.setDimensionsPhysicalSizeX(pixelSizeX, 0, 0); 
     223      store.setDimensionsPhysicalSizeY(pixelSizeY, 0, 0); 
     224      store.setDimensionsPhysicalSizeZ(pixelSizeZ, 0, 0); 
     225      store.setDimensionsTimeIncrement(pixelSizeT / 1000000.0, 0, 0); 
     226      for (int i=0; i<getEffectiveSizeC(); i++) { 
     227        if (cNames != null && i < cNames.length) { 
     228          store.setLogicalChannelName(cNames[i], 0, i);  
     229        }  
     230      } 
     231    } 
    221232  } 
    222233 
  • trunk/components/bio-formats/src/loci/formats/in/IvisionReader.java

    r6104 r6127  
    6666  private String gain, offset; 
    6767  private String deltaT; 
    68   private String magnification, lensNA, refractiveIndex; 
     68  private Integer magnification; 
     69  private Double lensNA, refractiveIndex; 
    6970  private String wavelength; 
    7071 
     
    135136      gain = offset = null; 
    136137      deltaT = null; 
    137       magnification = lensNA = refractiveIndex = null; 
     138      magnification = null; 
     139      lensNA = refractiveIndex = null; 
    138140      wavelength = null; 
    139141    } 
     
    205207    imageOffset = in.getFilePointer(); 
    206208 
    207     in.skipBytes(getSizeZ() * getSizeC() * getSizeT() * getSizeX() * 
    208       getSizeY() * FormatTools.getBytesPerPixel(getPixelType())); 
    209  
    210     // look for block of XML data 
    211     LOGGER.info("Looking for XML metadata"); 
    212     boolean xmlFound = false; 
    213     while (!xmlFound && in.getFilePointer() < in.length() - 6) { 
    214       int len = (int) Math.min(8192, in.length() - in.getFilePointer()); 
    215       String check = in.readString(len); 
    216       int xmlIndex = check.indexOf("<?xml"); 
    217       xmlFound = xmlIndex != -1; 
    218       if (xmlFound) { 
    219         in.seek(in.getFilePointer() - check.length() + xmlIndex); 
    220       } 
    221       else in.seek(in.getFilePointer() - 6); 
    222     } 
    223  
    224     if (xmlFound) { 
     209    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.ALL) { 
     210      in.skipBytes(getSizeZ() * getSizeC() * getSizeT() * getSizeX() * 
     211        getSizeY() * FormatTools.getBytesPerPixel(getPixelType())); 
     212 
     213      // look for block of XML data 
     214      LOGGER.info("Looking for XML metadata"); 
     215      in.findString(false, "<?xml"); 
     216      in.seek(in.getFilePointer() - 5); 
     217 
    225218      String xml = in.readString((int) (in.length() - in.getFilePointer())); 
    226219      xml = xml.substring(xml.indexOf("<"), xml.lastIndexOf(">") + 1); 
     
    248241    else MetadataTools.setDefaultCreationDate(store, currentId, 0); 
    249242 
    250     String instrumentID = MetadataTools.createLSID("Instrument", 0); 
    251  
    252     store.setInstrumentID(instrumentID, 0); 
    253     store.setImageInstrumentRef(instrumentID, 0); 
    254  
    255     if (deltaT != null) { 
    256       store.setDimensionsTimeIncrement(new Double(deltaT), 0, 0); 
    257     } 
    258  
    259     String objectiveID = MetadataTools.createLSID("Objective", 0, 0); 
    260     store.setObjectiveID(objectiveID, 0, 0); 
    261     store.setObjectiveSettingsObjective(objectiveID, 0); 
    262  
    263     store.setObjectiveCorrection("Unknown", 0, 0); 
    264     store.setObjectiveImmersion("Unknown", 0, 0); 
    265  
    266     if (lensNA != null) store.setObjectiveLensNA(new Double(lensNA), 0, 0); 
    267     if (magnification != null) { 
    268       store.setObjectiveNominalMagnification(new Integer(magnification), 0, 0); 
    269     } 
    270     if (refractiveIndex != null) { 
    271       store.setObjectiveSettingsRefractiveIndex(new Double(refractiveIndex), 0); 
    272     } 
    273  
    274     String detectorID = MetadataTools.createLSID("Detector", 0, 0); 
    275     store.setDetectorID(detectorID, 0, 0); 
    276     store.setDetectorSettingsDetector(detectorID, 0, 0); 
    277  
    278     store.setDetectorType("Unknown", 0, 0); 
    279  
    280     store.setDetectorSettingsBinning(binX + "x" + binY, 0, 0); 
    281     if (gain != null) store.setDetectorSettingsGain(new Double(gain), 0, 0); 
     243    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.ALL) { 
     244      String instrumentID = MetadataTools.createLSID("Instrument", 0); 
     245 
     246      store.setInstrumentID(instrumentID, 0); 
     247      store.setImageInstrumentRef(instrumentID, 0); 
     248 
     249      if (deltaT != null) { 
     250        store.setDimensionsTimeIncrement(new Double(deltaT), 0, 0); 
     251      } 
     252 
     253      String objectiveID = MetadataTools.createLSID("Objective", 0, 0); 
     254      store.setObjectiveID(objectiveID, 0, 0); 
     255      store.setObjectiveSettingsObjective(objectiveID, 0); 
     256 
     257      store.setObjectiveCorrection("Unknown", 0, 0); 
     258      store.setObjectiveImmersion("Unknown", 0, 0); 
     259 
     260      if (lensNA != null) store.setObjectiveLensNA(lensNA, 0, 0); 
     261      if (magnification != null) { 
     262        store.setObjectiveNominalMagnification(magnification, 0, 0); 
     263      } 
     264      if (refractiveIndex != null) { 
     265        store.setObjectiveSettingsRefractiveIndex(refractiveIndex, 0); 
     266      } 
     267 
     268      String detectorID = MetadataTools.createLSID("Detector", 0, 0); 
     269      store.setDetectorID(detectorID, 0, 0); 
     270      store.setDetectorSettingsDetector(detectorID, 0, 0); 
     271 
     272      store.setDetectorType("Unknown", 0, 0); 
     273 
     274      store.setDetectorSettingsBinning(binX + "x" + binY, 0, 0); 
     275      if (gain != null) store.setDetectorSettingsGain(new Double(gain), 0, 0); 
     276    } 
    282277  } 
    283278 
     
    302297      else if ("iplab:Offset".equals(key)) offset = value; 
    303298      else if ("iplab:Interval_T".equals(key)) deltaT = value; 
    304       else if ("iplab:Objective_Mag".equals(key)) magnification = value; 
    305       else if ("iplab:Objective_NA".equals(key)) lensNA = value; 
    306       else if ("iplab:Objective_RI".equals(key)) refractiveIndex = value; 
     299      else if ("iplab:Objective_Mag".equals(key)) { 
     300        try { 
     301          magnification = new Integer((int) Double.parseDouble(value)); 
     302        } 
     303        catch (NumberFormatException e) { } 
     304      } 
     305      else if ("iplab:Objective_NA".equals(key)) { 
     306        try { 
     307          lensNA = new Double(value); 
     308        } 
     309        catch (NumberFormatException e) { } 
     310      } 
     311      else if ("iplab:Objective_RI".equals(key)) { 
     312        try { 
     313          refractiveIndex = new Double(value); 
     314        } 
     315        catch (NumberFormatException e) { } 
     316      } 
    307317      else if ("iplab:Wavelength".equals(key)) wavelength = value; 
    308318    } 
  • trunk/components/bio-formats/src/loci/formats/in/JEOLReader.java

    r6026 r6127  
    4343 */ 
    4444public class JEOLReader extends FormatReader { 
    45  
    46   // -- Constants -- 
    4745 
    4846  // -- Fields -- 
     
    139137      int commentLength = in.readShort(); 
    140138      core[0].sizeX = 1024; 
    141       in.skipBytes(56); 
    142       String comment = in.readString(commentLength); 
    143       pixelOffset = in.getFilePointer(); 
     139      pixelOffset = in.getFilePointer() + commentLength + 56; 
    144140      core[0].sizeY = (int) ((in.length() - pixelOffset) / getSizeX()); 
    145141    } 
     
    149145      pixelOffset = 0; 
    150146    } 
     147 
     148    addGlobalMeta("Pixel data offset", pixelOffset); 
    151149 
    152150    core[0].pixelType = FormatTools.UINT8; 
  • trunk/components/bio-formats/src/loci/formats/in/JPEG2000Reader.java

    r6055 r6127  
    6060    final int blockLen = 8; 
    6161    if (!FormatTools.validStream(stream, blockLen, false)) return false; 
    62     int b1 = stream.read() & 0xff; 
    63     int b2 = stream.read() & 0xff; 
    64     boolean validStart = b1 == 0xff && b2 == 0x4f; 
     62    boolean validStart = (stream.readShort() & 0xffff) == 0xff4f; 
    6563    if (!validStart) { 
    6664      stream.skipBytes(2); 
     
    6866    } 
    6967    stream.seek(stream.length() - 2); 
    70     b1 = stream.read() & 0xff; 
    71     b2 = stream.read() & 0xff; 
    72     boolean validEnd = b1 == 0xff && b2 == 0xd9; 
     68    boolean validEnd = (stream.readShort() & 0xffff) == 0xffd9; 
    7369    return validStart && validEnd; 
    7470  } 
     
    8783 
    8884    in.seek(0); 
    89     return new JPEG2000Codec().decompress(in, options); 
     85    byte[] plane = new JPEG2000Codec().decompress(in, options); 
     86    RandomAccessInputStream s = new RandomAccessInputStream(plane); 
     87    readPlane(s, x, y, w, h, buf); 
     88    s.close(); 
     89    return buf; 
    9090  } 
    9191 
     
    121121          core[0].sizeC = in.readShort(); 
    122122          int type = in.readInt(); 
    123           if (type == 0xf070100 || type == 0xf070000) { 
    124             core[0].pixelType = FormatTools.UINT16; 
    125           } 
    126           else core[0].pixelType = FormatTools.UINT8; 
     123          core[0].pixelType = convertPixelType(type); 
    127124          lastBoxFound = true; 
    128125        } 
     
    134131        core[0].sizeC = in.readShort(); 
    135132        int type = in.readInt(); 
    136         if (type == 0xf070100 || type == 0xf070000) { 
    137           core[0].pixelType = FormatTools.UINT16; 
    138         } 
    139         else core[0].pixelType = FormatTools.UINT8; 
    140  
     133        core[0].pixelType = convertPixelType(type); 
    141134        lastBoxFound = true; 
    142135      } 
     
    158151  } 
    159152 
     153  // -- Helper methods -- 
     154 
     155  private int convertPixelType(int type) { 
     156    if (type == 0xf070100 || type == 0xf070000) { 
     157      return FormatTools.UINT16; 
     158    } 
     159    return FormatTools.UINT8; 
     160  } 
     161 
    160162} 
Note: See TracChangeset for help on using the changeset viewer.