Changeset 3197


Ignore:
Timestamp:
09/27/07 14:42:20 (12 years ago)
Author:
melissa
Message:
  • Added isFalseColor() to IFormatReader API; updated ChannelFiller accordingly.
  • OMETiffReader now attempts to stitch together all TIFF files in the dataset.
  • Lots of code cleanup
  • Flagged a bunch of readers as 'metadata complete'.
  • Various bugfixes, mostly relating to MetadataStore population.
Location:
trunk/loci/formats
Files:
68 edited

Legend:

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

    r3178 r3197  
    5252  } 
    5353 
     54  /* @see IFormatReader#isFalseColor() */ 
     55  public boolean isFalseColor() { 
     56    return false; 
     57  } 
     58 
    5459  /* @see IFormatReader#get8BitLookupTable() */ 
    5560  public byte[][] get8BitLookupTable() { 
     61    try { 
     62      return reader.isFalseColor() ? reader.get8BitLookupTable() : null; 
     63    } 
     64    catch (FormatException e) { } 
     65    catch (IOException e) { } 
    5666    return null; 
    5767  } 
     
    5969  /* @see IFormatReader#get16BitLookupTable() */ 
    6070  public short[][] get16BitLookupTable() { 
     71    try { 
     72      return reader.isFalseColor() ? reader.get16BitLookupTable() : null; 
     73    } 
     74    catch (FormatException e) { } 
     75    catch (IOException e) { } 
    6176    return null; 
    6277  } 
     
    6479  /* @see IFormatReader#openBytes(int) */ 
    6580  public byte[] openBytes(int no) throws FormatException, IOException { 
    66     if (reader.isIndexed()) { 
     81    if (reader.isIndexed() && !reader.isFalseColor()) { 
    6782      if (getPixelType() == FormatTools.UINT8) { 
    6883        byte[][] b = ImageTools.indexedToRGB(reader.get8BitLookupTable(), 
     
    119134  /* @see IFormatReader#openImage(int) */ 
    120135  public BufferedImage openImage(int no) throws FormatException, IOException { 
    121     if (reader.isIndexed()) { 
     136    if (reader.isIndexed() && !reader.isFalseColor()) { 
    122137      return ImageTools.indexedToRGB(reader.openImage(no), isLittleEndian()); 
    123138    } 
  • trunk/loci/formats/ChannelSeparator.java

    r3126 r3197  
    104104  public boolean isRGB() { 
    105105    FormatTools.assertId(getCurrentFile(), true, 2); 
    106     return false; 
     106    return isIndexed() && !isFalseColor(); 
    107107  } 
    108108 
     
    155155      return ImageTools.splitChannels(lastImage, c, 
    156156        FormatTools.getBytesPerPixel(getPixelType()), 
    157         false, isInterleaved())[channel]; 
     157        false, !isInterleaved())[channel]; 
    158158    } 
    159159    else return reader.openBytes(no); 
  • trunk/loci/formats/CoreMetadata.java

    r3015 r3197  
    4343  public String[] currentOrder; 
    4444  public boolean[] orderCertain, rgb, littleEndian, interleaved; 
     45  public boolean[] indexed, falseColor, metadataComplete; 
    4546  public Hashtable[] seriesMetadata; 
    4647 
     
    6263    littleEndian = new boolean[series]; 
    6364    interleaved = new boolean[series]; 
    64     seriesMetadata = new Hashtable[series]; 
    65     for (int i=0; i<series; i++) seriesMetadata[i] = new Hashtable(); 
     65    indexed = new boolean[series]; 
     66    falseColor = new boolean[series]; 
     67    metadataComplete = new boolean[series]; 
     68    seriesMetadata = new Hashtable[series]; for (int i=0; i<series; i++) 
     69    seriesMetadata[i] = new Hashtable(); 
    6670  } 
    6771 
  • trunk/loci/formats/FileStitcher.java

    r3173 r3197  
    285285    FormatTools.assertId(currentId, true, 2); 
    286286    return reader.isIndexed(); 
     287  } 
     288 
     289  /* @see IFormatReader#isFalseColor() */ 
     290  public boolean isFalseColor() { 
     291    FormatTools.assertId(currentId, true, 2); 
     292    return reader.isFalseColor(); 
    287293  } 
    288294 
  • trunk/loci/formats/FormatReader.java

    r3185 r3197  
    6060  /** Core metadata values. */ 
    6161  protected CoreMetadata core; 
    62  
    63   /** Whether or not the metadata is completely parsed. */ 
    64   protected boolean complete = false; 
    6562 
    6663  /** Whether or not to normalize float data. */ 
     
    251248  /* @see IFormatReader#isIndexed() */ 
    252249  public boolean isIndexed() { 
    253     return false; 
     250    FormatTools.assertId(currentId, true, 1); 
     251    return core.indexed[series]; 
     252  } 
     253 
     254  /* @see IFormatReader#isFalseColor() */ 
     255  public boolean isFalseColor() { 
     256    FormatTools.assertId(currentId, true, 1); 
     257    return core.falseColor[series]; 
    254258  } 
    255259 
     
    335339  } 
    336340 
    337   /* @see IFormatReader#openBytes(int, byte[]) */ 
    338   public byte[] openBytes(int no, byte[] buf) 
    339     throws FormatException, IOException 
    340   { 
    341     return openBytes(no); 
     341  /* @see IFormatReader#openBytes(int) */ 
     342  public byte[] openBytes(int no) throws FormatException, IOException { 
     343    byte[] buf = new byte[getSizeX() * getSizeY() * getRGBChannelCount() * 
     344      FormatTools.getBytesPerPixel(getPixelType())]; 
     345    return openBytes(no, buf); 
    342346  } 
    343347 
     
    454458  /* @see IFormatReader#isMetadataComplete() */ 
    455459  public boolean isMetadataComplete() { 
    456     return complete; 
     460    FormatTools.assertId(currentId, true, 1); 
     461    return core.metadataComplete[series]; 
    457462  } 
    458463 
  • trunk/loci/formats/FormatTools.java

    r3185 r3197  
    403403        new Integer(r.getSizeZ()), new Integer(r.getSizeC()), 
    404404        new Integer(r.getSizeT()), new Integer(r.getPixelType()), 
    405         new Boolean(!r.isLittleEndian()), r.getDimensionOrder(), null, ii); 
     405        new Boolean(!r.isLittleEndian()), r.getDimensionOrder(), ii, null); 
    406406    } 
    407407    r.setSeries(oldSeries); 
     
    443443  } 
    444444 
     445  /** Checks that the given plane number is valid for the given reader. */ 
     446  public static void checkPlaneNumber(IFormatReader r, int no) 
     447    throws FormatException 
     448  { 
     449    if (no < 0 || no >= r.getImageCount()) { 
     450      throw new FormatException("Invalid image number: " + no); 
     451    } 
     452  } 
     453 
     454  public static void checkBufferSize(IFormatReader r, int len) 
     455    throws FormatException 
     456  { 
     457    int size = r.getSizeX() * r.getSizeY() * 
     458      (r.isIndexed() ? 1 : r.getRGBChannelCount()) * 
     459      getBytesPerPixel(r.getPixelType()); 
     460    if (size > len) { 
     461      throw new FormatException("Buffer too small."); 
     462    } 
     463  } 
     464 
    445465} 
  • trunk/loci/formats/IFormatReader.java

    r3183 r3197  
    9090  /** Gets whether the images are indexed color. */ 
    9191  boolean isIndexed(); 
     92 
     93  /** 
     94   * Returns false if isIndexed is false, or if isIndexed is true and the lookup 
     95   * table represents "real" color data.  Returns true if isIndexed is true 
     96   * and the lookup table is only present to aid in visualization. 
     97   */ 
     98  boolean isFalseColor(); 
    9299 
    93100  /** 
  • trunk/loci/formats/ImageReader.java

    r3139 r3197  
    237237  } 
    238238 
     239  /* @see IFormatReader#isFalseColor() */ 
     240  public boolean isFalseColor() { 
     241    FormatTools.assertId(currentId, true, 2); 
     242    return getReader().isFalseColor(); 
     243  } 
     244 
    239245  /* @see IFormatReader#get8BitLookupTable() */ 
    240246  public byte[][] get8BitLookupTable() throws FormatException, IOException { 
     
    403409  /* @see IFormatReader#isGroupFiles() */ 
    404410  public boolean isGroupFiles() { 
    405     return readers[0].isGroupFiles(); 
     411    return getReader().isGroupFiles(); 
    406412  } 
    407413 
     
    413419  /* @see IFormatReader#isMetadataComplete() */ 
    414420  public boolean isMetadataComplete() { 
    415     return readers[0].isMetadataComplete(); 
     421    FormatTools.assertId(currentId, true, 2); 
     422    return getReader().isMetadataComplete(); 
    416423  } 
    417424 
  • trunk/loci/formats/ImageTools.java

    r3180 r3197  
    18931893    BufferedImage result = null; 
    18941894    Image scaled = scaleAWT(source, width, height, Image.SCALE_AREA_AVERAGING); 
    1895     try { 
    1896       result = makeBuffered(scaled, source.getColorModel()); 
    1897     } 
    1898     catch (Exception e) { 
    1899       // CTR TODO - eliminate catch-all exception handling 
    1900       result = makeBuffered(scaled); 
    1901     } 
     1895    result = makeBuffered(scaled, source.getColorModel()); 
    19021896    return padImage(result, finalWidth, finalHeight); 
    19031897  } 
  • trunk/loci/formats/MetadataTools.java

    r3143 r3197  
    166166    else { 
    167167      // metadata store is foreign; create an OME-XML 
    168       // metadata object and copy it into the destionation 
     168      // metadata object and copy it into the destination 
    169169      MetadataRetrieve src = (MetadataRetrieve) createOMEXMLMetadata(xml); 
    170170      convertMetadata(src, dest); 
  • trunk/loci/formats/MinMaxCalculator.java

    r3015 r3197  
    337337    minMaxDone[series]++; 
    338338 
    339     if (minMaxDone[series] == getImageCount()) { 
     339    if (minMaxDone[getSeries()] == getImageCount()) { 
    340340      MetadataStore store = getMetadataStore(); 
    341341      for (int c=0; c<getSizeC(); c++) { 
    342         store.setChannelGlobalMinMax(c, new Double(chanMin[series][c]), 
    343           new Double(chanMax[series][c]), new Integer(getSeries())); 
     342        store.setChannelGlobalMinMax(c, new Double(chanMin[getSeries()][c]), 
     343          new Double(chanMax[getSeries()][c]), new Integer(getSeries())); 
    344344      } 
    345345    } 
  • trunk/loci/formats/ReaderWrapper.java

    r3139 r3197  
    122122  } 
    123123 
     124  public boolean isFalseColor() { 
     125    return reader.isFalseColor(); 
     126  } 
     127 
    124128  public byte[][] get8BitLookupTable() throws FormatException, IOException { 
    125129    return reader.get8BitLookupTable(); 
  • trunk/loci/formats/codec/MJPBCodec.java

    r3015 r3197  
    66 
    77import java.io.*; 
     8import java.util.Arrays; 
    89import loci.formats.*; 
    910 
     
    7980          int len = ras.readShort(); 
    8081          ras.skipBytes(1); 
    81           quant = new byte[len - 3]; 
     82          quant = new byte[64]; 
    8283          ras.read(quant); 
    8384        } 
     
    9495          lumAcBits = new byte[16]; 
    9596          ras.read(lumAcBits); 
    96           lumAc = new byte[162]; 
     97 
     98          int sum = 0; 
     99 
     100          for (int i=0; i<lumAcBits.length; i++) { 
     101            sum += lumAcBits[i] & 0xff; 
     102          } 
     103 
     104          lumAc = new byte[sum]; 
    97105          ras.read(lumAc); 
     106          /* 
     107          if (sum == 162) ras.read(lumAc); 
     108          else { 
     109            byte[] tmp = new byte[162]; 
     110            ras.read(tmp); 
     111 
     112            ByteVector v = new ByteVector(sum); 
     113            int[] count = new int[lumAcBits.length]; 
     114            Arrays.fill(count, (byte) 0); 
     115            for (int i=0; i<tmp.length; i++) { 
     116              int size = 0; 
     117              int val = tmp[i] & 0xff; 
     118              while (Math.pow(2, size) < val) size++; 
     119              if (count[size] < lumAcBits[size]) { 
     120                v.add(tmp[i]); 
     121                count[size]++; 
     122              } 
     123              else if (size == 8) { 
     124                for (int j=size+1; j<lumAcBits.length; j++) { 
     125                  if (count[j] < lumAcBits[j]) { 
     126                    v.add(tmp[i]); 
     127                    count[j]++; 
     128                  } 
     129                } 
     130              } 
     131            } 
     132 
     133            lumAc = v.toByteArray(); 
     134          } 
     135          */ 
    98136        } 
    99137 
     
    161199      v.add(new byte[] {(byte) 0xff, (byte) 0xdb}); 
    162200 
    163       int length = 67; 
     201      int length = 4 + quant.length*2; 
    164202      v.add((byte) ((length >>> 8) & 0xff)); 
    165203      v.add((byte) (length & 0xff)); 
    166204      v.add((byte) 0); 
     205      v.add(quant); 
     206 
     207      v.add((byte) 1); 
    167208      v.add(quant); 
    168209 
  • trunk/loci/formats/in/AVIReader.java

    r3184 r3197  
    3434 * AVIReader is the file format reader for uncompressed AVI files. 
    3535 * 
    36  * Much of this form's code was adapted from Wayne Rasband's AVI Movie Reader 
     36 * Much of this code was adapted from Wayne Rasband's AVI Movie Reader 
    3737 * plugin for ImageJ (available at http://rsb.info.nih.gov/ij). 
    3838 * 
     
    6060  private int bmpColorsUsed, bmpWidth; 
    6161  private int bmpCompression, bmpScanLineSize; 
    62   private int bmpActualColorsUsed; 
    6362  private short bmpBitsPerPixel; 
    64   private byte[] pr = null; 
    65   private byte[] pg = null; 
    66   private byte[] pb = null; 
     63  private byte[][] lut = null; 
    6764  private boolean isRLE = false; 
    6865 
     
    7471  public AVIReader() { super("Audio Video Interleave", "avi"); } 
    7572 
    76   // -- AVIReader API methods -- 
    77  
    78   /** Reads a 4-byte String. */ 
    79   public String readStringBytes() throws IOException { 
    80     byte[] list = new byte[4]; 
    81     in.read(list); 
    82     return new String(list); 
    83   } 
    84  
    85   /** 
    86    * Throws a FormatException to apologize for the fact that 
    87    * AVI support is suboptimal. 
    88    */ 
    89   private void whine(String msg) throws FormatException { 
    90     throw new FormatException(msg); 
    91   } 
    92  
    9373  // -- IFormatReader API methods -- 
    9474 
    9575  /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    9676  public boolean isThisType(byte[] block) { 
    97     return false; 
    98   } 
    99  
    100   /* @see loci.formats.IFormatReader#isIndexed() */ 
    101   public boolean isIndexed() { 
    102     FormatTools.assertId(currentId, true, 1); 
    103     return isRLE; 
     77    return new String(block).startsWith("RIFF"); 
    10478  } 
    10579 
     
    10781  public byte[][] get8BitLookupTable() throws FormatException, IOException { 
    10882    FormatTools.assertId(currentId, true, 1); 
    109     return new byte[][] {pr, pg, pb}; 
     83    return lut; 
    11084  } 
    11185 
    112   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    113   public byte[] openBytes(int no) throws FormatException, IOException { 
     86  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     87  public byte[] openBytes(int no, byte[] buf) 
     88    throws FormatException, IOException 
     89  { 
    11490    FormatTools.assertId(currentId, true, 1); 
     91    FormatTools.checkPlaneNumber(this, no); 
     92    FormatTools.checkBufferSize(this, buf.length); 
     93 
    11594    int bytes = FormatTools.getBytesPerPixel(core.pixelType[0]); 
    11695    double p = ((double) bmpScanLineSize) / bmpBitsPerPixel; 
     
    11998      effectiveWidth = core.sizeX[0]; 
    12099    } 
    121  
    122     int bufSize = core.sizeY[0] * effectiveWidth * bytes; 
    123     if (!isIndexed()) bufSize *= core.sizeC[0]; 
    124     byte[] buf = new byte[bufSize]; 
    125     return openBytes(no, buf); 
    126   } 
    127  
    128   /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    129   public byte[] openBytes(int no, byte[] buf) 
    130     throws FormatException, IOException 
    131   { 
    132     FormatTools.assertId(currentId, true, 1); 
    133     if (no < 0 || no >= getImageCount()) { 
    134       throw new FormatException("Invalid image number: " + no); 
    135     } 
    136  
    137     int bytes = FormatTools.getBytesPerPixel(core.pixelType[0]); 
    138     double p = ((double) bmpScanLineSize) / bmpBitsPerPixel; 
    139     int effectiveWidth = (int) (bmpScanLineSize / p); 
    140     if (effectiveWidth == 0 || effectiveWidth < core.sizeX[0]) { 
    141       effectiveWidth = core.sizeX[0]; 
    142     } 
    143  
    144     int minSize = effectiveWidth * bytes * core.sizeY[0]; 
    145     if (!isIndexed()) minSize *= core.sizeC[0]; 
    146  
    147     if (buf.length < minSize) throw new FormatException("Buffer too small."); 
    148100 
    149101    long fileOff = ((Long) offsets.get(no)).longValue(); 
     
    225177    lengths = new Vector(); 
    226178 
    227     byte[] list = new byte[4]; 
    228179    String listString; 
    229180 
    230     type = readStringBytes(); 
     181    type = in.readString(4); 
    231182    size = in.readInt(); 
    232     fcc = readStringBytes(); 
     183    fcc = in.readString(4); 
    233184 
    234185    if (type.equals("RIFF")) { 
    235       if (!fcc.equals("AVI ")) whine("Sorry, AVI RIFF format not found."); 
    236     } 
    237     else whine("Not an AVI file"); 
     186      if (!fcc.equals("AVI ")) { 
     187        throw new FormatException("Sorry, AVI RIFF format not found."); 
     188      } 
     189    } 
     190    else throw new FormatException("Not an AVI file"); 
    238191 
    239192    pos = in.getFilePointer(); 
     
    243196 
    244197    while ((in.length() - in.getFilePointer()) > 4) { 
    245       in.read(list); 
     198      listString = in.readString(4); 
    246199      in.seek(pos); 
    247       listString = new String(list); 
    248200      if (listString.equals(" JUN")) { 
    249201        in.skipBytes(1); 
     
    252204 
    253205      if (listString.equals("JUNK")) { 
    254         type = readStringBytes(); 
     206        type = in.readString(4); 
    255207        size = in.readInt(); 
    256208 
     
    261213      else if (listString.equals("LIST")) { 
    262214        spos = in.getFilePointer(); 
    263         type = readStringBytes(); 
     215        type = in.readString(4); 
    264216        size = in.readInt(); 
    265         fcc = readStringBytes(); 
     217        fcc = in.readString(4); 
    266218 
    267219        in.seek(spos); 
    268220        if (fcc.equals("hdrl")) { 
    269           type = readStringBytes(); 
     221          type = in.readString(4); 
    270222          size = in.readInt(); 
    271           fcc = readStringBytes(); 
     223          fcc = in.readString(4); 
    272224 
    273225          if (type.equals("LIST")) { 
    274226            if (fcc.equals("hdrl")) { 
    275               type = readStringBytes(); 
     227              type = in.readString(4); 
    276228              size = in.readInt(); 
    277229              if (type.equals("avih")) { 
     
    308260          long streamSize = size; 
    309261 
    310           type = readStringBytes(); 
     262          type = in.readString(4); 
    311263          size = in.readInt(); 
    312           fcc = readStringBytes(); 
     264          fcc = in.readString(4); 
    313265 
    314266          if (type.equals("LIST")) { 
    315267            if (fcc.equals("strl")) { 
    316               type = readStringBytes(); 
     268              type = in.readString(4); 
    317269              size = in.readInt(); 
    318270 
    319271              if (type.equals("strh")) { 
    320272                spos = in.getFilePointer(); 
    321                 readStringBytes(); 
    322  
    323                 in.skipBytes(36); 
     273                in.skipBytes(40); 
    324274 
    325275                addMeta("Stream quality", new Integer(in.readInt())); 
     
    331281              } 
    332282 
    333               type = readStringBytes(); 
     283              type = in.readString(4); 
    334284              size = in.readInt(); 
    335285              if (type.equals("strf")) { 
     
    352302                addMeta("Bitmap compression value", 
    353303                  new Integer(bmpCompression)); 
    354                 addMeta("Number of colors used", 
    355                   new Integer(bmpColorsUsed)); 
     304                addMeta("Number of colors used", new Integer(bmpColorsUsed)); 
    356305                addMeta("Bits per pixel", new Integer(bmpBitsPerPixel)); 
    357306 
     
    362311                bmpScanLineSize = (bmpWidth + npad) * (bmpBitsPerPixel / 8); 
    363312 
     313                int bmpActualColorsUsed = 0; 
    364314                if (bmpColorsUsed != 0) { 
    365315                  bmpActualColorsUsed = bmpColorsUsed; 
    366316                } 
    367                 else { 
     317                else if (bmpBitsPerPixel < 16) { 
    368318                  // a value of 0 means we determine this based on the 
    369319                  // bits per pixel 
    370                   if (bmpBitsPerPixel < 16) { 
    371                     bmpActualColorsUsed = 1 << bmpBitsPerPixel; 
    372                   } 
    373                   else { 
    374                     // no palette 
    375                     bmpActualColorsUsed = 0; 
    376                   } 
     320                  bmpActualColorsUsed = 1 << bmpBitsPerPixel; 
    377321                } 
    378322 
    379323                if (bmpCompression == 1) { 
    380324                  // MS RLE compression scheme 
    381  
    382325                  isRLE = true; 
    383326                } 
    384327                else if (bmpCompression != 0) { 
    385                   whine("Sorry, compressed AVI files not supported."); 
     328                  throw new FormatException("Unsupported compression type " + 
     329                    bmpCompression); 
    386330                } 
    387331 
     
    390334                  bmpBitsPerPixel == 32)) 
    391335                { 
    392                   whine("Sorry, " + bmpBitsPerPixel + " bits per pixel not " + 
    393                     "supported"); 
     336                  throw new FormatException(bmpBitsPerPixel + 
     337                    " bits per pixel not supported"); 
    394338                } 
    395339 
    396340                if (bmpActualColorsUsed != 0) { 
    397341                  // read the palette 
    398                   pr = new byte[bmpColorsUsed]; 
    399                   pg = new byte[bmpColorsUsed]; 
    400                   pb = new byte[bmpColorsUsed]; 
     342                  lut = new byte[3][bmpColorsUsed]; 
    401343 
    402344                  for (int i=0; i<bmpColorsUsed; i++) { 
    403                     pb[i] = (byte) (in.read() & 0xff); 
    404                     pg[i] = (byte) (in.read() & 0xff); 
    405                     pr[i] = (byte) (in.read() & 0xff); 
    406                     in.read(); 
     345                    lut[2][i] = in.readByte(); 
     346                    lut[1][i] = in.readByte(); 
     347                    lut[0][i] = in.readByte(); 
     348                    in.skipBytes(1); 
    407349                  } 
    408350                } 
     
    413355 
    414356            spos = in.getFilePointer(); 
    415             type = readStringBytes(); 
     357            type = in.readString(4); 
    416358            size = in.readInt(); 
    417359            if (type.equals("strd")) { 
     
    423365 
    424366            spos = in.getFilePointer(); 
    425             type = readStringBytes(); 
     367            type = in.readString(4); 
    426368            size = in.readInt(); 
    427369            if (type.equals("strn")) { 
     
    438380        } 
    439381        else if (fcc.equals("movi")) { 
    440           type = readStringBytes(); 
     382          type = in.readString(4); 
    441383          size = in.readInt(); 
    442           fcc = readStringBytes(); 
     384          fcc = in.readString(4); 
    443385 
    444386          if (type.equals("LIST")) { 
     
    446388              spos = in.getFilePointer(); 
    447389              if (spos >= in.length() - 12) break; 
    448               type = readStringBytes(); 
     390              type = in.readString(4); 
    449391              size = in.readInt(); 
    450               fcc = readStringBytes(); 
     392              fcc = in.readString(4); 
    451393              if (!(type.equals("LIST") && fcc.equals("rec "))) { 
    452394                in.seek(spos); 
     
    454396 
    455397              spos = in.getFilePointer(); 
    456               type = readStringBytes(); 
     398              type = in.readString(4); 
    457399              size = in.readInt(); 
    458400 
     
    471413                spos = in.getFilePointer(); 
    472414 
    473                 type = readStringBytes(); 
     415                type = in.readString(4); 
    474416                size = in.readInt(); 
    475417                if (type.equals("JUNK")) { 
    476418                  in.skipBytes(size); 
    477419                  spos = in.getFilePointer(); 
    478                   type = readStringBytes(); 
     420                  type = in.readString(4); 
    479421                  size = in.readInt(); 
    480422                } 
     
    494436      else { 
    495437        // skipping unknown block 
    496         type = readStringBytes(); 
     438        type = in.readString(4); 
    497439        if (in.getFilePointer() + size + 4 <= in.length()) { 
    498440          size = in.readInt(); 
     
    512454    core.currentOrder[0] = core.sizeC[0] == 3 ? "XYCTZ" : "XYTCZ"; 
    513455    core.littleEndian[0] = true; 
    514     core.interleaved[0] = bmpBitsPerPixel == 16; 
     456    core.interleaved[0] = bmpBitsPerPixel != 16; 
     457    core.indexed[0] = isRLE; 
     458    core.falseColor[0] = false; 
     459    core.metadataComplete[0] = true; 
    515460 
    516461    if (bmpBitsPerPixel <= 8) core.pixelType[0] = FormatTools.UINT8; 
     
    518463    else if (bmpBitsPerPixel == 32) core.pixelType[0] = FormatTools.UINT32; 
    519464    else if (bmpBitsPerPixel == 24) core.pixelType[0] = FormatTools.UINT8; 
    520     else 
     465    else { 
    521466      throw new FormatException( 
    522467          "Unknown matching for pixel bit width of: " + bmpBitsPerPixel); 
     468    } 
    523469 
    524470    MetadataStore store = getMetadataStore(); 
     
    530476    for (int i=0; i<core.sizeC[0]; i++) { 
    531477      store.setLogicalChannel(i, null, null, null, null, null, null, null, null, 
    532         null, null, null, null, core.sizeC[0] == 1 ? "monochrome" : "RGB", 
     478        null, null, null, null, null, 
    533479        null, null, null, null, null, null, null, null, null, null, null); 
    534480    } 
  • trunk/loci/formats/in/AliconaReader.java

    r3184 r3197  
    5757  } 
    5858 
    59   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    60   public boolean isMetadataComplete() { 
    61     return true; 
    62   } 
    63  
    64   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    65   public byte[] openBytes(int no) throws FormatException, IOException { 
    66     FormatTools.assertId(currentId, true, 1); 
    67     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * numBytes]; 
    68     return openBytes(no, buf); 
    69   } 
    70  
    7159  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    7260  public byte[] openBytes(int no, byte[] buf) 
     
    7462  { 
    7563    FormatTools.assertId(currentId, true, 1); 
    76     if (no < 0 || no >= getImageCount()) { 
    77       throw new FormatException("Invalid image number: " + no); 
    78     } 
     64    FormatTools.checkPlaneNumber(this, no); 
     65    FormatTools.checkBufferSize(this, buf.length); 
    7966 
    8067    int pad = (8 - (core.sizeX[0] % 8)) % 8; 
    81  
    82     if (buf.length < core.sizeX[0] * core.sizeY[0] * numBytes) { 
    83       throw new FormatException("Buffer too small."); 
    84     } 
    8568 
    8669    for (int i=0; i<numBytes; i++) { 
    8770      in.seek(textureOffset + (no * (core.sizeX[0] + pad)*core.sizeY[0]*(i+1))); 
    8871      for (int j=0; j<core.sizeX[0] * core.sizeY[0]; j++) { 
    89         buf[j*numBytes + i] = (byte) (in.read() & 0xff); 
     72        buf[j*numBytes + i] = in.readByte(); 
    9073        if (j % core.sizeX[0] == core.sizeX[0] - 1) in.skipBytes(pad); 
    9174      } 
     
    123106 
    124107    for (int i=0; i<count; i++) { 
    125       String key = in.readString(20); 
    126       String value = in.readString(30); 
    127       key = key.trim(); 
    128       value = value.trim(); 
     108      String key = in.readString(20).trim(); 
     109      String value = in.readString(30).trim(); 
    129110 
    130111      addMeta(key, value); 
     
    162143    core.pixelType[0] = numBytes == 2 ? FormatTools.UINT16 : FormatTools.UINT8; 
    163144    core.currentOrder[0] = "XYCTZ"; 
     145    core.metadataComplete[0] = true; 
     146    core.indexed[0] = false; 
     147    core.falseColor[0] = false; 
    164148 
    165149    MetadataStore store = getMetadataStore(); 
  • trunk/loci/formats/in/BMPReader.java

    r3185 r3197  
    7373  /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    7474  public boolean isThisType(byte[] block) { 
    75     if (block.length != 14) { 
    76       return false; 
    77     } 
    78     if (block[0] != 'B' || block[1] != 'M') return false; 
    79     return true; 
    80   } 
    81  
    82   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    83   public boolean isMetadataComplete() { 
    84     return true; 
    85   } 
    86  
    87   /* @see loci.formats.IFormatReader#isIndexed() */ 
    88   public boolean isIndexed() { 
    89     FormatTools.assertId(currentId, true, 1); 
    90     return palette != null; 
     75    return new String(block).startsWith("BM"); 
    9176  } 
    9277 
     
    9580    FormatTools.assertId(currentId, true, 1); 
    9681    return palette; 
    97   } 
    98  
    99   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    100   public byte[] openBytes(int no) throws FormatException, IOException { 
    101     FormatTools.assertId(currentId, true, 1); 
    102     int size = core.sizeX[0] * core.sizeY[0]; 
    103     if (!isIndexed()) size *= core.sizeC[0]; 
    104     byte[] buf = new byte[size]; 
    105     return openBytes(no, buf); 
    10682  } 
    10783 
     
    11187  { 
    11288    FormatTools.assertId(currentId, true, 1); 
    113     if (no < 0 || no >= getImageCount()) { 
    114       throw new FormatException("Invalid image number: " + no); 
    115     } 
    116  
    117     int pixels = core.sizeX[0] * core.sizeY[0]; 
    118  
    119     int size = isIndexed() ? pixels : pixels * (bpp / 8); 
    120     if (buf.length < size) throw new FormatException("Buffer too small."); 
     89    FormatTools.checkPlaneNumber(this, no); 
     90    FormatTools.checkBufferSize(this, buf.length); 
    12191 
    12292    if (compression != 0) { 
     
    12797    in.seek(global); 
    12898 
    129     if (palette != null && palette[0].length > 0) { 
     99    if ((palette != null && palette[0].length > 0) || core.sizeC[0] == 1) { 
    130100      for (int y=core.sizeY[0]-1; y>=0; y--) { 
    131101        in.read(buf, y*core.sizeX[0], core.sizeX[0]); 
    132102      } 
    133       return buf; 
    134103    } 
    135104    else { 
    136       if (core.sizeC[0] == 1) { 
    137         for (int y=core.sizeY[0]-1; y>=0; y--) { 
    138           in.read(buf, y*core.sizeX[0], core.sizeX[0]); 
    139         } 
    140       } 
    141       else { 
    142         for (int y=core.sizeY[0]-1; y>=0; y--) { 
    143           for (int x=0; x<core.sizeX[0]; x++) { 
    144             int off = y*core.sizeX[0] + x; 
    145             buf[2*core.sizeX[0]*core.sizeY[0] + off] = (byte)(in.read() & 0xff); 
    146             buf[core.sizeX[0]*core.sizeY[0] + off] = (byte) (in.read() & 0xff); 
    147             buf[off] = (byte) (in.read() & 0xff); 
    148           } 
    149         } 
     105      for (int y=core.sizeY[0]-1; y>=0; y--) { 
     106        in.read(buf, y*core.sizeX[0]*3, core.sizeX[0]*3); 
     107      } 
     108      for (int i=0; i<buf.length/3; i++) { 
     109        byte tmp = buf[i*3 + 2]; 
     110        buf[i*3 + 2] = buf[i*3]; 
     111        buf[i*3] = tmp; 
    150112      } 
    151113    } 
     
    230192      for (int i=0; i<nColors; i++) { 
    231193        for (int j=palette.length; j>0; j--) { 
    232           palette[j][i] = (byte) (in.read() & 0xff); 
     194          palette[j][i] = in.readByte(); 
    233195        } 
    234         in.read(); 
     196        in.skipBytes(1); 
    235197      } 
    236198    } 
     
    265227    core.sizeT[0] = 1; 
    266228    core.currentOrder[0] = "XYCTZ"; 
     229    core.metadataComplete[0] = true; 
     230    core.indexed[0] = palette != null; 
     231    core.falseColor[0] = false; 
    267232 
    268233    // Populate metadata store. 
  • trunk/loci/formats/in/BaseTiffReader.java

    r3195 r3197  
    7979  } 
    8080 
    81   /* @see loci.formats.IFormatReader#isIndexed() */ 
    82   public boolean isIndexed() { 
    83     FormatTools.assertId(currentId, true, 1); 
    84     return TiffTools.getIFDIntValue(ifds[0], 
    85       TiffTools.PHOTOMETRIC_INTERPRETATION) == TiffTools.RGB_PALETTE; 
    86   } 
    87  
    8881  /* @see loci.formats.IFormatReader#get8BitLookupTable() */ 
    8982  public byte[][] get8BitLookupTable() throws FormatException, IOException { 
     
    9487        (int[]) TiffTools.getIFDValue(ifds[0], TiffTools.COLOR_MAP); 
    9588      if (colorMap == null) return null; 
     89 
    9690      byte[][] table = new byte[3][colorMap.length / 3]; 
    9791      int next = 0; 
     
    145139  } 
    146140 
    147   /* @see loci.formats.FormatReader#openBytes(int) */ 
    148   public byte[] openBytes(int no) throws FormatException, IOException { 
    149     FormatTools.assertId(currentId, true, 1); 
    150     if (no < 0 || no >= getImageCount()) { 
    151       throw new FormatException("Invalid image number: " + no); 
    152     } 
    153  
    154     int bytesPerPixel = FormatTools.getBytesPerPixel(getPixelType()); 
    155     int bufSize = getSizeX() * getSizeY() * bytesPerPixel; 
    156     if (!isIndexed()) bufSize *= getRGBChannelCount(); 
    157     byte[] buf = new byte[bufSize]; 
    158     return openBytes(no, buf); 
    159   } 
    160  
    161141  /* @see loci.formats.FormatReader#openBytes(int, byte[]) */ 
    162142  public byte[] openBytes(int no, byte[] buf) 
     
    164144  { 
    165145    FormatTools.assertId(currentId, true, 1); 
    166     if (no < 0 || no >= getImageCount()) { 
    167       throw new FormatException("Invalid image number: " + no); 
    168     } 
     146    FormatTools.checkPlaneNumber(this, no); 
     147    FormatTools.checkBufferSize(this, buf.length); 
    169148 
    170149    TiffTools.getSamples(ifds[no], in, buf); 
     
    546525    core.rgb[0] = samples > 1 || p == TiffTools.RGB_PALETTE || 
    547526      p == TiffTools.CFA_ARRAY || p == TiffTools.RGB; 
    548     core.interleaved[0] = true; 
     527    core.interleaved[0] = false; 
    549528    core.littleEndian[0] = TiffTools.isLittleEndian(ifds[0]); 
    550529 
     
    556535    core.sizeC[0] = core.rgb[0] ? 3 : 1; 
    557536    core.sizeT[0] = ifds.length; 
     537    core.metadataComplete[0] = true; 
     538    core.indexed[0] = TiffTools.getIFDIntValue(ifds[0], 
     539      TiffTools.PHOTOMETRIC_INTERPRETATION) == TiffTools.RGB_PALETTE; 
     540    core.falseColor[0] = false; 
    558541 
    559542    int bitFormat = TiffTools.getIFDIntValue(ifds[0], 
  • trunk/loci/formats/in/BioRadReader.java

    r3184 r3197  
    8080  // -- IFormatReader API methods -- 
    8181 
    82   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    83   public boolean isMetadataComplete() { 
    84     return true; 
    85   } 
    86  
    8782  /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    8883  public boolean isThisType(byte[] block) { 
     
    9792  } 
    9893 
    99   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    100   public byte[] openBytes(int no) throws FormatException, IOException { 
    101     FormatTools.assertId(currentId, true, 1); 
    102     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * (byteFormat ? 1 : 2)]; 
    103     return openBytes(no, buf); 
    104   } 
    105  
    10694  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    10795  public byte[] openBytes(int no, byte[] buf) 
     
    10997  { 
    11098    FormatTools.assertId(currentId, true, 1); 
    111     if (no < 0 || no >= core.imageCount[0]) { 
    112       throw new FormatException("Invalid image number: " + no); 
    113     } 
    114     if (buf.length < core.sizeX[0] * core.sizeY[0] * (byteFormat ? 1 : 2)) { 
    115       throw new FormatException("Buffer too small."); 
    116     } 
     99    FormatTools.checkPlaneNumber(this, no); 
     100    FormatTools.checkBufferSize(this, buf.length); 
    117101 
    118102    long offset = no * core.sizeX[0] * core.sizeY[0] * (byteFormat ? 1 : 2); 
     
    144128    int ramp1min = in.readShort(); 
    145129    int ramp1max = in.readShort(); 
    146     boolean notes = (in.read() | in.read() | in.read() | in.read()) != 0; 
     130    boolean notes = in.readInt() != 0; 
    147131    byteFormat = in.readShort() != 0; 
    148132    int imageNumber = in.readShort(); 
     
    198182    core.interleaved[0] = false; 
    199183    core.littleEndian[0] = LITTLE_ENDIAN; 
     184    core.metadataComplete[0] = true; 
    200185 
    201186    status("Reading notes"); 
     
    213198 
    214199      int level = in.readShort(); 
    215       notes = (in.read() | in.read() | in.read() | in.read()) != 0; 
     200      notes = in.readInt() != 0; 
    216201      int num = in.readShort(); 
    217202      int status = in.readShort(); 
     
    610595    for (int i=0; i<numLuts; i++) { 
    611596      for (int l=0; l<256; l++) { 
    612         int qr = 0x000000ff & lut[i][l]; 
    613         int qg = 0x000000ff & lut[i][l + 256]; 
    614         int qb = 0x000000ff & lut[i][l + 512]; 
    615         colors[i][0][l] = (float) qr; 
    616         colors[i][1][l] = (float) qg; 
    617         colors[i][2][l] = (float) qb; 
     597        colors[i][0][l] = (float) (lut[i][l] & 0xff); 
     598        colors[i][1][l] = (float) (lut[i][l + 256] & 0xff); 
     599        colors[i][2][l] = (float) (lut[i][l + 512] & 0xff); 
    618600      } 
    619601    } 
     
    690672      } 
    691673    } 
     674 
     675    core.indexed[0] = false; 
     676    core.falseColor[0] = false; 
    692677 
    693678    // Populate the metadata store 
  • trunk/loci/formats/in/DeltavisionReader.java

    r3184 r3197  
    4242 
    4343  private static final short LITTLE_ENDIAN = -16224; 
     44  private static final int HEADER_LENGTH = 1024; 
    4445 
    4546  // -- Fields -- 
    4647 
    47   /** Byte array containing basic image header data. */ 
    48   protected byte[] header; 
    49  
    50   /** Byte array containing extended header data. */ 
    51   protected byte[] extHeader; 
     48  /** Size of extended header. */ 
     49  private int extSize; 
    5250 
    5351  /** Bytes per pixel. */ 
     
    8280  // -- IFormatReader API methods -- 
    8381 
    84   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    85   public boolean isMetadataComplete() { 
    86     return true; 
    87   } 
    88  
    8982  /* @see loci.formats.IFormatReader#isThisType(byte[]) */ 
    9083  public boolean isThisType(byte[] block) { 
    9184    return false; 
    92   } 
    93  
    94   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    95   public byte[] openBytes(int no) throws FormatException, IOException { 
    96     FormatTools.assertId(currentId, true, 1); 
    97     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bytesPerPixel]; 
    98     return openBytes(no, buf); 
    9985  } 
    10086 
     
    10490  { 
    10591    FormatTools.assertId(currentId, true, 1); 
    106     if (no < 0 || no >= core.imageCount[0]) { 
    107       throw new FormatException("Invalid image number: " + no); 
    108     } 
     92    FormatTools.checkPlaneNumber(this, no); 
     93    FormatTools.checkBufferSize(this, buf.length); 
    10994 
    11095    // read the image plane's pixel data 
    111     long offset = header.length + extHeader.length; 
     96    long offset = HEADER_LENGTH + extSize; 
    11297    long bytes = core.sizeX[0] * core.sizeY[0] * bytesPerPixel; 
    113     offset += bytes * no; 
    114     in.seek(offset); 
     98    in.seek(offset + bytes*no); 
    11599    in.read(buf); 
    116100    return buf; 
     
    129113 
    130114    // read in the image header data 
    131     header = new byte[1024]; 
    132     in.read(header); 
    133  
    134     int endian = DataTools.bytesToShort(header, 96, 2, true); 
    135     core.littleEndian[0] = endian == LITTLE_ENDIAN; 
    136     RandomAccessStream hstream = new RandomAccessStream(header); 
    137     hstream.order(core.littleEndian[0]); 
    138  
    139     hstream.skipBytes(8); 
    140     core.imageCount[0] = hstream.readInt(); 
    141  
    142     hstream.seek(92); 
    143     int extSize = hstream.readInt(); 
    144     extHeader = new byte[extSize]; 
    145     in.read(extHeader); 
    146  
    147     hstream.seek(0); 
    148     core.sizeX[0] = hstream.readInt(); 
    149     core.sizeY[0] = hstream.readInt(); 
     115    in.seek(96); 
     116    in.order(true); 
     117    core.littleEndian[0] = in.readShort() == LITTLE_ENDIAN; 
     118 
     119    in.order(core.littleEndian[0]); 
     120    in.seek(8); 
     121 
     122    core.imageCount[0] = in.readInt(); 
     123 
     124    in.seek(92); 
     125    extSize = in.readInt(); 
     126 
     127    in.seek(0); 
     128    core.sizeX[0] = in.readInt(); 
     129    core.sizeY[0] = in.readInt(); 
    150130 
    151131    Integer xSize = new Integer(core.sizeX[0]); 
     
    153133    addMeta("ImageWidth", xSize); 
    154134    addMeta("ImageHeight", ySize); 
    155     addMeta("NumberOfImages", new Integer(hstream.readInt())); 
    156     int filePixelType = hstream.readInt(); 
     135    addMeta("NumberOfImages", new Integer(in.readInt())); 
     136    int filePixelType = in.readInt(); 
    157137    String pixel; 
    158138 
     
    195175 
    196176    addMeta("PixelType", pixel); 
    197     addMeta("Sub-image starting point (X)", new Integer(hstream.readInt())); 
    198     addMeta("Sub-image starting point (Y)", new Integer(hstream.readInt())); 
    199     addMeta("Sub-image starting point (Z)", new Integer(hstream.readInt())); 
    200     addMeta("Pixel sampling size (X)", new Integer(hstream.readInt())); 
    201     addMeta("Pixel sampling size (Y)", new Integer(hstream.readInt())); 
    202     addMeta("Pixel sampling size (Z)", new Integer(hstream.readInt())); 
    203  
    204     float pixX = hstream.readFloat(); 
    205     float pixY = hstream.readFloat(); 
    206     float pixZ = hstream.readFloat(); 
     177    addMeta("Sub-image starting point (X)", new Integer(in.readInt())); 
     178    addMeta("Sub-image starting point (Y)", new Integer(in.readInt())); 
     179    addMeta("Sub-image starting point (Z)", new Integer(in.readInt())); 
     180    addMeta("Pixel sampling size (X)", new Integer(in.readInt())); 
     181    addMeta("Pixel sampling size (Y)", new Integer(in.readInt())); 
     182    addMeta("Pixel sampling size (Z)", new Integer(in.readInt())); 
     183 
     184    float pixX = in.readFloat(); 
     185    float pixY = in.readFloat(); 
     186    float pixZ = in.readFloat(); 
    207187 
    208188    addMeta("X element length (in um)", new Float(pixX)); 
    209189    addMeta("Y element length (in um)", new Float(pixY)); 
    210190    addMeta("Z element length (in um)", new Float(pixZ)); 
    211     addMeta("X axis angle", new Float(hstream.readFloat())); 
    212     addMeta("Y axis angle", new Float(hstream.readFloat())); 
    213     addMeta("Z axis angle", new Float(hstream.readFloat())); 
    214     addMeta("Column axis sequence", new Integer(hstream.readInt())); 
    215     addMeta("Row axis sequence", new Integer(hstream.readInt())); 
    216     addMeta("Section axis sequence", new Integer(hstream.readInt())); 
    217     Float wave1Min = new Float(hstream.readFloat()); 
     191    addMeta("X axis angle", new Float(in.readFloat())); 
     192    addMeta("Y axis angle", new Float(in.readFloat())); 
     193    addMeta("Z axis angle", new Float(in.readFloat())); 
     194    addMeta("Column axis sequence", new Integer(in.readInt())); 
     195    addMeta("Row axis sequence", new Integer(in.readInt())); 
     196    addMeta("Section axis sequence", new Integer(in.readInt())); 
     197    Float wave1Min = new Float(in.readFloat()); 
    218198    addMeta("Wavelength 1 min. intensity", wave1Min); 
    219     Float wave1Max = new Float(hstream.readFloat()); 
     199    Float wave1Max = new Float(in.readFloat()); 
    220200    addMeta("Wavelength 1 max. intensity", wave1Max); 
    221     addMeta("Wavelength 1 mean intensity", new Float(hstream.readFloat())); 
    222     addMeta("Space group number", new Integer(hstream.readInt())); 
    223  
    224     hstream.seek(132); 
    225     addMeta("Number of Sub-resolution sets", new Integer(hstream.readShort())); 
    226     addMeta("Z axis reduction quotient", new Integer(hstream.readShort())); 
    227     Float wave2Min = new Float(hstream.readFloat()); 
     201    addMeta("Wavelength 1 mean intensity", new Float(in.readFloat())); 
     202    addMeta("Space group number", new Integer(in.readInt())); 
     203 
     204    in.seek(132); 
     205    addMeta("Number of Sub-resolution sets", new Integer(in.readShort())); 
     206    addMeta("Z axis reduction quotient", new Integer(in.readShort())); 
     207    Float wave2Min = new Float(in.readFloat()); 
    228208    addMeta("Wavelength 2 min. intensity", wave2Min); 
    229     Float wave2Max = new Float(hstream.readFloat()); 
     209    Float wave2Max = new Float(in.readFloat()); 
    230210    addMeta("Wavelength 2 max. intensity", wave2Max); 
    231211 
    232     Float wave3Min = new Float(hstream.readFloat()); 
     212    Float wave3Min = new Float(in.readFloat()); 
    233213    addMeta("Wavelength 3 min. intensity", wave3Min); 
    234214 
    235     Float wave3Max = new Float(hstream.readFloat()); 
     215    Float wave3Max = new Float(in.readFloat()); 
    236216    addMeta("Wavelength 3 max. intensity", wave3Max); 
    237217 
    238     Float wave4Min = new Float(hstream.readFloat()); 
     218    Float wave4Min = new Float(in.readFloat()); 
    239219    addMeta("Wavelength 4 min. intensity", wave4Min); 
    240220 
    241     Float wave4Max = new Float(hstream.readFloat()); 
     221    Float wave4Max = new Float(in.readFloat()); 
    242222    addMeta("Wavelength 4 max. intensity", wave4Max); 
    243223 
    244     int type = hstream.readShort(); 
     224    int type = in.readShort(); 
    245225    String imageType; 
    246226    switch (type) { 
     
    265245 
    266246    addMeta("Image Type", imageType); 
    267     addMeta("Lens ID Number", new Integer(hstream.readShort())); 
    268  
    269     hstream.seek(172); 
    270     Float wave5Min = new Float(hstream.readFloat()); 
     247    addMeta("Lens ID Number", new Integer(in.readShort())); 
     248 
     249    in.seek(172); 
     250    Float wave5Min = new Float(in.readFloat()); 
    271251    addMeta("Wavelength 5 min. intensity", wave5Min); 
    272252 
    273     Float wave5Max = new Float(hstream.readFloat()); 
     253    Float wave5Max = new Float(in.readFloat()); 
    274254    addMeta("Wavelength 5 max. intensity", wave5Max); 
    275255 
    276     core.sizeT[0] = hstream.readShort(); 
     256    core.sizeT[0] = in.readShort(); 
    277257    addMeta("Number of timepoints", new Integer(core.sizeT[0])); 
    278258 
    279     int sequence = hstream.readShort(); 
     259    int sequence = in.readShort(); 
    280260    String imageSequence; 
    281261    switch (sequence) { 
     
    297277    addMeta("Image sequence", imageSequence); 
    298278 
    299     addMeta("X axis tilt angle", new Float(hstream.readFloat())); 
    300     addMeta("Y axis tilt angle", new Float(hstream.readFloat())); 
    301     addMeta("Z axis tilt angle", new Float(hstream.readFloat())); 
    302  
    303     core.sizeC[0] = hstream.readShort(); 
     279    addMeta("X axis tilt angle", new Float(in.readFloat())); 
     280    addMeta("Y axis tilt angle", new Float(in.readFloat())); 
     281    addMeta("Z axis tilt angle", new Float(in.readFloat())); 
     282 
     283    core.sizeC[0] = in.readShort(); 
    304284    addMeta("Number of wavelengths", new Integer(core.sizeC[0])); 
    305285    core.sizeZ[0] = core.imageCount[0] / (core.sizeC[0] * core.sizeT[0]); 
     
    308288    core.rgb[0] = false; 
    309289    core.interleaved[0] = false; 
     290    core.metadataComplete[0] = true; 
     291    core.indexed[0] = false; 
     292    core.falseColor[0] = false; 
    310293 
    311294    short[] waves = new short[5]; 
    312     for (int i=0; i<waves.length; i++) waves[i] = hstream.readShort(); 
     295    for (int i=0; i<waves.length; i++) waves[i] = in.readShort(); 
    313296 
    314297    addMeta("Wavelength 1 (in nm)", new Integer(waves[0])); 
     
    317300    addMeta("Wavelength 4 (in nm)", new Integer(waves[3])); 
    318301    addMeta("Wavelength 5 (in nm)", new Integer(waves[4])); 
    319     addMeta("X origin (in um)", new Float(hstream.readFloat())); 
    320     addMeta("Y origin (in um)", new Float(hstream.readFloat())); 
    321     addMeta("Z origin (in um)", new Float(hstream.readFloat())); 
     302    addMeta("X origin (in um)", new Float(in.readFloat())); 
     303    addMeta("Y origin (in um)", new Float(in.readFloat())); 
     304    addMeta("Z origin (in um)", new Float(in.readFloat())); 
    322305 
    323306    // The metadata store we're working with. 
    324307    MetadataStore store = getMetadataStore(); 
    325308 
     309    in.seek(224); 
     310 
    326311    String title = null; 
    327     for (int i=10; i>=1; i--) { 
     312    for (int i=1; i<=10; i++) { 
    328313      // Make sure that "null" characters are stripped out 
    329       title = new String(header, 224 + 80*(i-1), 80).replaceAll("\0", ""); 
     314      title = in.readString(80).replaceAll("\0", ""); 
    330315      addMeta("Title " + i, title); 
    331316    } 
     
    335320    status("Reading extended header"); 
    336321 
    337     hstream.seek(128); 
    338     numIntsPerSection = hstream.readShort(); 
    339     numFloatsPerSection = hstream.readShort(); 
     322    in.seek(128); 
     323    numIntsPerSection = in.readShort(); 
     324    numFloatsPerSection = in.readShort(); 
    340325    setOffsetInfo(sequence, core.sizeZ[0], core.sizeC[0], core.sizeT[0]); 
    341326    extHdrFields = 
    342327      new DVExtHdrFields[core.sizeZ[0]][core.sizeC[0]][core.sizeT[0]]; 
    343  
    344     hstream.close(); 
    345328 
    346329    FormatTools.populatePixels(store, this); 
     
    358341      for (int t=0; t<core.sizeT[0]; t++) { 
    359342        for (int w=0; w<core.sizeC[0]; w++) { 
     343          in.seek(HEADER_LENGTH); 
    360344          extHdrFields[z][w][t] = new DVExtHdrFields(getTotalOffset(z, w, t), 
    361             numIntsPerSection, extHeader, core.littleEndian[0]); 
     345            numIntsPerSection, in, core.littleEndian[0]); 
    362346 
    363347          store.setPlaneInfo(z, w, t, 
     
    561545     * @param startingOffset 
    562546     * @param numIntsPerSection 
    563      * @param extHeader 
     547     * @param in  
    564548     * @param little 
    565549     */ 
    566550    protected DVExtHdrFields(int startingOffset, int numIntsPerSection, 
    567       byte[] extHeader, boolean little) 
     551      RandomAccessStream in, boolean little) 
    568552    { 
    569553      try { 
    570         RandomAccessStream ext = new RandomAccessStream(extHeader); 
    571         ext.order(little); 
    572  
     554        long fp = in.getFilePointer(); 
    573555        // skip over the int values that have nothing in them 
    574556        offsetWithInts = startingOffset + (numIntsPerSection * 4); 
     
    578560        // (optical density) rating. 
    579561        // To convert from one to the other the formula is %T = 10^(-OD) X 100. 
    580         ext.seek(offsetWithInts + 36); 
    581         oDFilter = ext.readFloat(); 
     562        in.skipBytes(offsetWithInts + 36); 
     563        oDFilter = in.readFloat(); 
    582564 
    583565        // fill in the extended header information for the floats 
    584         ext.seek(offsetWithInts); 
    585         photosensorReading = ext.readFloat(); 
    586         timeStampSeconds = ext.readFloat(); 
    587         stageXCoord = ext.readFloat(); 
    588         stageYCoord = ext.readFloat(); 
    589         stageZCoord = ext.readFloat(); 
    590         minInten = ext.readFloat(); 
    591         maxInten = ext.readFloat(); 
    592         meanInten = ext.readFloat(); 
    593         expTime = ext.readFloat(); 
     566        in.seek(fp + offsetWithInts); 
     567        photosensorReading = in.readFloat(); 
     568        timeStampSeconds = in.readFloat(); 
     569        stageXCoord = in.readFloat(); 
     570        stageYCoord = in.readFloat(); 
     571        stageZCoord = in.readFloat(); 
     572        minInten = in.readFloat(); 
     573        maxInten = in.readFloat(); 
     574        meanInten = in.readFloat(); 
     575        expTime = in.readFloat(); 
    594576        ndFilter = (float) Math.pow(10.0, -oDFilter); 
    595         ext.skipBytes(4); 
    596  
    597         exFilter = ext.readFloat(); 
    598         emFilter = ext.readFloat(); 
    599         exWavelen = ext.readFloat(); 
    600         emWavelen = ext.readFloat(); 
    601         intenScaling = ext.readFloat(); 
    602         energyConvFactor = ext.readFloat(); 
     577        in.skipBytes(4); 
     578 
     579        exFilter = in.readFloat(); 
     580        emFilter = in.readFloat(); 
     581        exWavelen = in.readFloat(); 
     582        emWavelen = in.readFloat(); 
     583        intenScaling = in.readFloat(); 
     584        energyConvFactor = in.readFloat(); 
    603585      } 
    604586      catch (IOException e) { 
  • trunk/loci/formats/in/DicomReader.java

    r3192 r3197  
    3030import loci.formats.*; 
    3131import loci.formats.codec.*; 
    32  
    33 //import javax.imageio.ImageIO; 
    34 //import javax.imageio.stream.*; 
    3532 
    3633/** 
     
    7067  private static final int PIXEL_DATA = 0x7FE00010; 
    7168 
    72   private static final int AE=0x4145, AS=0x4153, AT=0x4154, CS=0x4353; 
    73   private static final int DA=0x4441, DS=0x4453, DT=0x4454, FD=0x4644; 
    74   private static final int FL=0x464C, IS=0x4953, LO=0x4C4F, LT=0x4C54; 
    75   private static final int PN=0x504E, SH=0x5348, SL=0x534C, SS=0x5353; 
    76   private static final int ST=0x5354, TM=0x544D, UI=0x5549, UL=0x554C; 
    77   private static final int US=0x5553, UT=0x5554, OB=0x4F42, OW=0x4F57; 
    78   private static final int SQ=0x5351, UN=0x554E, QQ=0x3F3F; 
     69  private static final int AE = 0x4145, AS = 0x4153, AT = 0x4154, CS = 0x4353; 
     70  private static final int DA = 0x4441, DS = 0x4453, DT = 0x4454, FD = 0x4644; 
     71  private static final int FL = 0x464C, IS = 0x4953, LO = 0x4C4F, LT = 0x4C54; 
     72  private static final int PN = 0x504E, SH = 0x5348, SL = 0x534C, SS = 0x5353; 
     73  private static final int ST = 0x5354, TM = 0x544D, UI = 0x5549, UL = 0x554C; 
     74  private static final int US = 0x5553, UT = 0x5554, OB = 0x4F42, OW = 0x4F57; 
     75  private static final int SQ = 0x5351, UN = 0x554E, QQ = 0x3F3F; 
    7976 
    8077  private static final int IMPLICIT_VR = 0x2d2d; 
     
    9491  private boolean inSequence; 
    9592  private boolean bigEndianTransferSyntax; 
    96   private boolean indexed = false; 
    9793  private byte[][] lut; 
    9894 
     
    115111  } 
    116112 
    117   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    118   public boolean isMetadataComplete() { 
    119     return true; 
    120   } 
    121  
    122   /* @see loci.formats.IFormatReader#isIndexed() */ 
    123   public boolean isIndexed() { 
    124     FormatTools.assertId(currentId, true, 1); 
    125     return indexed; 
    126   } 
    127  
    128113  /* @see loci.formats.IFormatReader#get8BitLookupTable() */ 
    129114  public byte[][] get8BitLookupTable() { 
     
    132117  } 
    133118 
    134   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    135   public byte[] openBytes(int no) throws FormatException, IOException { 
    136     FormatTools.assertId(currentId, true, 1); 
    137     int bytes = core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8); 
    138     if (!indexed) bytes *= core.sizeC[0]; 
    139     byte[] buf = new byte[bytes]; 
    140     return openBytes(no, buf); 
    141   } 
    142  
    143119  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    144120  public byte[] openBytes(int no, byte[] buf) 
     
    146122  { 
    147123    FormatTools.assertId(currentId, true, 1); 
    148     if (no < 0 || no >= getImageCount()) { 
    149       throw new FormatException("Invalid image number: " + no); 
    150     } 
    151  
    152     int plane = core.sizeX[0] * core.sizeY[0] * core.sizeC[0]; 
    153     int bytes = core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8); 
    154     if (!indexed) bytes *= core.sizeC[0]; 
    155  
    156     if (buf.length < bytes) { 
    157       throw new FormatException("Buffer too small."); 
    158     } 
    159  
     124    FormatTools.checkPlaneNumber(this, no); 
     125    FormatTools.checkBufferSize(this, buf.length); 
     126 
     127    int bytes = core.sizeX[0] * core.sizeY[0] * 
     128      FormatTools.getBytesPerPixel(core.pixelType[0]) * 
     129      (isIndexed() ? 1 : core.sizeC[0]); 
    160130    in.seek(offsets + bytes * no); 
    161131    if (isRLE) { 
     
    171141 
    172142      int b = FormatTools.getBytesPerPixel(core.pixelType[0]); 
     143      int plane = bytes / b; 
    173144      if (b > 1) { 
    174145        byte[][] tmp = new byte[b][plane]; 
     
    329300    core.currentOrder[0] = "XYCZT"; 
    330301    core.interleaved[0] = !(isJPEG || isRLE); 
     302    core.metadataComplete[0] = true; 
     303    core.falseColor[0] = false; 
    331304 
    332305    // The metadata store we're working with. 
     
    398371      else if (key.equals("Photometric Interpretation")) { 
    399372        if (info.trim().equals("PALETTE COLOR")) { 
    400           indexed = true; 
     373          core.indexed[0] = true; 
    401374          core.sizeC[0] = 3; 
    402375          core.rgb[0] = true; 
  • trunk/loci/formats/in/EPSReader.java

    r3184 r3197  
    7070  } 
    7171 
    72   /* @see loci.formats.IFormatRaeder#openBytes(int) */ 
    73   public byte[] openBytes(int no) throws FormatException, IOException { 
    74     FormatTools.assertId(currentId, true, 1); 
    75     byte[] buf = 
    76       new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * (bps / 8)]; 
    77     return openBytes(no, buf); 
    78   } 
    79  
    8072  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    8173  public byte[] openBytes(int no, byte[] buf) 
     
    8375  { 
    8476    FormatTools.assertId(currentId, true, 1); 
    85     if (no < 0 || no >= getImageCount()) { 
    86       throw new FormatException("Invalid image number: " + no); 
    87     } 
    88     if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * (bps / 8)) 
    89     { 
    90       throw new FormatException("Buffer too small."); 
    91     } 
     77    FormatTools.checkPlaneNumber(this, no); 
     78    FormatTools.checkBufferSize(this, buf.length); 
    9279 
    9380    if (isTiff) { 
     
    195182      core.imageCount[0] = 1; 
    196183      core.currentOrder[0] = "XYCZT"; 
     184      core.metadataComplete[0] = true; 
     185      core.indexed[0] = false; 
     186      core.falseColor[0] = false; 
     187 
     188      MetadataStore store = getMetadataStore(); 
     189      store.setImage(currentId, null, null, null); 
     190 
     191      FormatTools.populatePixels(store, this); 
     192      for (int i=0; i<core.sizeC[0]; i++) { 
     193        store.setLogicalChannel(i, null, null, null, null, null, null, null, 
     194         null, null, null, null, null, null, null, null, null, null, null, 
     195         null, null, null, null, null, null); 
     196      } 
    197197 
    198198      return; 
     
    290290    // The metadata store we're working with. 
    291291    MetadataStore store = getMetadataStore(); 
    292  
    293292    store.setImage(currentId, null, null, null); 
    294293 
  • trunk/loci/formats/in/FitsReader.java

    r3184 r3197  
    5757  } 
    5858 
    59   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    60   public byte[] openBytes(int no) throws FormatException, IOException { 
    61     FormatTools.assertId(currentId, true, 1); 
    62     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * 
    63       FormatTools.getBytesPerPixel(core.pixelType[0])]; 
    64     return openBytes(no, buf); 
    65   } 
    66  
    6759  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    6860  public byte[] openBytes(int no, byte[] buf) 
     
    7062  { 
    7163    FormatTools.assertId(currentId, true, 1); 
    72     if (no < 0 || no >= getImageCount()) { 
    73       throw new FormatException("Invalid image number: " + no); 
    74     } 
    75     if (buf.length < core.sizeX[0] * core.sizeY[0] * 
    76       FormatTools.getBytesPerPixel(core.pixelType[0])) 
    77     { 
    78       throw new FormatException("Buffer too small."); 
    79     } 
     64    FormatTools.checkPlaneNumber(this, no); 
     65    FormatTools.checkBufferSize(this, buf.length); 
    8066 
    8167    in.seek(2880 + 2880 * (((count * 80) - 1) / 2880)); 
     
    144130    core.interleaved[0] = false; 
    145131    core.currentOrder[0] = "XYZCT"; 
     132    core.indexed[0] = false; 
     133    core.falseColor[0] = false; 
     134    core.metadataComplete[0] = true; 
    146135 
    147136    MetadataStore store = getMetadataStore(); 
     
    151140 
    152141    store.setLogicalChannel(0, null, null, null, null, null, null, null, null, 
    153       null, null, null, null, "monochrome", null, null, null, null, null, null, 
     142      null, null, null, null, null, null, null, null, null, null, null, 
    154143      null, null, null, null, null); 
    155144  } 
  • trunk/loci/formats/in/FluoviewReader.java

    r3132 r3197  
    101101  } 
    102102 
    103   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    104   public boolean isMetadataComplete() { 
    105     return true; 
    106   } 
    107  
    108103  /* @see loci.formats.IFormatReader#openBytes(int) */ 
    109104  public byte[] openBytes(int no) throws FormatException, IOException { 
     
    270265    core.sizeZ[0] = core.sizeC[0] = core.sizeT[0] = 1; 
    271266    core.currentOrder[0] = "XY"; 
     267    core.metadataComplete[0] = true; 
    272268 
    273269    for (int i=0; i<10; i++) { 
  • trunk/loci/formats/in/GIFReader.java

    r3185 r3197  
    110110  public boolean isThisType(byte[] block) { return false; } 
    111111 
    112   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    113   public boolean isMetadataComplete() { 
    114     return true; 
    115   } 
    116  
    117   /* @see loci.formats.IFormatReader#isIndexed() */ 
    118   public boolean isIndexed() { 
    119     return true; 
    120   } 
    121  
    122112  /* @see loci.formats.IFormatReader#get8BitLookupTable() */ 
    123113  public byte[][] get8BitLookupTable() throws FormatException, IOException { 
     
    132122  } 
    133123 
    134   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    135   public byte[] openBytes(int no) throws FormatException, IOException { 
    136     FormatTools.assertId(currentId, true, 1); 
    137     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0]]; 
    138     return openBytes(no, buf); 
    139   } 
    140  
    141124  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    142125  public byte[] openBytes(int no, byte[] buf) 
     
    144127  { 
    145128    FormatTools.assertId(currentId, true, 1); 
    146     if (no < 0 || no >= getImageCount()) { 
    147       throw new FormatException("Invalid image number: " + no); 
    148     } 
    149     if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0]) { 
    150       throw new FormatException("Buffer too small."); 
    151     } 
     129    FormatTools.checkPlaneNumber(this, no); 
     130    FormatTools.checkBufferSize(this, buf.length); 
    152131 
    153132    act = (int[]) colorTables.get(no); 
     
    157136      byte[] prev = (byte[]) images.get(no - 1); 
    158137      for (int i=0; i<buf.length; i++) { 
    159         if ((act[buf[i] & 0xff] & 0x00ffffff) == 0) { 
     138        if ((act[buf[i] & 0xff] & 0xffffff) == 0) { 
    160139          buf[i] = prev[i]; 
    161140        } 
     
    336315    core.littleEndian[0] = true; 
    337316    core.interleaved[0] = true; 
     317    core.metadataComplete[0] = true; 
     318    core.indexed[0] = true; 
     319    core.falseColor[0] = false; 
    338320 
    339321    // populate metadata store 
  • trunk/loci/formats/in/GatanReader.java

    r3184 r3197  
    6666  } 
    6767 
    68   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    69   public boolean isMetadataComplete() { 
    70     return true; 
    71   } 
    72  
    73   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    74   public byte[] openBytes(int no) throws FormatException, IOException { 
    75     FormatTools.assertId(currentId, true, 1); 
    76     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bytesPerPixel]; 
    77     return openBytes(no, buf); 
    78   } 
    79  
    8068  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    8169  public byte[] openBytes(int no, byte[] buf) 
     
    8371  { 
    8472    FormatTools.assertId(currentId, true, 1); 
    85     if (no != 0) { 
    86       throw new FormatException("Invalid image number: " + no); 
    87     } 
    88     if (buf.length < core.sizeX[0] * core.sizeY[0] * bytesPerPixel) { 
    89       throw new FormatException("Buffer too small."); 
    90     } 
     73    FormatTools.checkPlaneNumber(this, no); 
     74    FormatTools.checkBufferSize(this, buf.length); 
    9175 
    9276    in.seek(pixelOffset); 
     
    158142    core.rgb[0] = false; 
    159143    core.interleaved[0] = false; 
     144    core.metadataComplete[0] = true; 
     145    core.indexed[0] = false; 
     146    core.falseColor[0] = false; 
    160147 
    161148    // The metadata store we're working with. 
  • trunk/loci/formats/in/GelReader.java

    r3132 r3197  
    6363  public boolean isThisType(byte[] block) { return false; } 
    6464 
    65   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    66   public boolean isMetadataComplete() { 
    67     return true; 
    68   } 
    69  
    7065  // -- Internal BaseTiffReader API methods -- 
    7166 
  • trunk/loci/formats/in/ICSReader.java

    r3184 r3197  
    114114  } 
    115115 
    116   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    117   public byte[] openBytes(int no) throws FormatException, IOException { 
    118     FormatTools.assertId(currentId, true, 1); 
    119     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8) * 
    120       getRGBChannelCount()]; 
    121     return openBytes(no, buf); 
    122   } 
    123  
    124116  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    125117  public byte[] openBytes(int no, byte[] buf) 
     
    127119  { 
    128120    FormatTools.assertId(currentId, true, 1); 
    129     if (no < 0 || no >= getImageCount()) { 
    130       throw new FormatException("Invalid image number: " + no); 
    131     } 
    132     if (buf.length < core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8) * 
    133       getRGBChannelCount()) 
    134     { 
    135       throw new FormatException("Buffer too small."); 
    136     } 
     121    FormatTools.checkPlaneNumber(this, no); 
     122    FormatTools.checkBufferSize(this, buf.length); 
    137123 
    138124    int bpp = bitsPerPixel / 8; 
     
    323309    if (core.imageCount[0] == 0) core.imageCount[0] = 1; 
    324310    core.rgb[0] = core.rgb[0] && core.sizeC[0] > 1; 
    325     core.interleaved[0] = !core.rgb[0]; 
     311    core.interleaved[0] = core.rgb[0]; 
    326312    core.imageCount[0] = core.sizeZ[0] * core.sizeT[0]; 
    327313    if (!core.rgb[0]) core.imageCount[0] *= core.sizeC[0]; 
     314    core.indexed[0] = false; 
     315    core.falseColor[0] = false; 
     316    core.metadataComplete[0] = true; 
    328317 
    329318    String endian = byteOrder; 
  • trunk/loci/formats/in/IPLabReader.java

    r3184 r3197  
    6565    if (size != 4) return false; // first block size should be 4 
    6666    int version = DataTools.bytesToInt(block, 8, 4, little); 
    67     if (version < 0x100e) return false; // invalid version 
    68     return true; 
    69   } 
    70  
    71   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    72   public byte[] openBytes(int no) throws FormatException, IOException { 
    73     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bps * core.sizeC[0]]; 
    74     return openBytes(no, buf); 
     67    return version >= 0x100e; 
    7568  } 
    7669 
     
    8073  { 
    8174    FormatTools.assertId(currentId, true, 1); 
    82     if (no < 0 || no >= getImageCount()) { 
    83       throw new FormatException("Invalid image number: " + no); 
    84     } 
    85  
    86     int numPixels = core.sizeX[0] * core.sizeY[0] * core.sizeC[0]; 
    87     if (buf.length < numPixels * bps) { 
    88       throw new FormatException("Buffer too small."); 
    89     } 
    90     in.seek(numPixels * bps * (no / core.sizeC[0]) + 44); 
    91  
     75    FormatTools.checkPlaneNumber(this, no); 
     76    FormatTools.checkBufferSize(this, buf.length); 
     77 
     78    int numPixels = core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * bps; 
     79    in.seek(numPixels * (no / core.sizeC[0]) + 44); 
    9280    in.read(buf); 
    9381    return buf; 
     
    129117    String ptype; 
    130118    bps = 1; 
    131     switch ((int) filePixelType) { 
     119    switch (filePixelType) { 
    132120      case 0: 
    133121        ptype = "8 bit unsigned"; 
     
    162150      case 6: 
    163151        ptype = "Color48"; 
    164         core.pixelType[0] = FormatTools.UINT32; 
     152        core.pixelType[0] = FormatTools.UINT16; 
    165153        bps = 2; 
    166154        break; 
     
    182170 
    183171    core.rgb[0] = core.sizeC[0] > 1; 
    184     core.interleaved[0] = true; 
     172    core.interleaved[0] = false; 
     173    core.indexed[0] = false; 
     174    core.falseColor[0] = false; 
     175    core.metadataComplete[0] = true; 
    185176 
    186177    // The metadata store we're working with. 
    187178    MetadataStore store = getMetadataStore(); 
    188  
     179    store.setImage(currentId, null, null, null); 
    189180    FormatTools.populatePixels(store, this); 
    190181 
     
    219210          // explicitly defined lookup table 
    220211          // length is 772 
    221           in.skipBytes(4 + 256 * 3); 
     212          in.skipBytes(772); 
    222213        } 
    223214      } 
     
    232223        } 
    233224 
     225        String[] types = new String[] { 
     226          "user", "plane", "sequence", "saturated plane", 
     227          "saturated sequence", "ROI" 
     228        }; 
     229 
    234230        for (int i=0; i<core.sizeC[0]; i++) { 
    235231          int source = in.readInt(); 
    236           String[] types = new String[] { 
    237             "user", "plane", "sequence", "saturated plane", 
    238             "saturated sequence", "ROI" 
    239           }; 
    240232 
    241233          String sourceType = (source >= 0 && source < types.length) ? 
     
    267259 
    268260        int size = in.readInt(); 
    269  
    270261        for (int i=0; i<size / 22; i++) { 
    271262          int num = in.readShort(); 
    272           String name = in.readString(20); 
    273           addMeta("Header" + num, name); 
     263          addMeta("Header" + num, in.readString(20)); 
    274264        } 
    275265      } 
     
    291281        Integer y0 = new Integer(roiBottom); 
    292282        Integer y1 = new Integer(roiTop); 
    293         store.setDisplayROI( 
    294           x0, y0, null, x1, y1, null, null, null, null, null); 
     283        store.setDisplayROI(x0, y0, null, x1, y1, null, null, null, null, null); 
    295284 
    296285        in.skipBytes(8 * numRoiPts); 
     
    322311      else if (tag.equals("view")) { 
    323312        // read in view 
    324         in.readInt(); 
     313        in.skipBytes(4); 
    325314      } 
    326315      else if (tag.equals("plot")) { 
     
    331320      else if (tag.equals("notes")) { 
    332321        // read in notes (image info) 
    333         in.readInt(); // size is 576 
     322        in.skipBytes(4); 
    334323        String descriptor = in.readString(64); 
    335324        String notes = in.readString(512); 
  • trunk/loci/formats/in/IPWReader.java

    r3185 r3197  
    8989  } 
    9090 
    91   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    92   public byte[] openBytes(int no) throws FormatException, IOException { 
    93     FormatTools.assertId(currentId, true, 1); 
    94     int c = getRGBChannelCount(); 
    95     if (c == 2) c++; 
    96     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * c * 
    97       FormatTools.getBytesPerPixel(core.pixelType[0])]; 
    98     return openBytes(no, buf); 
    99   } 
    100  
    10191  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    10292  public byte[] openBytes(int no, byte[] buf) 
     
    10494  { 
    10595    FormatTools.assertId(currentId, true, 1); 
    106     if (no < 0 || no >= getImageCount()) { 
    107       throw new FormatException("Invalid image number: " + no); 
    108     } 
    109     if (buf.length < core.sizeX[0] * core.sizeY[0] * 
    110       FormatTools.getBytesPerPixel(core.pixelType[0]) * 
    111       ((isRGB() && !isIndexed()) ? core.sizeC[0] : 1)) 
    112     { 
    113       throw new FormatException("Buffer too small."); 
    114     } 
     96    FormatTools.checkPlaneNumber(this, no); 
     97    FormatTools.checkBufferSize(this, buf.length); 
    11598 
    11699    RandomAccessStream stream = getStream(no); 
     
    338321    } 
    339322 
    340     core.interleaved[0] = true; 
    341323  } 
    342324 
  • trunk/loci/formats/in/ImageIOReader.java

    r3175 r3197  
    5959  public boolean isThisType(byte[] block) { return false; } 
    6060 
    61   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    62   public boolean isMetadataComplete() { 
    63     return true; 
    64   } 
    65  
    66   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    67   public byte[] openBytes(int no) throws FormatException, IOException { 
    68     FormatTools.assertId(currentId, true, 1); 
    69     byte[] b = ImageTools.getBytes(openImage(no), false, no); 
     61  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     62  public byte[] openBytes(int no, byte[] buf) 
     63    throws FormatException, IOException 
     64  { 
     65    buf = ImageTools.getBytes(openImage(no), false, no); 
    7066    int bytesPerChannel = core.sizeX[0] * core.sizeY[0]; 
    71     if (b.length > bytesPerChannel) { 
    72       byte[] tmp = b; 
    73       b = new byte[bytesPerChannel * 3]; 
     67    if (buf.length > bytesPerChannel) { 
     68      byte[] tmp = buf; 
     69      buf = new byte[bytesPerChannel * 3]; 
    7470      for (int i=0; i<3; i++) { 
    75         System.arraycopy(tmp, i * bytesPerChannel, b, i*bytesPerChannel, 
     71        System.arraycopy(tmp, i * bytesPerChannel, buf, i*bytesPerChannel, 
    7672          bytesPerChannel); 
    7773      } 
    7874    } 
    79     return b; 
     75    return buf; 
    8076  } 
    8177 
     
    127123    core.currentOrder[0] = "XYCZT"; 
    128124    core.pixelType[0] = ImageTools.getPixelType(img); 
    129     core.interleaved[0] = true; 
     125    core.interleaved[0] = false; 
    130126    core.littleEndian[0] = false; 
     127    core.metadataComplete[0] = true; 
     128    core.indexed[0] = false; 
     129    core.falseColor[0] = false; 
    131130 
    132131    // populate the metadata store 
  • trunk/loci/formats/in/ImarisReader.java

    r3184 r3197  
    6666  } 
    6767 
    68   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    69   public byte[] openBytes(int no) throws FormatException, IOException { 
    70     FormatTools.assertId(currentId, true, 1); 
    71     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0]]; 
    72     return openBytes(no, buf); 
    73   } 
    74  
    7568  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    7669  public byte[] openBytes(int no, byte[] buf) 
     
    7871  { 
    7972    FormatTools.assertId(currentId, true, 1); 
    80     if (no < 0 || no >= getImageCount()) { 
    81       throw new FormatException("Invalid image number: " + no); 
    82     } 
    83     if (buf.length < core.sizeX[0] * core.sizeY[0]) { 
    84       throw new FormatException("Buffer too small."); 
    85     } 
     73    FormatTools.checkPlaneNumber(this, no); 
     74    FormatTools.checkBufferSize(this, buf.length); 
    8675 
    8776    in.seek(offsets[no]); 
     
    176165    core.interleaved[0] = false; 
    177166    core.littleEndian[0] = IS_LITTLE; 
     167    core.indexed[0] = false; 
     168    core.falseColor[0] = false; 
     169    core.metadataComplete[0] = true; 
    178170 
    179171    // The metadata store we're working with. 
     
    181173 
    182174    core.pixelType[0] = FormatTools.UINT8; 
     175 
     176    store.setImage(currentId, null, null, null); 
    183177    FormatTools.populatePixels(store, this); 
    184  
    185     String d = (String) getMeta("Original date"); 
    186     if (d == null || d.trim().length() == 0) d = null; 
    187  
    188     String fname = (String) getMeta("Image name"); 
    189     if (fname == null) fname = currentId; 
    190     store.setImage(fname, d, (String) getMeta("Image comment"), null); 
    191178 
    192179    store.setDimensions(new Float(dx), new Float(dy), new Float(dz), 
  • trunk/loci/formats/in/ImarisTiffReader.java

    r3175 r3197  
    8181  } 
    8282 
    83   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    84   public boolean isMetadataComplete() { 
    85     return true; 
    86   } 
    87  
    8883  // -- IFormatHandler API methods -- 
    8984 
  • trunk/loci/formats/in/KhorosReader.java

    r3185 r3197  
    5757  } 
    5858 
    59   /* @see loci.formats.IFormatReader#isIndexed() */ 
    60   public boolean isIndexed() { 
    61     FormatTools.assertId(currentId, true, 1); 
    62     return lut != null; 
    63   } 
    64  
    6559  /* @see loci.formats.IFormatReader#get8BitLookupTable() */ 
    6660  public byte[][] get8BitLookupTable() throws FormatException, IOException { 
    6761    FormatTools.assertId(currentId, true, 1); 
     62    if (lut == null) return null; 
    6863    byte[][] table = new byte[3][lut.length / 3]; 
    6964    int next = 0; 
     
    7671  } 
    7772 
    78   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    79   public byte[] openBytes(int no) throws FormatException, IOException { 
    80     FormatTools.assertId(currentId, true, 1); 
    81     int bufSize = core.sizeX[0] * core.sizeY[0] * 
    82       FormatTools.getBytesPerPixel(core.pixelType[0]); 
    83     if (!isIndexed()) bufSize *= core.sizeC[0]; 
    84     byte[] buf = new byte[bufSize]; 
    85     return openBytes(no, buf); 
    86   } 
    87  
    8873  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    8974  public byte[] openBytes(int no, byte[] buf) 
     
    9176  { 
    9277    FormatTools.assertId(currentId, true, 1); 
    93     if (no < 0 || no >= core.imageCount[0]) { 
    94       throw new FormatException("Invalid image number: " + no); 
    95     } 
     78    FormatTools.checkPlaneNumber(this, no); 
     79    FormatTools.checkBufferSize(this, buf.length); 
    9680 
    9781    int bufSize = core.sizeX[0] * core.sizeY[0] * 
    9882      FormatTools.getBytesPerPixel(core.pixelType[0]); 
    99     if (!isIndexed()) bufSize *= core.sizeC[0]; 
    100     if (buf.length < bufSize) throw new FormatException("Buffer too small."); 
    10183 
    10284    in.seek(offset + no * bufSize); 
     
    186168    core.littleEndian[0] = dependency == 4 || dependency == 8; 
    187169    core.currentOrder[0] = "XYCZT"; 
     170    core.indexed[0] = lut != null; 
     171    core.falseColor[0] = false; 
     172    core.metadataComplete[0] = true; 
    188173 
    189174    MetadataStore store = getMetadataStore(); 
     
    193178    for (int i=0; i<core.sizeC[0]; i++) { 
    194179      store.setLogicalChannel(i, null, null, null, null, null, null, null, null, 
    195         null, null, null, null, core.sizeC[0] == 1 ? "monochrome" : "RGB", null, 
     180        null, null, null, null, null, null, 
    196181        null, null, null, null, null, null, null, null, null, null); 
    197182    } 
  • trunk/loci/formats/in/LIFReader.java

    r3184 r3197  
    8181  } 
    8282 
    83   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    84   public boolean isMetadataComplete() { 
    85     return true; 
    86   } 
    87  
    88   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    89   public byte[] openBytes(int no) throws FormatException, IOException { 
    90     FormatTools.assertId(currentId, true, 1); 
    91     bpp = bitsPerPixel[series]; 
    92     while (bpp % 8 != 0) bpp++; 
    93     byte[] buf = new byte[core.sizeX[series] * core.sizeY[series] * 
    94       (bpp / 8) * getRGBChannelCount()]; 
    95     return openBytes(no, buf); 
    96   } 
    97  
    9883  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    9984  public byte[] openBytes(int no, byte[] buf) 
     
    10186  { 
    10287    FormatTools.assertId(currentId, true, 1); 
    103     if (no < 0 || no >= getImageCount()) { 
    104       throw new FormatException("Invalid image number: " + no); 
    105     } 
    106     bpp = bitsPerPixel[series]; 
    107     while (bpp % 8 != 0) bpp++; 
    108     int bytes = bpp / 8; 
    109     if (buf.length < core.sizeX[series] * core.sizeY[series] * bytes * 
    110       getRGBChannelCount()) 
    111     { 
    112       throw new FormatException("Buffer too small."); 
    113     } 
     88    FormatTools.checkPlaneNumber(this, no); 
     89    FormatTools.checkBufferSize(this, buf.length); 
    11490 
    11591    long offset = ((Long) offsets.get(series)).longValue(); 
    116     in.seek(offset + core.sizeX[series] * core.sizeY[series] * 
    117       bytes * no * getRGBChannelCount()); 
     92    in.seek(offset + core.sizeX[series] * core.sizeY[series] * no * 
     93      FormatTools.getBytesPerPixel(getPixelType()) * getRGBChannelCount()); 
    11894 
    11995    in.read(buf); 
     
    440416      } 
    441417 
     418      core.metadataComplete[i] = true; 
    442419      core.littleEndian[i] = true; 
    443       core.rgb[i] = core.sizeC[i] > 1 && core.sizeC[i] < 4; 
    444       core.interleaved[i] = true; 
     420      core.rgb[i] = false; 
     421      core.interleaved[i] = false; 
    445422      core.imageCount[i] = core.sizeZ[i] * core.sizeT[i]; 
    446       if (!core.rgb[i]) core.imageCount[i] *= core.sizeC[i]; 
     423      core.imageCount[i] *= core.sizeC[i]; 
     424      core.indexed[i] = false; 
     425      core.falseColor[i] = false; 
    447426 
    448427      while (bitsPerPixel[i] % 8 != 0) bitsPerPixel[i]++; 
  • trunk/loci/formats/in/LegacyPictReader.java

    r3175 r3197  
    5656  } 
    5757 
    58   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    59   public byte[] openBytes(int no) throws FormatException, IOException { 
    60     return ImageTools.getBytes(openImage(no), false, 3); 
     58  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     59  public byte[] openBytes(int no, byte[] buf) 
     60    throws FormatException, IOException 
     61  { 
     62    buf = ImageTools.getBytes(openImage(no), false, 3); 
     63    return buf; 
    6164  } 
    6265 
     
    106109    core.imageCount[0] = 1; 
    107110    core.littleEndian[0] = false; 
     111    core.indexed[0] = false; 
     112    core.falseColor[0] = false; 
    108113 
    109114    MetadataStore store = getMetadataStore(); 
  • trunk/loci/formats/in/LegacyQTReader.java

    r3179 r3197  
    7575  public boolean isThisType(byte[] block) { return false; } 
    7676 
    77   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    78   public byte[] openBytes(int no) throws FormatException, IOException { 
    79     FormatTools.assertId(currentId, true, 1); 
    80     return ImageTools.getBytes(openImage(no), false, 3); 
     77  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     78  public byte[] openBytes(int no, byte[] buf) 
     79    throws FormatException, IOException 
     80  { 
     81    buf = ImageTools.getBytes(openImage(no), false, 3); 
     82    return buf; 
    8183  } 
    8284 
     
    216218      core.interleaved[0] = false; 
    217219      core.littleEndian[0] = false; 
     220      core.indexed[0] = false; 
     221      core.falseColor[0] = false; 
    218222 
    219223      MetadataStore store = getMetadataStore(); 
     
    227231      } 
    228232    } 
    229     catch (Exception e) { 
    230       // CTR TODO - eliminate catch-all exception handling 
     233    catch (ReflectException e) { 
    231234      throw new FormatException("Open movie failed", e); 
    232235    } 
  • trunk/loci/formats/in/LegacyZVIReader.java

    r3175 r3197  
    9898  } 
    9999 
    100   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    101   public byte[] openBytes(int no) throws FormatException, IOException { 
    102     FormatTools.assertId(currentId, true, 1); 
    103     byte[] buf = new byte[((ZVIBlock) blockList.elementAt(no)).imageSize]; 
    104     return openBytes(no, buf); 
    105   } 
    106  
    107100  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    108101  public byte[] openBytes(int no, byte[] buf) 
     
    110103  { 
    111104    FormatTools.assertId(currentId, true, 1); 
    112     if (no < 0 || no >= getImageCount()) { 
    113       throw new FormatException("Invalid image number: " + no); 
    114     } 
     105    FormatTools.checkPlaneNumber(this, no); 
     106    FormatTools.checkBufferSize(this, buf.length); 
    115107 
    116108    ZVIBlock zviBlock = (ZVIBlock) blockList.elementAt(no); 
     
    122114  public BufferedImage openImage(int no) throws FormatException, IOException { 
    123115    FormatTools.assertId(currentId, true, 1); 
    124     if (no < 0 || no >= getImageCount()) { 
    125       throw new FormatException("Invalid image number: " + no); 
    126     } 
     116    FormatTools.checkPlaneNumber(this, no); 
    127117 
    128118    if (debug) debug("Reading image #" + no + "..."); 
    129  
    130119    ZVIBlock zviBlock = (ZVIBlock) blockList.elementAt(no); 
    131120    return zviBlock.readImage(in); 
     
    400389      core.interleaved[0] = false; 
    401390      core.littleEndian[0] = true; 
     391      core.indexed[0] = false; 
     392      core.falseColor[0] = false; 
    402393 
    403394      // Populate metadata store 
  • trunk/loci/formats/in/LeicaReader.java

    r3185 r3197  
    106106  } 
    107107 
    108   /* @see loci.formats.IFormatReader#isIndexed() */ 
    109   public boolean isIndexed() { 
    110     return true; 
    111   } 
    112  
    113108  /* @see loci.formats.IFormatReader#get8BitLookupTable() */ 
    114109  public byte[][] get8BitLookupTable() throws FormatException, IOException { 
     
    125120  } 
    126121 
    127   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    128   public boolean isMetadataComplete() { 
    129     return true; 
    130   } 
    131  
    132122  /* @see loci.formats.IFormatReader#fileGroupOption(String) */ 
    133123  public int fileGroupOption(String id) throws FormatException, IOException { 
    134124    return id.toLowerCase().endsWith(".lei") ? FormatTools.MUST_GROUP : 
    135125      FormatTools.CAN_GROUP; 
    136   } 
    137  
    138   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    139   public byte[] openBytes(int no) throws FormatException, IOException { 
    140     FormatTools.assertId(currentId, true, 1); 
    141     if (no < 0 || no >= getImageCount()) { 
    142       throw new FormatException("Invalid image number: " + no); 
    143     } 
    144     tiff[series][no].setId((String) files[series].get(no)); 
    145     byte[] b = tiff[series][no].openBytes(0); 
    146     tiff[series][no].close(); 
    147     return b; 
    148126  } 
    149127 
     
    153131  { 
    154132    FormatTools.assertId(currentId, true, 1); 
    155     if (no < 0 || no >= getImageCount()) { 
    156       throw new FormatException("Invalid image number: " + no); 
    157     } 
     133    FormatTools.checkPlaneNumber(this, no); 
    158134    tiff[series][no].setId((String) files[series].get(no)); 
    159     tiff[series][no].openBytes(0, buf); 
    160     tiff[series][no].close(); 
    161     return buf; 
     135    return tiff[series][no].openBytes(0, buf); 
    162136  } 
    163137 
     
    10471021      Integer ii = new Integer(i); 
    10481022 
    1049       core.rgb[i] = true; 
    1050       core.sizeC[i] *= 3; 
     1023      core.rgb[i] = false; 
     1024      //core.sizeC[i] *= 3; 
     1025 
     1026      core.indexed[i] = true; 
     1027      core.falseColor[i] = true; 
     1028      core.metadataComplete[i] = true; 
    10511029 
    10521030      String timestamp = (String) getMeta("Timestamp " + (i+1)); 
     
    10621040 
    10631041      store.setImage((String) seriesNames.get(i), timestamp, description, ii); 
    1064  
     1042    } 
     1043    FormatTools.populatePixels(store, this); 
     1044 
     1045    for (int i=0; i<core.sizeC.length; i++) { 
    10651046      for (int j=0; j<core.sizeC[i]; j++) { 
    1066         store.setLogicalChannel(i, null, null, null, null, null, null, null, 
     1047        store.setLogicalChannel(j, null, null, null, null, null, null, null, 
    10671048          null, null, null, null, null, null, null, null, null, null, null, 
    1068           null, null, null, null, null, null); 
     1049          null, null, null, null, null, new Integer(i)); 
    10691050        // TODO: get channel min/max from metadata 
    10701051//        store.setChannelGlobalMinMax(j, getChannelGlobalMinimum(currentId, j), 
     
    10721053      } 
    10731054    } 
    1074     FormatTools.populatePixels(store, this); 
    10751055  } 
    10761056 
  • trunk/loci/formats/in/MNGReader.java

    r3175 r3197  
    6464  } 
    6565 
    66   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    67   public boolean isMetadataComplete() { 
    68     return true; 
    69   } 
    70  
    71   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    72   public byte[] openBytes(int no) throws FormatException, IOException { 
    73     return ImageTools.getBytes(openImage(no), true, core.sizeC[0]); 
     66  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     67  public byte[] openBytes(int no, byte[] buf) 
     68    throws FormatException, IOException 
     69  { 
     70    buf = ImageTools.getBytes(openImage(no), true, core.sizeC[0]); 
     71    return buf; 
    7472  } 
    7573 
     
    178176    core.interleaved[0] = false; 
    179177    core.littleEndian[0] = false; 
     178    core.metadataComplete[0] = true; 
     179    core.indexed[0] = false; 
     180    core.falseColor[0] = false; 
    180181 
    181182    MetadataStore store = getMetadataStore(); 
  • trunk/loci/formats/in/MRCReader.java

    r3184 r3197  
    6464  } 
    6565 
    66   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    67   public byte[] openBytes(int no) throws FormatException, IOException { 
    68     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bpp]; 
    69     return openBytes(no, buf); 
    70   } 
    71  
    7266  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    7367  public byte[] openBytes(int no, byte[] buf) 
     
    7569  { 
    7670    FormatTools.assertId(currentId, true, 1); 
    77     if (no < 0 || no >= getImageCount()) { 
    78       throw new FormatException("Invalid image number: " + no); 
    79     } 
    80     if (buf.length < core.sizeX[0] * core.sizeY[0] * bpp) { 
    81       throw new FormatException("Buffer too small."); 
    82     } 
    83     in.seek(1024 + extHeaderSize + (no * core.sizeX[0] * core.sizeY[0] * bpp)); 
     71    FormatTools.checkPlaneNumber(this, no); 
     72    FormatTools.checkBufferSize(this, buf.length); 
     73    in.seek(1024 + (no * core.sizeX[0] * core.sizeY[0] * bpp)); 
    8474    in.read(buf); 
    8575    return buf; 
     
    171161 
    172162    in.skipBytes(4); 
    173  
    174163    extHeaderSize = in.readInt(); 
    175164 
     
    213202    core.rgb[0] = false; 
    214203    core.interleaved[0] = true; 
     204    core.indexed[0] = false; 
     205    core.falseColor[0] = false; 
     206    core.metadataComplete[0] = true; 
    215207 
    216208    MetadataStore store = getMetadataStore(); 
     
    218210    FormatTools.populatePixels(store, this); 
    219211 
    220     store.setDimensions(new Float(xlen / mx), new Float(ylen / my), 
    221       new Float(zlen / mz), null, null, null); 
     212    Float x = new Float(xlen / mx); 
     213    Float y = new Float(ylen / my); 
     214    Float z = new Float(zlen / mz); 
     215    if (x.floatValue() == Float.POSITIVE_INFINITY) x = new Float(1.0); 
     216    if (y.floatValue() == Float.POSITIVE_INFINITY) y = new Float(1.0); 
     217    if (z.floatValue() == Float.POSITIVE_INFINITY) z = new Float(1.0); 
     218 
     219    store.setDimensions(x, y, z, null, null, null); 
    222220    for (int i=0; i<core.sizeC[0]; i++) { 
    223221      store.setLogicalChannel(i, null, null, null, null, null, null, null, null, 
  • trunk/loci/formats/in/MetamorphReader.java

    r3185 r3197  
    113113      return false; // we went through the IFD; the ID wasn't found. 
    114114    } 
    115   } 
    116  
    117   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    118   public boolean isMetadataComplete() { 
    119     return true; 
    120115  } 
    121116 
  • trunk/loci/formats/in/MicromanagerReader.java

    r3184 r3197  
    7474  } 
    7575 
    76   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    77   public byte[] openBytes(int no) throws FormatException, IOException { 
    78     FormatTools.assertId(currentId, true, 1); 
    79     if (no < 0 || no >= getImageCount()) { 
    80       throw new FormatException("Invalid image number: " + no); 
    81     } 
    82     tiffReader.setId((String) tiffs.get(no)); 
    83     return tiffReader.openBytes(0); 
    84   } 
    85  
    8676  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    8777  public byte[] openBytes(int no, byte[] buf) 
     
    8979  { 
    9080    FormatTools.assertId(currentId, true, 1); 
    91     if (no < 0 || no >= getImageCount()) { 
    92       throw new FormatException("Invalid image number: " + no); 
    93     } 
     81    FormatTools.checkPlaneNumber(this, no); 
    9482    tiffReader.setId((String) tiffs.get(no)); 
    9583    return tiffReader.openBytes(0, buf); 
     
    142130    in = new RandomAccessStream(file.exists() ? new File(file.getParentFile(), 
    143131      METADATA).getAbsolutePath() : METADATA); 
     132    String parent = file.exists() ? file.getParentFile().getAbsolutePath() : ""; 
    144133 
    145134    // usually a small file, so we can afford to read it into memory 
     
    159148      if (pos == -1 || pos >= in.length()) break; 
    160149      String name = s.substring(s.indexOf(":", pos), s.indexOf(",", pos)); 
    161       tiffs.add(0, name.substring(3, name.length() - 1)); 
     150      tiffs.add(0, 
     151        parent + File.separator + name.substring(3, name.length() - 1)); 
    162152      pos++; 
    163153    } 
     
    232222    core.littleEndian[0] = tiffReader.isLittleEndian(); 
    233223    core.imageCount[0] = tiffs.size(); 
     224    core.indexed[0] = false; 
     225    core.falseColor[0] = false; 
     226    core.metadataComplete[0] = true; 
    234227 
    235228    MetadataStore store = getMetadataStore(); 
  • trunk/loci/formats/in/ND2Reader.java

    r3185 r3197  
    160160  } 
    161161 
    162   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    163   public byte[] openBytes(int no) throws FormatException, IOException { 
    164     byte[] b = new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * 
    165       FormatTools.getBytesPerPixel(core.pixelType[0])]; 
    166     return openBytes(no, b); 
    167   } 
    168  
    169162  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    170163  public byte[] openBytes(int no, byte[] buf) 
     
    172165  { 
    173166    FormatTools.assertId(currentId, true, 1); 
    174     if (no < 0 || no >= core.imageCount[0]) { 
    175       throw new FormatException("Invalid image number: " + no); 
    176     } 
    177     if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * 
    178       FormatTools.getBytesPerPixel(core.pixelType[0])) 
    179     { 
    180       throw new FormatException("Buffer too small."); 
    181     } 
     167    FormatTools.checkPlaneNumber(this, no); 
     168    FormatTools.checkBufferSize(this, buf.length); 
    182169 
    183170    in.seek(offsets[no]); 
     
    234221    if (!isJPEG) { 
    235222      return ImageTools.makeImage(openBytes(no), core.sizeX[0], core.sizeY[0], 
    236         core.sizeC[0], !core.interleaved[0], 
     223        core.sizeC[0], core.interleaved[0], 
    237224        FormatTools.getBytesPerPixel(core.pixelType[0]), core.littleEndian[0]); 
    238225    } 
     
    274261  } 
    275262 
     263  /* @see loci.formats.IFormatReader#close() */ 
     264  public void close() throws IOException { 
     265    super.close(); 
     266 
     267    offsets = null; 
     268    zs.clear(); 
     269    ts.clear(); 
     270    adjustImageCount = false; 
     271    isJPEG = false; 
     272    isLossless = false; 
     273  } 
     274 
    276275  // -- Internal FormatReader API methods -- 
    277276 
     
    396395      } 
    397396      core.littleEndian[0] = isLossless; 
    398       core.interleaved[0] = false; 
     397      core.interleaved[0] = true; 
     398      core.indexed[0] = false; 
     399      core.falseColor[0] = false; 
     400      core.metadataComplete[0] = true; 
     401 
     402      MetadataStore store = getMetadataStore(); 
     403      store.setImage(currentId, null, null, null); 
     404      FormatTools.populatePixels(store, this); 
     405      for (int i=0; i<core.sizeC[0]; i++) { 
     406        store.setLogicalChannel(i, null, null, null, null, null, null, null, 
     407          null, null, null, null, null, null, null, null, null, null, null, 
     408          null, null, null, null, null, null); 
     409      } 
    399410 
    400411      return; 
     
    439450 
    440451    core.pixelType[0] = FormatTools.UINT8; 
     452    core.indexed[0] = false; 
     453    core.falseColor[0] = false; 
    441454 
    442455    // read XML metadata from the end of the file 
     
    722735 
    723736    core.rgb[0] = core.sizeC[0] >= 3; 
    724     core.interleaved[0] = true; 
     737    core.interleaved[0] = false; 
    725738    core.littleEndian[0] = false; 
     739    core.metadataComplete[0] = true; 
    726740 
    727741    MetadataStore store = getMetadataStore(); 
  • trunk/loci/formats/in/NRRDReader.java

    r3184 r3197  
    7171  } 
    7272 
    73   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    74   public byte[] openBytes(int no) throws FormatException, IOException { 
    75     FormatTools.assertId(currentId, true, 1); 
    76     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * 
    77       FormatTools.getBytesPerPixel(core.pixelType[0])]; 
    78     return openBytes(no, buf); 
    79   } 
    80  
    8173  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    8274  public byte[] openBytes(int no, byte[] buf) 
     
    8476  { 
    8577    FormatTools.assertId(currentId, true, 1); 
    86     if (no < 0 || no >= core.imageCount[0]) { 
    87       throw new FormatException("Invalid image number: " + no); 
    88     } 
    89  
    90     if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * 
    91       FormatTools.getBytesPerPixel(core.pixelType[0])) 
    92     { 
    93       throw new FormatException("Buffer too small."); 
    94     } 
     78    FormatTools.checkPlaneNumber(this, no); 
     79    FormatTools.checkBufferSize(this, buf.length); 
    9580 
    9681    // TODO : add support for additional encoding types 
     
    204189 
    205190    if (dataFile == null) offset = in.getFilePointer(); 
    206     else helper.setId(dataFile); 
     191    else { 
     192      File f = new File(currentId); 
     193      if (f.exists() && f.getParentFile() != null) { 
     194        dataFile = 
     195          f.getParentFile().getAbsolutePath() + File.separator + dataFile; 
     196      } 
     197      helper.setId(dataFile); 
     198    } 
    207199 
    208200    core.rgb[0] = core.sizeC[0] > 1; 
    209201    core.interleaved[0] = true; 
    210202    core.imageCount[0] = core.sizeZ[0] * core.sizeT[0]; 
     203    core.indexed[0] = false; 
     204    core.falseColor[0] = false; 
     205    core.metadataComplete[0] = true; 
    211206 
    212207    MetadataStore store = getMetadataStore(); 
     
    217212    for (int i=0; i<core.sizeC[0]; i++) { 
    218213      store.setLogicalChannel(i, null, null, null, null, null, null, null, null, 
    219         null, null, null, null, core.sizeC[0] == 1 ? "monochrome" : "RGB", null, 
     214        null, null, null, null, null, null, 
    220215        null, null, null, null, null, null, null, null, null, null); 
    221216    } 
  • trunk/loci/formats/in/NikonReader.java

    r3104 r3197  
    181181    // it should contain version information 
    182182 
    183     short[] version = (short[]) 
    184       TiffTools.getIFDValue(original, TIFF_EPS_STANDARD); 
    185     String v = ""; 
    186     for (int i=0; i<version.length; i++) v += version[i]; 
    187     addMeta("Version", v); 
     183    try { 
     184      short[] version = (short[]) 
     185        TiffTools.getIFDValue(original, TIFF_EPS_STANDARD); 
     186      String v = ""; 
     187      for (int i=0; i<version.length; i++) v += version[i]; 
     188      addMeta("Version", v); 
     189    } 
     190    catch (NullPointerException e) { } 
    188191 
    189192    core.littleEndian[0] = true; 
     
    220223    } 
    221224    catch (IOException io) { } 
     225    catch (NullPointerException e) { } 
    222226 
    223227    // read the maker note 
  • trunk/loci/formats/in/OIBReader.java

    r3184 r3197  
    121121  } 
    122122 
    123   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    124   public byte[] openBytes(int no) throws FormatException, IOException { 
    125     FormatTools.assertId(currentId, true, 1); 
    126     byte[] buf = new byte[core.sizeX[series] * core.sizeY[series] * 
    127       getRGBChannelCount() * 
    128       FormatTools.getBytesPerPixel(core.pixelType[series])]; 
    129     return openBytes(no, buf); 
    130   } 
    131  
    132123  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    133124  public byte[] openBytes(int no, byte[] buf) 
     
    135126  { 
    136127    FormatTools.assertId(currentId, true, 1); 
    137     if (no < 0 || no >= getImageCount()) { 
    138       throw new FormatException("Invalid image number: " + no); 
    139     } 
     128    FormatTools.checkPlaneNumber(this, no); 
    140129 
    141130    try { 
     
    284273 
    285274      for (int i=0; i<numSeries; i++) { 
     275        core.indexed[i] = false; 
     276        core.falseColor[i] = false; 
     277 
    286278        core.sizeX[i] = ((Integer) width.get(i)).intValue(); 
    287279        core.sizeY[i] = ((Integer) height.get(i)).intValue(); 
     
    359351        core.rgb[i] = ((Boolean) rgb.get(i)).booleanValue(); 
    360352        core.interleaved[i] = false; 
     353        core.metadataComplete[i] = true; 
    361354      } 
    362355 
     
    401394  /** Initialize metadata hashtable and OME-XML structure. */ 
    402395  private void initMetadata() throws FormatException, IOException { 
    403     MetadataStore store = getMetadataStore(); 
    404     store.setImage((String) getMeta("[File Info] - DataName"), null, 
    405       null, null); 
    406  
    407396    for (int i=0; i<width.size(); i++) { 
    408397      switch (((Integer) bpp.get(0)).intValue() % 3) { 
     
    412401        default: core.pixelType[i] = FormatTools.UINT8; 
    413402      } 
    414  
     403    } 
     404 
     405    MetadataStore store = getMetadataStore(); 
     406    String name = (String) getMeta("[File Info] - DataName"); 
     407    if (name == null) name = currentId; 
     408 
     409    FormatTools.populatePixels(store, this); 
     410 
     411    for (int i=0; i<width.size(); i++) { 
    415412      String acquisition = "[Acquisition Parameters Common] - "; 
    416413 
     
    425422      } 
    426423 
    427       store.setImage(null, stamp, null, null); 
     424      store.setImage(name, stamp, null, new Integer(i)); 
    428425 
    429426      String pre = "[Reference Image Parameter] - "; 
     
    433430      store.setDimensions(x == null ? null : new Float(x), 
    434431        y == null ? null : new Float(y), null, null, null, new Integer(i)); 
    435       for (int j=0; j<core.sizeC[0]; j++) { 
     432      for (int j=0; j<core.sizeC[i]; j++) { 
    436433        String prefix = "[Channel " + (j + 1) + " Parameters] - "; 
    437434        String gain = (String) getMeta(prefix + "AnalogPMTGain"); 
    438435        String offset = (String) getMeta(prefix + "AnalogPMTOffset"); 
    439436        String voltage = (String) getMeta(prefix + "AnalogPMTVoltage"); 
     437 
     438        if (gain != null) gain = gain.replaceAll("\"", ""); 
     439        if (offset != null) offset = offset.replaceAll("\"", ""); 
     440        if (voltage != null) voltage = voltage.replaceAll("\"", ""); 
    440441 
    441442        store.setDetector(null, null, null, null, null, voltage == null ? null : 
     
    459460      } 
    460461    } 
    461     FormatTools.populatePixels(store, this); 
    462462  } 
    463463 
  • trunk/loci/formats/in/OIFReader.java

    r3185 r3197  
    7373  } 
    7474 
    75   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    76   public boolean isMetadataComplete() { 
    77     return true; 
    78   } 
    79  
    8075  /* @see loci.formats.IFormatReader#fileGroupOption(String) */ 
    8176  public int fileGroupOption(String id) throws FormatException, IOException { 
    8277    return FormatTools.MUST_GROUP; 
    83   } 
    84  
    85   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    86   public byte[] openBytes(int no) throws FormatException, IOException { 
    87     FormatTools.assertId(currentId, true, 1); 
    88     byte[] b = tiffReader[no].openBytes(0); 
    89     tiffReader[no].close(); 
    90     return b; 
    9178  } 
    9279 
     
    9683  { 
    9784    FormatTools.assertId(currentId, true, 1); 
    98     if (no < 0 || no >= getImageCount()) { 
    99       throw new FormatException("Invalid image number: " + no); 
    100     } 
     85    FormatTools.checkPlaneNumber(this, no); 
    10186 
    10287    tiffReader[no].openBytes(0, buf); 
     
    11095  { 
    11196    FormatTools.assertId(currentId, true, 1); 
    112     if (no < 0 || no >= getImageCount()) { 
    113       throw new FormatException("Invalid image number: " + no); 
    114     } 
     97    FormatTools.checkPlaneNumber(this, no); 
    11598 
    11699    String dir = 
     
    383366    core.littleEndian[0] = true; 
    384367    core.interleaved[0] = false; 
     368    core.metadataComplete[0] = true; 
     369    core.indexed[0] = tiffReader[0].isIndexed(); 
     370    core.falseColor[0] = false; 
    385371 
    386372    FormatTools.populatePixels(store, this); 
  • trunk/loci/formats/in/OMETiffReader.java

    r3108 r3197  
    4343public class OMETiffReader extends BaseTiffReader { 
    4444 
     45  // -- Fields -- 
     46 
     47  /** List of used files. */ 
     48  private String[] used; 
     49 
     50  private Hashtable coordinateMap; 
     51 
    4552  // -- Constructor -- 
    4653 
     
    7279  } 
    7380 
     81  // -- IFormatReader API methods -- 
     82 
     83  /* @see loci.formats.IFormatReader#getUsedFiles() */ 
     84  public String[] getUsedFiles() { 
     85    FormatTools.assertId(currentId, true, 1); 
     86    return used; 
     87  } 
     88 
     89  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     90  public byte[] openBytes(int no, byte[] buf) 
     91    throws FormatException, IOException 
     92  { 
     93    FormatTools.assertId(currentId, true, 1); 
     94    FormatTools.checkPlaneNumber(this, no); 
     95    FormatTools.checkBufferSize(this, buf.length); 
     96 
     97    int[] zct = getZCTCoords(no); 
     98    int fileIndex = -1; 
     99    int[] savedCoords = new int[] {-1, -1, -1}; 
     100    for (int i=0; i<coordinateMap.size(); i++) { 
     101      int[] firstZCT = (int[]) coordinateMap.get(new Integer(i)); 
     102      if (firstZCT[0] <= zct[0] && firstZCT[1] <= zct[1] && 
     103        firstZCT[2] <= zct[2] && firstZCT[0] >= savedCoords[0] && 
     104        firstZCT[1] >= savedCoords[1] && firstZCT[2] >= savedCoords[2]) 
     105      { 
     106        savedCoords = firstZCT; 
     107        fileIndex = i; 
     108      } 
     109    } 
     110    in = new RandomAccessStream(used[fileIndex]); 
     111    ifds = TiffTools.getIFDs(in); 
     112    TiffTools.getSamples(ifds[no % ifds.length], in, buf); 
     113    in.close(); 
     114    return swapIfRequired(buf); 
     115  } 
     116 
    74117  // -- Internal BaseTiffReader API methods -- 
    75118 
     
    78121    super.initStandardMetadata(); 
    79122 
     123    String imageId = (String) getMeta("Comment"); 
     124    int ndx = imageId.indexOf("<Image"); 
     125    ndx = imageId.indexOf("ID=\"", ndx); 
     126    imageId = imageId.substring(ndx + 4, imageId.indexOf("\"", ndx + 5)); 
     127 
     128    Vector files = new Vector(); 
     129    Location l = new Location(currentId); 
     130    l = l.getAbsoluteFile().getParentFile(); 
     131    String[] fileList = l.list(); 
     132    Vector tempComments = new Vector(); 
     133 
     134    for (int i=0; i<fileList.length; i++) { 
     135      Hashtable ifd = TiffTools.getFirstIFD(new RandomAccessStream( 
     136        l.getAbsolutePath() + File.separator + fileList[i])); 
     137      if (ifd == null) continue; 
     138      String comment = 
     139        (String) TiffTools.getIFDValue(ifd, TiffTools.IMAGE_DESCRIPTION); 
     140      tempComments.add(comment); 
     141      ndx = comment.indexOf("<Image"); 
     142      ndx = comment.indexOf("ID=\"", ndx); 
     143      comment = comment.substring(ndx + 4, comment.indexOf("\"", ndx + 5)); 
     144 
     145      String check = fileList[i].toLowerCase(); 
     146      if ((check.endsWith(".tif") || check.endsWith(".tiff")) && 
     147        comment.equals(imageId)) 
     148      { 
     149        files.add(l.getAbsolutePath() + File.separator + fileList[i]); 
     150      } 
     151    } 
     152 
     153    used = (String[]) files.toArray(new String[0]); 
     154 
     155    // reorder TIFF files 
     156    coordinateMap = new Hashtable(); 
     157    for (int i=0; i<files.size(); i++) { 
     158      String comment = (String) tempComments.get(i); 
     159      ByteArrayInputStream is = new ByteArrayInputStream(comment.getBytes()); 
     160      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     161      Document doc = null; 
     162      try { 
     163        DocumentBuilder builder = factory.newDocumentBuilder(); 
     164        doc = builder.parse(is); 
     165      } 
     166      catch (ParserConfigurationException exc) { } 
     167      catch (SAXException exc) { } 
     168      catch (IOException exc) { } 
     169 
     170      Element[][] tiffData = null; 
     171      if (doc != null) { 
     172        int numSeries = doc.getElementsByTagName("Pixels").getLength(); 
     173        tiffData = new Element[numSeries][]; 
     174        Vector v = new Vector(); 
     175        NodeList pixelsList = doc.getElementsByTagName("Pixels"); 
     176        for (int j=0; j<numSeries; j++) { 
     177          NodeList list = ((Element) pixelsList.item(j)).getChildNodes(); 
     178          int size = list.getLength(); 
     179          v.clear(); 
     180          for (int k=0; k<size; k++) { 
     181            Node node = list.item(k); 
     182            if ("TiffData".equals(node.getNodeName())) v.add(node); 
     183          } 
     184          tiffData[j] = new Element[v.size()]; 
     185          v.copyInto(tiffData[j]); 
     186        } 
     187 
     188        String firstZ = tiffData[0][0].getAttribute("FirstZ"); 
     189        String firstC = tiffData[0][0].getAttribute("FirstC"); 
     190        String firstT = tiffData[0][0].getAttribute("FirstT"); 
     191        if (firstZ == null || firstZ.equals("")) firstZ = "0"; 
     192        if (firstC == null || firstC.equals("")) firstC = "0"; 
     193        if (firstT == null || firstT.equals("")) firstT = "0"; 
     194        coordinateMap.put(new Integer(i), new int[] {Integer.parseInt(firstZ), 
     195          Integer.parseInt(firstC), Integer.parseInt(firstT)}); 
     196      } 
     197    } 
     198 
     199    int oldX = core.sizeX[0]; 
     200    int oldY = core.sizeY[0]; 
    80201    String comment = (String) getMeta("Comment"); 
    81202 
     
    134255      for (int i=0; i<tiffData.length; i++) { 
    135256        core.sizeX[i] = Integer.parseInt(pixels[i].getAttribute("SizeX")); 
     257        if (core.sizeX[i] != oldX) { 
     258          LogTools.println("Mismatched width: OME-XML reports SizeX=" + 
     259            core.sizeX[i] + "; expecting " + oldX); 
     260          core.sizeX[i] = oldX; 
     261        } 
    136262        core.sizeY[i] = Integer.parseInt(pixels[i].getAttribute("SizeY")); 
     263        if (core.sizeY[i] != oldY) { 
     264          LogTools.println("Mismatched height: OME-XML reports SizeY=" + 
     265            core.sizeY[i] + "; expecting " + oldY); 
     266          core.sizeY[i] = oldY; 
     267        } 
    137268        core.sizeZ[i] = Integer.parseInt(pixels[i].getAttribute("SizeZ")); 
    138269        core.sizeC[i] = Integer.parseInt(pixels[i].getAttribute("SizeC")); 
    139         core.imageCount[i] = ifds.length; 
     270        core.sizeT[i] = Integer.parseInt(pixels[i].getAttribute("SizeT")); 
     271        core.imageCount[i] = core.sizeZ[i] * core.sizeC[i] * core.sizeT[i]; 
    140272        int sc = core.sizeC[i]; 
    141273        if (rgb) sc /= 3; 
    142274        core.rgb[i] = rgb; 
    143         core.sizeT[i] = Integer.parseInt(pixels[i].getAttribute("SizeT")); 
    144275        core.pixelType[i] = FormatTools.pixelTypeFromString( 
    145276          pixels[i].getAttribute("PixelType")); 
  • trunk/loci/formats/in/OMEXMLReader.java

    r3184 r3197  
    8686  } 
    8787 
    88   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    89   public byte[] openBytes(int no) throws FormatException, IOException { 
     88  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     89  public byte[] openBytes(int no, byte[] buf) 
     90    throws FormatException, IOException 
     91  { 
    9092    FormatTools.assertId(currentId, true, 1); 
    91     if (no < 0 || no >= core.imageCount[series]) { 
    92       throw new FormatException("Invalid image number: " + no); 
    93     } 
     93    FormatTools.checkPlaneNumber(this, no); 
     94    FormatTools.checkBufferSize(this, buf.length); 
    9495 
    9596    in.seek(((Integer) offsets[series].get(no)).intValue()); 
    9697 
    97     byte[] buf; 
     98    byte[] b; 
    9899    if (no < getImageCount() - 1) { 
    99       buf = new byte[((Integer) offsets[series].get(no + 1)).intValue() - 
     100      b = new byte[((Integer) offsets[series].get(no + 1)).intValue() - 
    100101        ((Integer) offsets[series].get(no)).intValue()]; 
    101102    } 
    102103    else { 
    103       buf = new byte[(int) (in.length() - 
     104      b = new byte[(int) (in.length() - 
    104105        ((Integer) offsets[series].get(no)).intValue())]; 
    105106    } 
    106     in.read(buf); 
    107     String data = new String(buf); 
    108     buf = null; 
     107    in.read(b); 
     108    String data = new String(b); 
     109    b = null; 
    109110 
    110111    // retrieve the compressed pixel data 
     
    149150      } 
    150151    } 
    151     return pixels; 
     152    buf = pixels; 
     153    return buf;  
    152154  } 
    153155 
     
    369371      core.rgb[i] = false; 
    370372      core.interleaved[i] = false; 
     373      core.indexed[i] = false; 
     374      core.falseColor[i] = false; 
    371375 
    372376      String type = pixType.toLowerCase(); 
  • trunk/loci/formats/in/OpenlabRawReader.java

    r3184 r3197  
    6565  } 
    6666 
    67   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    68   public boolean isMetadataComplete() { 
    69     return true; 
    70   } 
    71  
    72   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    73   public byte[] openBytes(int no) throws FormatException, IOException { 
    74     FormatTools.assertId(currentId, true, 1); 
    75     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bytesPerPixel]; 
    76     return openBytes(no, buf); 
    77   } 
    78  
    7967  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    8068  public byte[] openBytes(int no, byte[] buf) 
     
    8270  { 
    8371    FormatTools.assertId(currentId, true, 1); 
    84     if (no < 0 || no >= getImageCount()) { 
    85       throw new FormatException("Invalid image number: " + no); 
    86     } 
    87     if (buf.length < core.sizeX[0] * core.sizeY[0] * bytesPerPixel) { 
    88       throw new FormatException("Buffer too small."); 
    89     } 
     72    FormatTools.checkPlaneNumber(this, no); 
     73    FormatTools.checkBufferSize(this, buf.length); 
    9074 
    9175    in.seek(offsets[no / core.sizeC[0]] + 288); 
     
    171155    core.interleaved[0] = false; 
    172156    core.littleEndian[0] = false; 
     157    core.metadataComplete[0] = true; 
     158    core.indexed[0] = false; 
     159    core.falseColor[0] = false; 
    173160 
    174161    // The metadata store we're working with. 
  • trunk/loci/formats/in/OpenlabReader.java

    r3176 r3197  
    8888  } 
    8989 
     90  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     91  public byte[] openBytes(int no, byte[] buf) 
     92    throws FormatException, IOException 
     93  { 
     94    FormatTools.assertId(currentId, true, 1); 
     95    FormatTools.checkPlaneNumber(this, no); 
     96    FormatTools.checkBufferSize(this, buf.length); 
     97 
     98    buf = openBytes(no); 
     99    return buf; 
     100  } 
     101 
    90102  /* @see loci.formats.IFormatReader#openBytes(int) */ 
    91103  public byte[] openBytes(int no) throws FormatException, IOException { 
    92104    FormatTools.assertId(currentId, true, 1); 
    93     if (no < 0 || no >= getImageCount()) { 
    94       throw new FormatException("Invalid image number: " + no); 
    95     } 
     105    FormatTools.checkPlaneNumber(this, no); 
    96106 
    97107    LayerInfo info = (LayerInfo) layerInfoList[series].get(no); 
     
    147157        byte[][] tmp = ImageTools.getBytes(img); 
    148158        b = new byte[tmp.length * tmp[0].length]; 
    149         for (int i=0; i<tmp.length; i++) { 
    150           System.arraycopy(tmp[i], 0, b, i * tmp[i].length, tmp[i].length); 
     159        int pt = 0; 
     160        for (int i=0; i<tmp[0].length; i++) { 
     161          for (int j=0; j<tmp.length; j++) { 
     162            b[pt++] = tmp[j][i]; 
     163          } 
    151164        } 
    152165      } 
     
    604617    } 
    605618 
     619    Arrays.fill(core.metadataComplete, true); 
     620 
    606621    status("Populating metadata"); 
    607622 
     
    673688      store.setDimensions(new Float(xCal), new Float(yCal), new Float(zCal), 
    674689        null, null, new Integer(i)); 
    675       for (int j=0; j<core.sizeC[0]; j++) { 
     690    } 
     691    FormatTools.populatePixels(store, this); 
     692    for (int i=0; i<numSeries; i++) { 
     693      for (int j=0; j<core.sizeC[i]; j++) { 
    676694        store.setLogicalChannel(j, null, null, null, null, null, null, null, 
    677695          null, null, null, null, null, null, null, null, null, null, null, 
     
    679697      } 
    680698    } 
    681     FormatTools.populatePixels(store, this); 
    682699  } 
    683700 
  • trunk/loci/formats/in/PCIReader.java

    r3185 r3197  
    8787  } 
    8888 
    89   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    90   public byte[] openBytes(int no) throws FormatException, IOException { 
    91     FormatTools.assertId(currentId, true, 1); 
    92     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * 
    93       FormatTools.getBytesPerPixel(core.pixelType[0]) * getRGBChannelCount()]; 
    94     return openBytes(no, buf); 
    95   } 
    96  
    9789  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    9890  public byte[] openBytes(int no, byte[] buf) 
     
    10193    FormatTools.assertId(currentId, true, 1); 
    10294    if (noPOI) throw new FormatException(NO_POI_MSG); 
    103     if (no < 0 || no >= getImageCount()) { 
    104       throw new FormatException("Invalid image number: " + no); 
    105     } 
    106  
    107     if (buf.length < core.sizeX[0] * core.sizeY[0] * 
    108       FormatTools.getBytesPerPixel(core.pixelType[0]) * getRGBChannelCount()) 
    109     { 
    110       throw new FormatException("Buffer too small."); 
    111     } 
     95    FormatTools.checkPlaneNumber(this, no); 
     96    FormatTools.checkBufferSize(this, buf.length); 
    11297 
    11398    Integer ii = new Integer(no); 
     
    154139      core.sizeT[0] = 1; 
    155140      core.rgb[0] = core.sizeC[0] > 1; 
    156       core.interleaved[0] = true; 
     141      core.interleaved[0] = false; 
    157142      core.currentOrder[0] = "XYCZT"; 
    158143      core.littleEndian[0] = true; 
     144      core.indexed[0] = false; 
     145      core.falseColor[0] = false; 
     146      core.metadataComplete[0] = true; 
    159147 
    160148      MetadataStore store = getMetadataStore(); 
    161149      FormatTools.populatePixels(store, this); 
     150      store.setImage(currentId, null, null, null); 
     151      for (int i=0; i<core.sizeC[0]; i++) { 
     152        store.setLogicalChannel(i, null, null, null, null, null, null, null, 
     153          null, null, null, null, null, null, null, null, null, null, null, 
     154          null, null, null, null, null, null); 
     155      } 
    162156    } 
    163157    catch (ReflectException exc) { 
  • trunk/loci/formats/in/PGMReader.java

    r3184 r3197  
    5959  } 
    6060 
    61   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    62   public byte[] openBytes(int no) throws FormatException, IOException { 
    63     FormatTools.assertId(currentId, true, 1); 
    64     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * 
    65       FormatTools.getBytesPerPixel(core.pixelType[0])]; 
    66     return openBytes(no, buf); 
    67   } 
    68  
    6961  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    7062  public byte[] openBytes(int no, byte[] buf) 
     
    7264  { 
    7365    FormatTools.assertId(currentId, true, 1); 
    74     if (no < 0 || no >= getImageCount()) { 
    75       throw new FormatException("Invalid image number: " + no); 
    76     } 
    77     if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * 
    78       FormatTools.getBytesPerPixel(core.pixelType[0])) 
    79     { 
    80       throw new FormatException("Buffer too small."); 
    81     } 
     66    FormatTools.checkPlaneNumber(this, no); 
     67    FormatTools.checkBufferSize(this, buf.length); 
    8268 
    8369    in.seek(offset); 
     
    147133    core.sizeT[0] = 1; 
    148134    core.imageCount[0] = 1; 
     135    core.indexed[0] = false; 
     136    core.falseColor[0] = false; 
     137    core.metadataComplete[0] = true; 
    149138 
    150139    MetadataStore store = getMetadataStore(); 
     
    154143    for (int i=0; i<core.sizeC[0]; i++) { 
    155144      store.setLogicalChannel(i, null, null, null, null, null, null, null, 
    156         null, null, null, null, null, 
    157         core.sizeC[0] == 1 ? "monochrome" : "RGB", null, null, null, null, 
     145        null, null, null, null, null, null, null, null, null, null, 
    158146        null, null, null, null, null, null, null); 
    159147    } 
  • trunk/loci/formats/in/PerkinElmerReader.java

    r3184 r3197  
    7272  public boolean isThisType(byte[] block) { return false; } 
    7373 
    74   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    75   public boolean isMetadataComplete() { 
    76     return true; 
    77   } 
    78  
    7974  /* @see loci.formats.IFormatReader#fileGroupOption(String) */ 
    8075  public int fileGroupOption(String id) throws FormatException, IOException { 
     
    8277  } 
    8378 
    84   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    85   public byte[] openBytes(int no) throws FormatException, IOException { 
     79  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     80  public byte[] openBytes(int no, byte[] buf) 
     81    throws FormatException, IOException 
     82  { 
    8683    FormatTools.assertId(currentId, true, 1); 
     84    FormatTools.checkPlaneNumber(this, no); 
    8785    if (isTiff) { 
    8886      tiff[no / core.sizeC[0]].setId(files[no / core.sizeC[0]]); 
    89       return tiff[no / core.sizeC[0]].openBytes(0); 
    90     } 
     87      return tiff[no / core.sizeC[0]].openBytes(0, buf); 
     88    } 
     89 
     90    FormatTools.checkBufferSize(this, buf.length); 
    9191 
    9292    String file = files[no]; 
    9393    RandomAccessStream ras = new RandomAccessStream(file); 
    94     byte[] b = new byte[(int) ras.length() - 6]; // each file has 6 magic bytes 
    9594    ras.skipBytes(6); 
    96     ras.read(b); 
     95    ras.read(buf); 
    9796    ras.close(); 
    98     return b; 
     97    return buf; 
    9998  } 
    10099 
     
    128127      } 
    129128    } 
     129  } 
     130 
     131  /* @see loci.formats.IFormatHandler#isThisType(String, boolean) */ 
     132  public boolean isThisType(String name, boolean open) { 
     133    if (name.toLowerCase().endsWith(".cfg")) { 
     134      try { 
     135        RandomAccessStream s = new RandomAccessStream(name); 
     136        String ss = s.readString(512); 
     137        return ss.indexOf("Series") != -1; 
     138      } 
     139      catch (IOException e) { 
     140        if (debug) trace(e); 
     141        return false; 
     142      } 
     143    } 
     144    return super.isThisType(name, open); 
    130145  } 
    131146 
     
    529544    } 
    530545    else { 
    531       int bpp = openBytes(0).length / (core.sizeX[0] * core.sizeY[0]); 
     546      RandomAccessStream tmp = new RandomAccessStream(files[0]); 
     547      int bpp = (int) (tmp.length() - 6) / (core.sizeX[0] * core.sizeY[0]); 
     548      tmp.close(); 
    532549      switch (bpp) { 
    533550        case 1: 
     
    564581    core.interleaved[0] = false; 
    565582    core.littleEndian[0] = isTiff ? tiff[0].isLittleEndian() : true; 
     583    core.metadataComplete[0] = true; 
     584    core.indexed[0] = isTiff ? tiff[0].isIndexed() : false; 
     585    core.falseColor[0] = false; 
    566586 
    567587    // Populate metadata store 
  • trunk/loci/formats/in/PictReader.java

    r3175 r3197  
    278278  } 
    279279 
    280   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    281   public byte[] openBytes(int no) throws FormatException, IOException { 
    282     FormatTools.assertId(currentId, true, 1); 
    283     return ImageTools.getBytes(openImage(no), false, no % 3); 
     280  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     281  public byte[] openBytes(int no, byte[] buf) 
     282    throws FormatException, IOException 
     283  { 
     284    buf = ImageTools.getBytes(openImage(no), false, no % 3); 
     285    return buf; 
    284286  } 
    285287 
     
    287289  public BufferedImage openImage(int no) throws FormatException, IOException { 
    288290    FormatTools.assertId(currentId, true, 1); 
    289     if (no < 0 || no >= getImageCount()) { 
    290       throw new FormatException("Invalid image number: " + no); 
    291     } 
     291    FormatTools.checkPlaneNumber(this, no); 
    292292 
    293293    return open(bytes); 
     
    325325    core.currentOrder[0] = "XYCZT"; 
    326326    core.rgb[0] = true; 
    327     core.interleaved[0] = true; 
     327    core.interleaved[0] = false; 
    328328    core.imageCount[0] = 1; 
     329    core.indexed[0] = false; 
     330    core.falseColor[0] = false; 
     331    core.metadataComplete[0] = true; 
    329332 
    330333    // The metadata store we're working with. 
     
    332335    store.setImage(currentId, null, null, null); 
    333336 
    334     core.pixelType[0] = FormatTools.UINT8; 
     337    core.pixelType[0] = ImageTools.getPixelType(openImage(0)); 
     338 
    335339    FormatTools.populatePixels(store, this); 
    336340    for (int i=0; i<core.sizeC[0]; i++) { 
  • trunk/loci/formats/in/PrairieReader.java

    r3184 r3197  
    7979    } 
    8080 
    81     if (new String(block).indexOf("xml") != -1) return true; 
     81    String s = new String(block); 
     82    if (s.indexOf("xml") != -1 && s.indexOf("PV") != -1) return true; 
    8283 
    8384    boolean little = (block[0] == 0x49 && block[1] == 0x49); 
     
    124125  } 
    125126 
    126   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    127   public byte[] openBytes(int no) throws FormatException, IOException { 
    128     FormatTools.assertId(currentId, true, 1); 
    129     if (no < 0 || no >= getImageCount()) { 
    130       throw new FormatException("Invalid image number: " + no); 
    131     } 
    132     tiff.setId(files[no]); 
    133     return tiff.openBytes(0); 
    134   } 
    135  
    136127  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    137128  public byte[] openBytes(int no, byte[] buf) 
     
    139130  { 
    140131    FormatTools.assertId(currentId, true, 1); 
    141     if (no < 0 || no >= getImageCount()) { 
    142       throw new FormatException("Invalid image number: " + no); 
    143     } 
     132    FormatTools.checkPlaneNumber(this, no); 
    144133    tiff.setId(files[no]); 
    145     tiff.openBytes(0, buf); 
    146     return buf; 
     134    return tiff.openBytes(0, buf); 
    147135  } 
    148136 
     
    167155    int xmlCount = 0; 
    168156    for (int i=0; i<listing.length; i++) { 
    169       if (listing[i].toLowerCase().endsWith(".xml")) xmlCount++; 
     157      if (listing[i].toLowerCase().endsWith(".xml")) { 
     158        try { 
     159          RandomAccessStream s = new RandomAccessStream( 
     160            parent.getAbsolutePath() + File.separator + listing[i]); 
     161          if (s.readString(512).indexOf("PV") != -1) xmlCount++; 
     162        } 
     163        catch (IOException e) { } 
     164      } 
    170165    } 
    171166    if (xmlCount == 0) { 
    172167      listing = (String[]) Location.getIdMap().keySet().toArray(new String[0]); 
    173168      for (int i=0; i<listing.length; i++) { 
    174         if (listing[i].toLowerCase().endsWith(".xml")) xmlCount++; 
     169        if (listing[i].toLowerCase().endsWith(".xml")) { 
     170          try { 
     171            RandomAccessStream s = new RandomAccessStream(listing[i]); 
     172            if (s.readString(512).indexOf("PV") != -1) xmlCount++; 
     173          } 
     174          catch (IOException e) { } 
     175        } 
    175176      } 
    176177    } 
     
    329330        core.interleaved[0] = false; 
    330331        core.littleEndian[0] = tiff.isLittleEndian(); 
     332        core.indexed[0] = tiff.isIndexed(); 
     333        core.falseColor[0] = false; 
    331334 
    332335        String px = (String) getMeta("micronsPerPixel_XAxis"); 
  • trunk/loci/formats/in/QTReader.java

    r3175 r3197  
    127127  } 
    128128 
    129   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    130   public boolean isMetadataComplete() { 
    131     return true; 
    132   } 
    133  
    134129  /* @see loci.formats.IFormatReader#setMetadataStore(MetadataStore) */ 
    135130  public void setMetadataStore(MetadataStore store) { 
     
    139134  } 
    140135 
    141   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    142   public byte[] openBytes(int no) throws FormatException, IOException { 
     136  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     137  public byte[] openBytes(int no, byte[] buf) 
     138    throws FormatException, IOException 
     139  { 
    143140    FormatTools.assertId(currentId, true, 1); 
    144     if (no < 0 || no >= getImageCount()) { 
    145       throw new FormatException("Invalid image number: " + no); 
    146     } 
     141    FormatTools.checkPlaneNumber(this, no); 
     142    FormatTools.checkBufferSize(this, buf.length); 
    147143 
    148144    String code = codec; 
     
    189185      !code.equals(altCodec); 
    190186 
    191     byte[] bytes = uncompress(pixs, code); 
     187    buf = uncompress(pixs, code); 
    192188    if (code.equals("rpza")) { 
    193       for (int i=0; i<bytes.length; i++) { 
    194         bytes[i] = (byte) (255 - bytes[i]); 
     189      for (int i=0; i<buf.length; i++) { 
     190        buf[i] = (byte) (255 - buf[i]); 
    195191      } 
    196192      prevPlane = no; 
    197       return bytes; 
     193      return buf; 
    198194    } 
    199195 
    200196    // on rare occassions, we need to trim the data 
    201     if (canUsePrevious && (prevPixels.length < bytes.length)) { 
    202       byte[] temp = bytes; 
    203       bytes = new byte[prevPixels.length]; 
    204       System.arraycopy(temp, 0, bytes, 0, bytes.length); 
    205     } 
    206  
    207     prevPixels = bytes; 
     197    if (canUsePrevious && (prevPixels.length < buf.length)) { 
     198      byte[] temp = buf; 
     199      buf = new byte[prevPixels.length]; 
     200      System.arraycopy(temp, 0, buf, 0, buf.length); 
     201    } 
     202 
     203    prevPixels = buf; 
    208204    prevPlane = no; 
    209205 
     
    218214 
    219215    if (pad > 0) { 
    220       bytes = new byte[prevPixels.length - core.sizeY[0]*pad]; 
     216      buf = new byte[prevPixels.length - core.sizeY[0]*pad]; 
    221217 
    222218      for (int row=0; row<core.sizeY[0]; row++) { 
    223         System.arraycopy(prevPixels, row*(core.sizeX[0]+pad), bytes, 
     219        System.arraycopy(prevPixels, row*(core.sizeX[0]+pad), buf, 
    224220          row*core.sizeX[0], core.sizeX[0]); 
    225221      } 
     
    228224    if ((bitsPerPixel == 40 || bitsPerPixel == 8) && !code.equals("mjpb")) { 
    229225      // invert the pixels 
    230       for (int i=0; i<bytes.length; i++) { 
    231         bytes[i] = (byte) (255 - bytes[i]); 
    232       } 
    233       return bytes; 
     226      for (int i=0; i<buf.length; i++) { 
     227        buf[i] = (byte) (255 - buf[i]); 
     228      } 
     229      return buf; 
    234230    } 
    235231    else if (bitsPerPixel == 32) { 
    236232      // strip out alpha channel 
    237       byte[][] data = new byte[3][bytes.length / 4]; 
     233      byte[][] data = new byte[3][buf.length / 4]; 
    238234      for (int i=0; i<data[0].length; i++) { 
    239         data[0][i] = bytes[4*i + 1]; 
    240         data[1][i] = bytes[4*i + 2]; 
    241         data[2][i] = bytes[4*i + 3]; 
     235        data[0][i] = buf[4*i + 1]; 
     236        data[1][i] = buf[4*i + 2]; 
     237        data[2][i] = buf[4*i + 3]; 
    242238      } 
    243239 
     
    248244      return rtn; 
    249245    } 
    250     else { 
    251       return bytes; 
    252     } 
     246    return buf; 
    253247  } 
    254248 
     
    256250  public BufferedImage openImage(int no) throws FormatException, IOException { 
    257251    FormatTools.assertId(currentId, true, 1); 
    258     if (no < 0 || no >= getImageCount()) { 
    259       throw new FormatException("Invalid image number: " + no); 
    260     } 
     252    FormatTools.checkPlaneNumber(this, no); 
    261253 
    262254    String code = codec; 
     
    343335    core.currentOrder[0] = "XYCZT"; 
    344336    core.littleEndian[0] = false; 
    345     core.interleaved[0] = true; 
     337    core.interleaved[0] = false; 
     338    core.metadataComplete[0] = true; 
     339    core.indexed[0] = false; 
     340    core.falseColor[0] = false; 
    346341 
    347342    // The metadata store we're working with. 
  • trunk/loci/formats/in/SDTReader.java

    r3191 r3197  
    118118  } 
    119119 
    120   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    121   public byte[] openBytes(int no) throws FormatException, IOException { 
    122     FormatTools.assertId(currentId, true, 1); 
    123     int c = getRGBChannelCount(); 
    124     byte[] buf = new byte[2 * c * core.sizeX[series] * core.sizeY[series]]; 
    125     return openBytes(no, buf); 
    126   } 
    127  
    128120  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    129121  public byte[] openBytes(int no, byte[] buf) 
     
    131123  { 
    132124    FormatTools.assertId(currentId, true, 1); 
    133     if (no < 0 || no >= timeBins * channels) { 
    134       throw new FormatException("Invalid image number: " + no); 
    135     } 
    136     int c = getRGBChannelCount(); 
    137     if (buf.length < 2 * c * core.sizeX[series] * core.sizeY[series]) { 
    138       throw new FormatException("Buffer too small"); 
    139     } 
     125    FormatTools.checkPlaneNumber(this, no); 
     126    FormatTools.checkBufferSize(this, buf.length); 
    140127 
    141128    if (intensity) { 
     
    204191    core.littleEndian[0] = true; 
    205192    core.imageCount[0] = channels; 
     193    core.indexed[0] = false; 
     194    core.falseColor[0] = false; 
     195    core.metadataComplete[0] = true; 
    206196 
    207197    MetadataStore store = getMetadataStore(); 
  • trunk/loci/formats/in/SEQReader.java

    r3132 r3197  
    5555  /** Constructs a new Image-Pro SEQ reader. */ 
    5656  public SEQReader() { super("Image-Pro Sequence", "seq"); } 
    57  
    58   // -- IFormatReader API methods -- 
    59  
    60   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    61   public boolean isMetadataComplete() { 
    62     return true; 
    63   } 
    6457 
    6558  // -- Internal BaseTiffReader API methods -- 
  • trunk/loci/formats/in/SlidebookReader.java

    r3184 r3197  
    6363  } 
    6464 
    65   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    66   public byte[] openBytes(int no) throws FormatException, IOException { 
    67     FormatTools.assertId(currentId, true, 1); 
    68     byte[] buf = new byte[core.sizeX[series] * core.sizeY[series] * 2]; 
    69     return openBytes(no, buf); 
    70   } 
    71  
    7265  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    7366  public byte[] openBytes(int no, byte[] buf) 
     
    7568  { 
    7669    FormatTools.assertId(currentId, true, 1); 
    77     if (no < 0 || no >= getImageCount()) { 
    78       throw new FormatException("Invalid image number: " + no); 
    79     } 
    80     if (buf.length < core.sizeX[series] * core.sizeY[series] * 2) { 
    81       throw new FormatException("Buffer too small."); 
    82     } 
     70    FormatTools.checkPlaneNumber(this, no); 
     71    FormatTools.checkBufferSize(this, buf.length); 
    8372 
    8473    int plane = core.sizeX[series] * core.sizeY[series] * 2; 
     
    298287 
    299288      core.imageCount[i] = core.sizeC[i] * core.sizeZ[i] * core.sizeT[i]; 
     289 
     290      core.indexed[i] = false; 
     291      core.falseColor[i] = false; 
    300292    } 
    301293 
    302294    MetadataStore store = getMetadataStore(); 
    303     store.setImage(currentId, null, null, null); 
     295    FormatTools.populatePixels(store, this); 
    304296 
    305297    for (int i=0; i<core.sizeX.length; i++) { 
     298      Integer ii = new Integer(i); 
     299      store.setImage(currentId, null, null, ii); 
    306300      for (int j=0; j<core.sizeC[i]; j++) { 
    307301        store.setLogicalChannel(j, null, null, null, null, null, null, null, 
    308           null, null, null, null, null, core.sizeC[i] == 1 ? "monochrome" : 
    309           "RGB", null, null, null, null, null, null, null, null, null, null, 
    310           new Integer(i)); 
    311       } 
    312     } 
    313     FormatTools.populatePixels(store, this); 
     302          null, null, null, null, null, null, null, null, null, null, null, 
     303          null, null, null, null, null, ii); 
     304      } 
     305    } 
    314306  } 
    315307 
  • trunk/loci/formats/in/TCSReader.java

    r3132 r3197  
    6565    } 
    6666    catch (IOException e) { return false; } 
    67   } 
    68  
    69   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    70   public boolean isMetadataComplete() { 
    71     return true; 
    7267  } 
    7368 
  • trunk/loci/formats/in/TiffReader.java

    r3015 r3197  
    4646  public TiffReader() { 
    4747    super("Tagged Image File Format", new String[] {"tif", "tiff"}); 
    48   } 
    49  
    50   // -- IFormatReader API methods -- 
    51  
    52   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    53   public boolean isMetadataComplete() { 
    54     return true; 
    5548  } 
    5649 
  • trunk/loci/formats/in/VisitechReader.java

    r3184 r3197  
    5656  } 
    5757 
    58   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    59   public byte[] openBytes(int no) throws FormatException, IOException { 
    60     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * 
    61       FormatTools.getBytesPerPixel(core.pixelType[0])]; 
    62     return openBytes(no, buf); 
    63   } 
    64  
    6558  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    6659  public byte[] openBytes(int no, byte[] buf) 
     
    6861  { 
    6962    FormatTools.assertId(currentId, true, 1); 
    70     if (no < 0 || no >= core.imageCount[0]) { 
    71       throw new FormatException("Invalid image number: " + no); 
    72     } 
     63    FormatTools.checkPlaneNumber(this, no); 
     64    FormatTools.checkBufferSize(this, buf.length); 
     65 
    7366    int plane = core.sizeX[0] * core.sizeY[0] * 
    7467      FormatTools.getBytesPerPixel(core.pixelType[0]); 
    75     if (buf.length < plane) { 
    76       throw new FormatException("Buffer too small."); 
    77     } 
    78  
    79     int fileIndex = no / (core.sizeZ[0] * core.sizeT[0]); 
    80     int planeIndex = no % (core.sizeZ[0] * core.sizeT[0]); 
     68 
     69    int div = core.sizeZ[0] * core.sizeT[0]; 
     70    int fileIndex = no / div; 
     71    int planeIndex = no % div; 
    8172 
    8273    String file = (String) files.get(fileIndex); 
    8374    RandomAccessStream s = new RandomAccessStream(file); 
    8475    s.skipBytes(374); 
    85     boolean found = false; 
    86     while (!found) { 
    87       if (s.read() == (byte) 0xf0) { 
    88         found = true; 
    89         s.skipBytes(1); 
    90       } 
    91     } 
    92  
    93     s.skipBytes((plane + 164) * planeIndex); 
     76    while (s.read() != (byte) 0xf0); 
     77    s.skipBytes((plane + 164) * planeIndex + 1); 
    9478    s.read(buf); 
    9579    s.close(); 
     
    117101      String base = path.substring(ndx + 1, path.indexOf(" ", ndx)); 
    118102 
     103      String suffix = " Report.html"; 
    119104      currentId = null; 
    120105      initFile(file.exists() ? new Location(file.getParent(), 
    121         base + " Report.html").getAbsolutePath() : base + " Report.html"); 
     106        base + suffix).getAbsolutePath() : base + suffix); 
    122107      return; 
    123108    } 
     
    137122 
    138123    StringTokenizer st = new StringTokenizer(s, "\n"); 
     124    String token = null, key = null, value = null; 
    139125    while (st.hasMoreTokens()) { 
    140       String token = st.nextToken().trim(); 
     126      token = st.nextToken().trim(); 
    141127 
    142128      if ((token.startsWith("<") && !token.startsWith("</")) || 
     
    147133 
    148134        if (ndx != -1) { 
    149           addMeta(token.substring(0, ndx).trim(), 
    150             token.substring(ndx + 1).trim()); 
     135          key = token.substring(0, ndx).trim(); 
     136          value = token.substring(ndx + 1).trim(); 
     137 
     138          if (key.equals("Number of steps")) { 
     139            core.sizeZ[0] = Integer.parseInt(value); 
     140          } 
     141          else if (key.equals("Image bit depth")) { 
     142            int bits = Integer.parseInt(value); 
     143            while ((bits % 8) != 0) bits++; 
     144            switch (bits) { 
     145              case 16: 
     146                core.pixelType[0] = FormatTools.UINT16; 
     147                break; 
     148              case 32: 
     149                core.pixelType[0] = FormatTools.UINT32; 
     150                break; 
     151              default: core.pixelType[0] = FormatTools.UINT8; 
     152            } 
     153          } 
     154          else if (key.equals("Image dimensions")) { 
     155            int n = value.indexOf(","); 
     156            core.sizeX[0] = Integer.parseInt(value.substring(1, n).trim()); 
     157            core.sizeY[0] = Integer.parseInt(value.substring(n + 1, 
     158              value.length() - 1).trim()); 
     159          } 
     160 
     161          addMeta(key, value); 
    151162        } 
    152163 
     
    159170    } 
    160171 
    161     // now look for dimensions in the hashtable 
    162  
    163     core.sizeZ[0] = Integer.parseInt((String) metadata.get("Number of steps")); 
    164172    core.sizeT[0] = core.imageCount[0] / (core.sizeZ[0] * core.sizeC[0]); 
    165  
    166     int bits = Integer.parseInt((String) metadata.get("Image bit depth")); 
    167     while (bits % 8 != 0) bits++; 
    168     switch (bits) { 
    169       case 16: 
    170         core.pixelType[0] = FormatTools.UINT16; 
    171         break; 
    172       case 32: 
    173         core.pixelType[0] = FormatTools.UINT32; 
    174         break; 
    175       default: core.pixelType[0] = FormatTools.UINT8; 
    176     } 
    177  
    178     String xy = (String) metadata.get("Image dimensions"); 
    179     core.sizeX[0] = Integer.parseInt(xy.substring(1, xy.indexOf(",")).trim()); 
    180     core.sizeY[0] = Integer.parseInt(xy.substring(xy.indexOf(",") + 1, 
    181       xy.length() - 1).trim()); 
    182173    core.rgb[0] = false; 
    183174    core.currentOrder[0] = "XYZTC"; 
    184175    core.interleaved[0] = false; 
    185176    core.littleEndian[0] = true; 
     177    core.indexed[0] = false; 
     178    core.falseColor[0] = false; 
     179    core.metadataComplete[0] = true; 
    186180 
    187181    // find pixels files - we think there is one channel per file 
     
    206200    for (int i=0; i<core.sizeC[0]; i++) { 
    207201      store.setLogicalChannel(i, null, null, null, null, null, null, null, 
    208         null, null, null, null, null, core.sizeC[0] == 1 ? 
    209         "monochrome" : "RGB", null, null, null, null, null, null, null, null, 
    210         null, null, null); 
     202        null, null, null, null, null, null, null, null, null, null, null, null, 
     203        null, null, null, null, null); 
    211204    } 
    212205 
  • trunk/loci/formats/in/ZeissLSMReader.java

    r3176 r3197  
    8181  } 
    8282 
    83   /* @see loci.formats.IFormatReader#isMetadataComplete() */ 
    84   public boolean isMetadataComplete() { 
    85     return true; 
    86   } 
    87  
    88   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    89   public byte[] openBytes(int no) throws FormatException, IOException { 
    90     FormatTools.assertId(currentId, true, 1); 
    91     if (no < 0 || no >= getImageCount()) { 
    92       throw new FormatException("Invalid image number: " + no); 
    93     } 
    94  
    95     byte[] b = new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * 
    96       FormatTools.getBytesPerPixel(core.pixelType[0])]; 
    97     return openBytes(no, b); 
    98   } 
    99  
    10083  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    10184  public byte[] openBytes(int no, byte[] buf) 
     
    10386  { 
    10487    FormatTools.assertId(currentId, true, 1); 
    105     if (no < 0 || no >= getImageCount()) { 
    106       throw new FormatException("Invalid image number: " + no); 
    107     } 
    108  
    109     int bpp = FormatTools.getBytesPerPixel(core.pixelType[0]); 
    110  
    111     if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * bpp) { 
    112       throw new FormatException("Buffer too small."); 
    113     } 
     88    FormatTools.checkPlaneNumber(this, no); 
     89    FormatTools.checkBufferSize(this, buf.length); 
    11490 
    11591    ifds = TiffTools.getIFDs(in); 
     
    12399  { 
    124100    FormatTools.assertId(currentId, true, 1); 
    125     if (no < 0 || no >= getImageCount()) { 
    126       throw new FormatException("Invalid image number: " + no); 
    127     } 
     101    FormatTools.checkPlaneNumber(this, no); 
    128102 
    129103    if (2*no + 1 < ifds.length) return TiffTools.getImage(ifds[2*no + 1], in); 
  • trunk/loci/formats/in/ZeissZVIReader.java

    r3188 r3197  
    126126  } 
    127127 
    128   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    129   public byte[] openBytes(int no) throws FormatException, IOException { 
    130     FormatTools.assertId(currentId, true, 1); 
    131     byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * 
    132       FormatTools.getBytesPerPixel(core.pixelType[0]) * getRGBChannelCount()]; 
    133     return openBytes(no, buf); 
    134   } 
    135  
    136128  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
    137129  public byte[] openBytes(int no, byte[] buf) 
     
    140132    FormatTools.assertId(currentId, true, 1); 
    141133    if (noPOI || needLegacy) return legacy.openBytes(no, buf); 
    142     if (no < 0 || no >= getImageCount()) { 
    143       throw new FormatException("Invalid image number: " + no); 
    144     } 
    145  
    146     if (buf.length < core.sizeX[0] * core.sizeY[0] * 
    147       FormatTools.getBytesPerPixel(core.pixelType[0]) * getRGBChannelCount()) 
    148     { 
    149       throw new FormatException("Buffer too small."); 
    150     } 
     134    FormatTools.checkPlaneNumber(this, no); 
     135    FormatTools.checkBufferSize(this, buf.length); 
    151136 
    152137    try { 
     
    298283        (core.sizeZ[0] * core.sizeC[0] * core.sizeT[0] != core.imageCount[0]); 
    299284      core.littleEndian[0] = true; 
    300       core.interleaved[0] = false; 
     285      core.interleaved[0] = true; 
     286      core.indexed[0] = false; 
     287      core.falseColor[0] = false; 
     288      core.metadataComplete[0] = true; 
    301289 
    302290      core.sizeZ[0] = zIndices.size(); 
     
    311299        String zeroIndex = (String) getMeta("ImageTile Index 0"); 
    312300        String oneIndex = (String) getMeta("ImageTile Index 1"); 
     301        if (zeroIndex == null || zeroIndex.equals("")) zeroIndex = null; 
     302        if (oneIndex == null || oneIndex.equals("")) oneIndex = null; 
    313303        if (zeroIndex == null || oneIndex == null) { 
    314304          isTiled = false; 
     
    438428        String nextToLastDye = 
    439429          (String) getMeta("Reflector " + (core.sizeC[0] - 2)); 
     430        if (lastDye == null) lastDye = ""; 
     431        if (nextToLastDye == null) nextToLastDye = ""; 
    440432 
    441433        lastDye = DataTools.stripString(lastDye); 
     
    533525    store.setInstrument(null, scopeName, null, null, null); 
    534526 
    535     for (int i=0; i<getEffectiveSizeC(); i++) { 
    536       int idx = FormatTools.getIndex(this, 0, i, 0); 
    537       String name = (String) getMeta("Channel Name " + idx); 
     527    for (int i=0; i<core.sizeC[0]; i++) { 
     528      int idx = FormatTools.getIndex(this, 0, i % getEffectiveSizeC(), 0); 
    538529      String emWave = (String) getMeta("Emission Wavelength " + idx); 
    539530      String exWave = (String) getMeta("Excitation Wavelength " + idx); 
     
    545536        exWave = exWave.substring(0, exWave.indexOf(".")); 
    546537      } 
    547  
    548       store.setLogicalChannel(i, name, null, null, null, null, null, null, 
     538      store.setLogicalChannel(i, null, null, null, null, null, null, null, 
    549539        null, null, null, null, null, null, null, null, null, null, null, null, 
    550540        emWave == null ? null : new Integer(emWave), 
     
    579569      catch (NumberFormatException e) { } 
    580570      catch (NullPointerException e) { } 
    581       store.setPlaneInfo(zct[0], zct[1], zct[2], null, exp, null); 
     571      store.setPlaneInfo(zct[0], zct[1], zct[2], new Float(0.0), exp, null); 
    582572    } 
    583573 
  • trunk/loci/formats/ome/OMEReader.java

    r3104 r3197  
    200200  } 
    201201 
    202   /* @see loci.formats.IFormatReader#openBytes(int) */ 
    203   public byte[] openBytes(int no) throws FormatException, IOException { 
    204     if (no < 0 || no >= core.imageCount[0]) { 
    205       throw new FormatException("Invalid image number: " + no); 
    206     } 
     202  /* @see loci.formats.IFormatReader#openBytes(int, byte[]) */ 
     203  public byte[] openBytes(int no, byte[] buf) 
     204    throws FormatException, IOException 
     205  { 
     206    FormatTools.assertId(currentId, true, 1); 
     207    FormatTools.checkPlaneNumber(this, no); 
     208    FormatTools.checkBufferSize(this, buf.length); 
    207209    int[] indices = getZCTCoords(no); 
    208210    try { 
    209       byte[] b = pf.getPlane(pixels, indices[0], indices[1], indices[2], false); 
    210       return b; 
     211      buf = pf.getPlane(pixels, indices[0], indices[1], indices[2], false); 
     212      return buf; 
    211213    } 
    212214    catch (ImageServerException e) { 
     
    215217  } 
    216218 
    217   /* @see loci.formats.IFormatReader#openImage(int) */ 
    218   public BufferedImage openImage(int no) throws FormatException, IOException { 
    219     return ImageTools.makeImage(openBytes(no), core.sizeX[0], 
    220       core.sizeY[0], 1, false, FormatTools.getBytesPerPixel(core.pixelType[0]), 
    221       true); 
    222   } 
    223  
    224219  /* @see loci.formats.IFormatReader#openThumbBytes(int) */ 
    225220  public byte[] openThumbBytes(int no) throws FormatException, IOException { 
    226     if (no < 0 || no >= core.imageCount[0]) { 
    227       throw new FormatException("Invalid image number: " + no); 
    228     } 
     221    FormatTools.checkPlaneNumber(this, no); 
    229222    byte[][] b = ImageTools.getPixelBytes(openThumbImage(no), true); 
    230223    byte[] rtn = new byte[b.length * b[0].length]; 
     
    239232    throws FormatException, IOException 
    240233  { 
    241     if (no < 0 || no >= core.imageCount[0]) { 
    242       throw new FormatException("Invalid image number: " + no); 
    243     } 
     234    FormatTools.assertId(currentId, true, 1); 
     235    FormatTools.checkPlaneNumber(this, no); 
    244236    return thumb; 
    245237  } 
  • trunk/loci/formats/out/QTWriter.java

    r3124 r3197  
    4646 
    4747  // NB: Writing to Motion JPEG-B with QTJava seems to be broken. 
    48   ///** Value indicating Motion JPEG-B codec. */ 
    49   //public static final int CODEC_MOTION_JPEG_B = 1835692130; 
     48  /** Value indicating Motion JPEG-B codec. */ 
     49  public static final int CODEC_MOTION_JPEG_B = 1835692130; 
    5050 
    5151  /** Value indicating Cinepack codec. */ 
     
    121121      "Uncompressed", 
    122122      // NB: Writing to Motion JPEG-B with QTJava seems to be broken. 
    123       //"Motion JPEG-B", 
     123      "Motion JPEG-B", 
    124124      "Cinepak", "Animation", "H.263", "Sorenson", "Sorenson 3", "MPEG 4" 
    125125    }; 
     
    607607    if (compression.equals("Uncompressed")) codec = CODEC_RAW; 
    608608    // NB: Writing to Motion JPEG-B with QTJava seems to be broken. 
    609     //else if (compression.equals("Motion JPEG-B")) codec = CODEC_MOTION_JPEG_B; 
     609    else if (compression.equals("Motion JPEG-B")) codec = CODEC_MOTION_JPEG_B; 
    610610    else if (compression.equals("Cinepak")) codec = CODEC_CINEPAK; 
    611611    else if (compression.equals("Animation")) codec = CODEC_ANIMATION; 
  • trunk/loci/formats/tools/ImageInfo.java

    r3194 r3197  
    272272      boolean orderCertain = reader.isOrderCertain(); 
    273273      boolean interleaved = reader.isInterleaved(); 
     274      boolean metadataComplete = reader.isMetadataComplete(); 
    274275 
    275276      // output basic metadata for series #i 
     
    348349      LogTools.println("\tPixel type = " + 
    349350        FormatTools.getPixelTypeString(pixelType)); 
    350       LogTools.println("\tMetadata complete = " + reader.isMetadataComplete()); 
     351      LogTools.println("\tMetadata complete = " + metadataComplete); 
    351352      if (doMeta) { 
    352353        LogTools.println("\t-----"); 
Note: See TracChangeset for help on using the changeset viewer.