Changeset 2586


Ignore:
Timestamp:
04/10/07 10:33:31 (13 years ago)
Author:
melissa
Message:
  • Added API to toggle metadata collection.
  • Fixed bugs in several readers.
Location:
trunk/loci/formats
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/FileStitcher.java

    r2583 r2586  
    468468  /* @see IFormatReader#isNormalized() */ 
    469469  public boolean isNormalized() { return reader.isNormalized(); } 
     470 
     471  /* @see IFormatReader#setMetadataCollected(boolean) */ 
     472  public void setMetadataCollected(boolean collect) { 
     473    if (readers == null) reader.setMetadataCollected(collect); 
     474    else { 
     475      for (int i=0; i<readers.length; i++) { 
     476        readers[i].setMetadataCollected(collect); 
     477      }  
     478    } 
     479  } 
     480 
     481  /* @see IFormatReader#isMetadataCollected() */ 
     482  public boolean isMetadataCollected() { 
     483    return reader.isMetadataCollected(); 
     484  } 
    470485 
    471486  /* @see IFormatReader#getUsedFiles() */ 
     
    925940    boolean normalized = reader.isNormalized(); 
    926941    boolean metadataFiltered = reader.isMetadataFiltered(); 
     942    boolean metadataCollected = reader.isMetadataCollected();  
    927943    StatusListener[] statusListeners = reader.getStatusListeners(); 
    928944    for (int i=1; i<readers.length; i++) { 
    929945      readers[i].setNormalized(normalized); 
    930946      readers[i].setMetadataFiltered(metadataFiltered); 
     947      readers[i].setMetadataCollected(metadataCollected);  
    931948      for (int j=0; j<statusListeners.length; j++) { 
    932949        readers[i].addStatusListener(statusListeners[j]); 
     
    9901007    // initialize used files list only when requested 
    9911008    usedFiles = null; 
     1009   
     1010    computeAxisLengths();  
    9921011  } 
    9931012 
    9941013  /** Computes axis length arrays, and total axis lengths. */ 
    9951014  protected void computeAxisLengths() throws FormatException, IOException { 
    996     int sno = getSeries(currentId); 
     1015    int sno = getSeries(); 
    9971016 
    9981017    int[] count = fp.getCount(); 
  • trunk/loci/formats/FormatReader.java

    r2584 r2586  
    6666  /** Whether or not to filter out invalid metadata. */ 
    6767  protected boolean filterMetadata; 
     68 
     69  /** Whether or not to collect metadata. */ 
     70  protected boolean collectMetadata = true; 
    6871 
    6972  /** 
     
    142145  /** Adds an entry to the metadata table. */ 
    143146  protected void addMeta(String key, Object value) { 
    144     if (key == null || value == null) return; 
     147    if (key == null || value == null || !collectMetadata) return; 
    145148    if (filterMetadata) { 
    146149      // verify key & value are not empty 
     
    197200  /* @see IFormatReader#setId(String) */ 
    198201  public void setId(String id) throws FormatException, IOException { 
    199     initFile(id); 
     202    if (!id.equals(currentId)) initFile(id); 
    200203  } 
    201204 
     
    378381  } 
    379382 
     383  /* @see IFormatReader#setMetadataCollected(boolean) */ 
     384  public void setMetadataCollected(boolean collect) { 
     385    if (currentId != null) { 
     386      String s = "setMetadataCollected called with open file."; 
     387      if (debug && debugLevel >= 2) trace(s); 
     388      else System.err.println("Warning: " + s); 
     389    } 
     390    collectMetadata = collect;  
     391  } 
     392 
     393  /* @see IFormatReader#isMetadataCollected() */ 
     394  public boolean isMetadataCollected() { 
     395    return collectMetadata; 
     396  } 
     397 
    380398  /* @see IFormatReader#getUsedFiles() */ 
    381399  public String[] getUsedFiles() throws FormatException, IOException { 
  • trunk/loci/formats/FormatTools.java

    r2583 r2586  
    247247    reader.setNormalized(normalize); 
    248248    reader.setMetadataFiltered(true); 
     249    reader.setMetadataCollected(doMeta);  
    249250    reader.setId(id); 
    250251    if (minMaxCalc != null) minMaxCalc.setId(id); 
  • trunk/loci/formats/IFormatReader.java

    r2583 r2586  
    199199  boolean isNormalized(); 
    200200 
     201  /** Specifies whether or not to collect metadata. */ 
     202  void setMetadataCollected(boolean collect); 
     203 
     204  /** Returns true if we should collect metadata. */ 
     205  boolean isMetadataCollected(); 
     206 
    201207  /** Returns an array of filenames needed to open this dataset. */ 
    202208  String[] getUsedFiles() throws FormatException, IOException; 
  • trunk/loci/formats/ImageReader.java

    r2583 r2586  
    371371  }  
    372372 
     373  /* @see IFormatReader#setMetadataCollected(boolean) */ 
     374  public void setMetadataCollected(boolean collect) { 
     375    for (int i=0; i<readers.length; i++) { 
     376      readers[i].setMetadataCollected(collect); 
     377    } 
     378  } 
     379 
     380  /* @see IFormatReader#isMetadataCollected() */ 
     381  public boolean isMetadataCollected() { 
     382    return readers[0].isMetadataCollected(); 
     383  } 
     384 
    373385  /* @see IFormatReader#getCurrentFile() */ 
    374386  public String getCurrentFile() { 
  • trunk/loci/formats/ReaderWrapper.java

    r2583 r2586  
    194194  public boolean isNormalized() { return reader.isNormalized(); } 
    195195 
     196  public void setMetadataCollected(boolean collect) { 
     197    reader.setMetadataCollected(collect); 
     198  } 
     199 
     200  public boolean isMetadataCollected() { return reader.isMetadataCollected(); } 
     201 
    196202  public String[] getUsedFiles() throws FormatException, IOException { 
    197203    return reader.getUsedFiles(); 
  • trunk/loci/formats/TiffTools.java

    r2563 r2586  
    184184  public static final int Y_CB_CR = 6; 
    185185  public static final int CIE_LAB = 8; 
    186   public static final int CFA_ARRAY = 32803; 
     186  public static final int CFA_ARRAY = -32733; 
    187187 
    188188  // TIFF header constants 
     
    443443            s = new String(ascii, ndx + 1, j - ndx); 
    444444          } 
    445           if (strings != null) strings[c++] = s; 
     445          else s = null; 
     446          if (strings != null && s != null) strings[c++] = s; 
    446447        } 
    447448        value = strings == null ? (Object) s : strings; 
  • trunk/loci/formats/in/BMPReader.java

    r2584 r2586  
    110110    } 
    111111    else { 
    112       if (bpp <= 8) { 
     112      if (core.sizeC[0] == 1) { 
    113113        for (int y=core.sizeY[0]-1; y>=0; y--) { 
    114114          for (int x=0; x<core.sizeX[0]; x++) { 
     
    133133  /* @see loci.formats.IFormatReader#openBytes(int) */  
    134134  public byte[] openBytes(int no) throws FormatException, IOException { 
    135     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * (bpp / 8)]; 
     135    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0]]; 
    136136    return openBytes(no, buf); 
    137137  } 
     
    235235    status("Populating metadata"); 
    236236 
    237     core.sizeC[0] = (palette == null & bpp == 8) ? 1 : 3; 
     237    core.sizeC[0] = (palette == null && bpp == 8) ? 1 : 3; 
    238238    if (bpp > 8) bpp /= 3; 
    239239    while (bpp % 8 != 0) bpp++; 
     
    252252 
    253253    if (core.sizeX[0] % 2 == 1) core.sizeX[0]++;  
    254     core.rgb[0] = bpp > 8;  
     254    core.rgb[0] = core.sizeC[0] > 1;  
    255255    core.littleEndian[0] = true; 
    256256    core.interleaved[0] = true; 
    257257    core.imageCount[0] = 1;  
    258258    core.sizeZ[0] = 1; 
    259     core.sizeC[0] = core.rgb[0] ? 3 : 1; 
     259    //core.sizeC[0] = core.rgb[0] ? 3 : 1; 
    260260    core.sizeT[0] = 1; 
    261261    core.currentOrder[0] = "XYCTZ"; 
  • trunk/loci/formats/in/BioRadReader.java

    r2584 r2586  
    583583    // populate Pixels element 
    584584    in.seek(14); 
    585     core.pixelType[0] = in.readShort() == 1 ? FormatTools.UINT16 :  
    586       FormatTools.UINT8;  
     585    core.pixelType[0] = in.readShort() == 1 ? FormatTools.UINT8 :  
     586      FormatTools.UINT16;  
    587587 
    588588    core.currentOrder[0] = "XY"; 
  • trunk/loci/formats/in/ICSReader.java

    r2584 r2586  
    306306        bitsPerPixel = Integer.parseInt(imageToken); 
    307307      } 
    308       else if(orderToken.equals("x")) { 
     308      else if (orderToken.equals("x")) { 
    309309        core.sizeX[0] = Integer.parseInt(imageToken); 
    310310      } 
    311       else if(orderToken.equals("y")) { 
     311      else if (orderToken.equals("y")) { 
    312312        core.sizeY[0] = Integer.parseInt(imageToken); 
    313313      } 
    314       else if(orderToken.equals("z")) { 
     314      else if (orderToken.equals("z")) { 
    315315        core.sizeZ[0] = Integer.parseInt(imageToken); 
    316316      } 
    317       else if(orderToken.equals("ch")) { 
     317      else if (orderToken.equals("ch")) { 
    318318        core.sizeC[0] = Integer.parseInt(imageToken); 
    319319        if (core.sizeC[0] > 4) core.rgb[0] = false; 
     
    324324    } 
    325325 
    326     core.imageCount[0] = core.sizeZ[0] * core.sizeC[0] * core.sizeT[0]; 
     326    if (core.sizeZ[0] == 0) core.sizeZ[0] = 1; 
     327    if (core.sizeC[0] == 0) core.sizeC[0] = 1; 
     328    if (core.sizeT[0] == 0) core.sizeT[0] = 1; 
     329 
    327330    if (core.imageCount[0] == 0) core.imageCount[0] = 1; 
    328331    core.rgb[0] = core.rgb[0] && core.sizeC[0] > 1; 
    329332    core.interleaved[0] = !core.rgb[0]; 
     333    core.imageCount[0] = core.sizeZ[0] * core.sizeT[0]; 
     334    if (!core.rgb[0]) core.imageCount[0] *= core.sizeC[0]; 
    330335 
    331336    String endian = (String) getMeta("representation byte_order"); 
  • trunk/loci/formats/in/IPWReader.java

    r2584 r2586  
    176176    if (debug) debug("IPWReader.initFile(" + id + ")"); 
    177177    if (noPOI) throw new FormatException(NO_POI_MSG); 
    178     super.initFile(id); 
    179  
     178 
     179    currentId = id; 
     180    metadata = new Hashtable(); 
     181    core = new CoreMetadata(1); 
     182    Arrays.fill(core.orderCertain, true); 
     183    getMetadataStore().createRoot(); 
     184     
    180185    in = new RandomAccessStream(id); 
    181186 
     
    274279    core.sizeX[0] = TiffTools.getIFDIntValue(h, TiffTools.IMAGE_WIDTH); 
    275280    core.sizeY[0] = TiffTools.getIFDIntValue(h, TiffTools.IMAGE_LENGTH); 
    276     core.sizeZ[0] = Integer.parseInt((String) getMeta("frames")); 
    277     core.sizeC[0] = Integer.parseInt((String) getMeta("channels")); 
    278     core.sizeT[0] = Integer.parseInt((String) getMeta("slices")); 
     281    core.sizeZ[0] = Integer.parseInt(getMeta("frames").toString()); 
     282    core.sizeC[0] = Integer.parseInt(getMeta("channels").toString()); 
     283    core.sizeT[0] = Integer.parseInt(getMeta("slices").toString()); 
    279284    core.currentOrder[0] = "XY"; 
     285 
     286    if (core.sizeZ[0] == 0) core.sizeZ[0] = 1; 
     287    if (core.sizeC[0] == 0) core.sizeC[0] = 1; 
     288    if (core.sizeT[0] == 0) core.sizeT[0] = 1; 
    280289 
    281290    if (core.rgb[0]) core.sizeC[0] *= 3; 
  • trunk/loci/formats/in/ImageIOReader.java

    r2584 r2586  
    9999 
    100100    status("Populating metadata"); 
     101    core.imageCount[0] = 1; 
    101102    BufferedImage img = openImage(0); 
    102103 
     
    111112    core.currentOrder[0] = "XYCZT"; 
    112113    core.pixelType[0] = ImageTools.getPixelType(img); 
    113     core.imageCount[0] = 1; 
    114114    core.interleaved[0] = true; 
    115115    core.littleEndian[0] = false; 
  • trunk/loci/formats/in/ImarisTiffReader.java

    r2584 r2586  
    138138    core.currentOrder[0] = "XYZCT"; 
    139139    core.interleaved[0] = false; 
     140    core.rgb[0] =  
     141      core.imageCount[0] != core.sizeZ[0] * core.sizeC[0] * core.sizeT[0]; 
    140142 
    141143    int bitsPerSample = TiffTools.getIFDIntValue(ifds[0], 
  • trunk/loci/formats/in/LIFReader.java

    r2584 r2586  
    437437      core.interleaved[i] = true; 
    438438      core.imageCount[i] = core.sizeZ[i] * core.sizeT[i]; 
    439       if (core.rgb[i]) core.imageCount[i] *= core.sizeC[i]; 
     439      if (!core.rgb[i]) core.imageCount[i] *= core.sizeC[i]; 
    440440 
    441441      validBits[i] = new int[core.sizeC[i] != 2 ? core.sizeC[i] : 3]; 
  • trunk/loci/formats/in/LeicaReader.java

    r2584 r2586  
    10001000    for (int i=0; i<numSeries; i++) { 
    10011001      core.orderCertain[i] = true; 
    1002       core.rgb[i] = false; 
    10031002      core.interleaved[i] = true; 
    10041003      try {  
     
    10401039      } 
    10411040 
     1041      core.rgb[i] =  
     1042        core.imageCount[i] != core.sizeC[i] * core.sizeZ[i] * core.sizeT[i]; 
     1043 
    10421044      Integer ii = new Integer(i); 
    10431045 
  • trunk/loci/formats/in/OIFReader.java

    r2584 r2586  
    279279            value = value.substring(1, value.length() - 1); 
    280280            tiffs.add(i, tiffPath + File.separator + value); 
     281            tiffReader[i].setId((String) tiffs.get(i));  
    281282          } 
    282283          addMeta("Image " + i + " : " + key, value); 
  • trunk/loci/formats/in/OpenlabRawReader.java

    r2584 r2586  
    152152    addMeta("Image name", new String(s, 1, len).trim()); 
    153153 
    154     if (core.sizeC[0] < 1) core.sizeC[0] = 1; 
     154    if (core.sizeC[0] <= 1) core.sizeC[0] = 1; 
    155155    else core.sizeC[0] = 3; 
    156156    addMeta("Width", new Integer(core.sizeX[0])); 
  • trunk/loci/formats/in/OpenlabReader.java

    r2584 r2586  
    628628    for (int i=0; i<numSeries; i++) { 
    629629      core.sizeT[i] += 1; 
     630      core.sizeZ[i] = core.imageCount[i] / core.sizeT[i]; 
    630631      core.currentOrder[i] = isRGB() ? "XYCZT" : "XYZCT"; 
    631632      core.rgb[i] = core.sizeC[i] > 1; 
  • trunk/loci/formats/in/PerkinElmerReader.java

    r2584 r2586  
    333333    for (int i=0; i<tiff.length; i++) { 
    334334      tiff[i] = new TiffReader(); 
     335      tiff[i].setId(files[i]);  
    335336    } 
    336337 
  • trunk/loci/formats/in/PictReader.java

    r2584 r2586  
    210210    // through initFile(String) 
    211211    if (debug) debug("open"); 
     212 
     213    if (core == null) core = new CoreMetadata(1); 
    212214 
    213215    strips = new Vector(); 
  • trunk/loci/formats/in/PrairieReader.java

    r2584 r2586  
    279279        files = new String[f.size()]; 
    280280        f.copyInto(files); 
     281        tiff.setId(files[0]); 
    281282 
    282283        status("Populating metadata"); 
  • trunk/loci/formats/in/SEQReader.java

    r2583 r2586  
    8282 
    8383    if (core.sizeZ[0] == 0) core.sizeZ[0] = 1;  
     84    if (core.sizeT[0] == 0) core.sizeT[0] = 1; 
    8485 
    8586    if (core.sizeZ[0] == 1 && core.sizeT[0] == 1) { 
     
    106107 
    107108    core.sizeC[0] = Integer.parseInt((String) getMeta("channels")); 
     109    core.sizeZ[0] = Integer.parseInt((String) getMeta("frames")); 
     110    core.sizeT[0] = Integer.parseInt((String) getMeta("slices")); 
    108111 
    109112    try { 
  • trunk/loci/formats/in/TiffReader.java

    r2584 r2586  
    140140          core.sizeZ[i] = Integer.parseInt(pixels[i].getAttribute("SizeZ")); 
    141141          core.sizeC[i] = Integer.parseInt(pixels[i].getAttribute("SizeC")); 
     142          core.imageCount[i] = ifds.length;  
    142143          int sc = core.sizeC[i]; 
    143144          if (rgb) sc /= 3; 
     
    481482      } 
    482483    } 
    483  
    484  
    485484  } 
    486485 
  • trunk/loci/formats/in/ZeissZVIReader.java

    r2584 r2586  
    124124  /* @see loci.formats.IFormatReader#openBytes(int) */  
    125125  public byte[] openBytes(int no) throws FormatException, IOException { 
    126     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bpp]; 
     126    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] *  
     127      FormatTools.getBytesPerPixel(core.pixelType[0]) * getRGBChannelCount()]; 
    127128    return openBytes(no, buf); 
    128129  } 
     
    137138    } 
    138139 
    139     if (buf.length < core.sizeX[0] * core.sizeY[0] * bpp) { 
     140    if (buf.length < core.sizeX[0] * core.sizeY[0] *  
     141      FormatTools.getBytesPerPixel(core.pixelType[0]) * getRGBChannelCount()) 
     142    {  
    140143      throw new FormatException("Buffer too small."); 
    141144    } 
     
    180183  { 
    181184    return ImageTools.makeImage(openBytes(no), core.sizeX[0], core.sizeY[0], 
    182       core.sizeC[0], true, bpp == 3 ? 1 : bpp, true, validBits); 
     185      core.rgb[0] ? core.sizeC[0] : 1, true, bpp == 3 ? 1 : bpp, true,  
     186      validBits); 
    183187  } 
    184188 
     
    774778    core.imageCount[0]++; 
    775779    if (bpp % 3 == 0) core.sizeC[0] = 3; 
     780    else core.sizeC[0] = 1;  
    776781  } 
    777782 
Note: See TracChangeset for help on using the changeset viewer.