Changeset 2557


Ignore:
Timestamp:
04/04/07 07:30:30 (13 years ago)
Author:
melissa
Message:

Moved core metadata variables to loci.formats.CoreMetadata.

Location:
trunk/loci/formats
Files:
1 added
48 edited

Legend:

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

    r2538 r2557  
    5555  protected int series = 0; 
    5656 
    57   /** Dimension fields. */ 
    58   protected int[] sizeX, sizeY, sizeZ, sizeC, sizeT; 
    59   protected int[][] cLengths; 
    60   protected String[][] cTypes; 
    61   protected int[] pixelType; 
    62   protected String[] currentOrder; 
    63   protected boolean[] orderCertain; 
     57  /** Core metadata values. */ 
     58  protected CoreMetadata core; 
    6459 
    6560  /** Whether or not to ignore color tables, if present. */ 
     
    107102    metadata = new Hashtable(); 
    108103 
    109     sizeX = new int[1]; 
    110     sizeY = new int[1]; 
    111     sizeZ = new int[1]; 
    112     sizeC = new int[1]; 
    113     sizeT = new int[1]; 
    114     cLengths = new int[1][]; 
    115     cTypes = new String[1][]; 
    116     pixelType = new int[1]; 
    117     currentOrder = new String[1]; 
    118     orderCertain = new boolean[1]; 
    119     Arrays.fill(orderCertain, true); 
     104    core = new CoreMetadata(1); 
     105    Arrays.fill(core.orderCertain, true); 
    120106 
    121107    // reinitialize the MetadataStore 
     
    216202  public int getSizeX(String id) throws FormatException, IOException { 
    217203    if (!id.equals(currentId)) initFile(id); 
    218     return sizeX[series]; 
     204    return core.sizeX[series]; 
    219205  } 
    220206 
     
    222208  public int getSizeY(String id) throws FormatException, IOException { 
    223209    if (!id.equals(currentId)) initFile(id); 
    224     return sizeY[series]; 
     210    return core.sizeY[series]; 
    225211  } 
    226212 
     
    228214  public int getSizeZ(String id) throws FormatException, IOException { 
    229215    if (!id.equals(currentId)) initFile(id); 
    230     return sizeZ[series]; 
     216    return core.sizeZ[series]; 
    231217  } 
    232218 
     
    234220  public int getSizeC(String id) throws FormatException, IOException { 
    235221    if (!id.equals(currentId)) initFile(id); 
    236     return sizeC[series]; 
     222    return core.sizeC[series]; 
    237223  } 
    238224 
     
    240226  public int getSizeT(String id) throws FormatException, IOException { 
    241227    if (!id.equals(currentId)) initFile(id); 
    242     return sizeT[series]; 
     228    return core.sizeT[series]; 
    243229  } 
    244230 
     
    246232  public int getPixelType(String id) throws FormatException, IOException { 
    247233    if (!id.equals(currentId)) initFile(id); 
    248     return pixelType[series]; 
     234    return core.pixelType[series]; 
    249235  } 
    250236 
     
    265251  { 
    266252    if (!id.equals(currentId)) initFile(id); 
    267     if (cLengths[series] == null) { 
    268       cLengths[series] = new int[] {sizeC[series]}; 
    269     } 
    270     return cLengths[series]; 
     253    if (core.cLengths[series] == null) { 
     254      core.cLengths[series] = new int[] {core.sizeC[series]}; 
     255    } 
     256    return core.cLengths[series]; 
    271257  } 
    272258 
     
    276262  { 
    277263    if (!id.equals(currentId)) initFile(id); 
    278     if (cTypes[series] == null) { 
    279       cTypes[series] = new String[] {FormatTools.CHANNEL}; 
    280     } 
    281     return cTypes[series]; 
     264    if (core.cTypes[series] == null) { 
     265      core.cTypes[series] = new String[] {FormatTools.CHANNEL}; 
     266    } 
     267    return core.cTypes[series]; 
    282268  } 
    283269 
     
    305291  { 
    306292    if (!id.equals(currentId)) initFile(id); 
    307     return currentOrder[series]; 
     293    return core.currentOrder[series]; 
    308294  } 
    309295 
     
    311297  public boolean isOrderCertain(String id) throws FormatException, IOException { 
    312298    if (!id.equals(currentId)) initFile(id); 
    313     return orderCertain[series]; 
     299    return core.orderCertain[series]; 
    314300  } 
    315301 
     
    337323    throws FormatException, IOException 
    338324  { 
    339     buf = openBytes(id, no); 
    340     return buf; 
     325    return openBytes(id, no); 
    341326  } 
    342327 
     
    433418    if (!id.equals(currentId)) initFile(id); 
    434419    if (order == null) return; 
    435     if (order.equals(currentOrder[series])) return; 
     420    if (order.equals(core.currentOrder[series])) return; 
    436421 
    437422    int[] dims = new int[5]; 
    438423 
    439     int xndx = currentOrder[series].indexOf("X"); 
    440     int yndx = currentOrder[series].indexOf("Y"); 
    441     int zndx = currentOrder[series].indexOf("Z"); 
    442     int cndx = currentOrder[series].indexOf("C"); 
    443     int tndx = currentOrder[series].indexOf("T"); 
    444  
    445     dims[xndx] = sizeX[series]; 
    446     dims[yndx] = sizeY[series]; 
    447     dims[zndx] = sizeZ[series]; 
    448     dims[cndx] = sizeC[series]; 
    449     dims[tndx] = sizeT[series]; 
    450  
    451     sizeX[series] = dims[order.indexOf("X")]; 
    452     sizeY[series] = dims[order.indexOf("Y")]; 
    453     sizeZ[series] = dims[order.indexOf("Z")]; 
    454     sizeC[series] = dims[order.indexOf("C")]; 
    455     sizeT[series] = dims[order.indexOf("T")]; 
    456     currentOrder[series] = order; 
     424    int xndx = core.currentOrder[series].indexOf("X"); 
     425    int yndx = core.currentOrder[series].indexOf("Y"); 
     426    int zndx = core.currentOrder[series].indexOf("Z"); 
     427    int cndx = core.currentOrder[series].indexOf("C"); 
     428    int tndx = core.currentOrder[series].indexOf("T"); 
     429 
     430    dims[xndx] = core.sizeX[series]; 
     431    dims[yndx] = core.sizeY[series]; 
     432    dims[zndx] = core.sizeZ[series]; 
     433    dims[cndx] = core.sizeC[series]; 
     434    dims[tndx] = core.sizeT[series]; 
     435 
     436    core.sizeX[series] = dims[order.indexOf("X")]; 
     437    core.sizeY[series] = dims[order.indexOf("Y")]; 
     438    core.sizeZ[series] = dims[order.indexOf("Z")]; 
     439    core.sizeC[series] = dims[order.indexOf("C")]; 
     440    core.sizeT[series] = dims[order.indexOf("T")]; 
     441    core.currentOrder[series] = order; 
    457442 
    458443    MetadataStore store = getMetadataStore(id); 
    459     store.setPixels(new Integer(sizeX[series]), new Integer(sizeY[series]), 
    460       new Integer(sizeZ[series]), new Integer(sizeC[series]), 
    461       new Integer(sizeT[series]), null, null, order, new Integer(series), null); 
     444    store.setPixels(new Integer(core.sizeX[series]),  
     445      new Integer(core.sizeY[series]), new Integer(core.sizeZ[series]),  
     446      new Integer(core.sizeC[series]), new Integer(core.sizeT[series]),  
     447      null, null, order, new Integer(series), null); 
    462448  } 
    463449 
  • trunk/loci/formats/in/AVIReader.java

    r2535 r2557  
    5555  private String fcc = "error"; 
    5656  private int size = -1; 
    57   private int bigChunkSize; 
    5857  private long pos; 
    5958 
    60   // AVI Header chunk fields 
    61  
    62   private int dwMicroSecPerFrame, dwMaxBytesPerSec, dwReserved1, dwFlags; 
    63   private int dwTotalFrames, dwInitialFrames, dwStreams, dwSuggestedBufferSize; 
    64   private int dwWidth, dwHeight, dwScale, dwRate, dwStart, dwLength; 
    65  
    6659  // Stream Header chunk fields 
    6760 
    68   private String fccStreamType, fccStreamHandler; 
    69   private int dwStreamFlags, dwStreamReserved1, dwStreamInitialFrames; 
    70   private int dwStreamScale, dwStreamRate, dwStreamStart, dwStreamLength; 
    71   private int dwStreamSuggestedBufferSize, dwStreamQuality, dwStreamSampleSize; 
     61  private String fccStreamType; 
    7262 
    7363  // Stream Format chunk fields 
    7464 
    75   private int bmpSize, bmpSizeOfBitmap, bmpHorzResolution, bmpVertResolution; 
    76   private int bmpColorsUsed, bmpColorsImportant, bmpNoOfPixels, bmpWidth; 
    77   private int bmpHeight, bmpCompression, bmpActualSize, bmpScanLineSize; 
     65  private int bmpSizeOfBitmap; 
     66  private int bmpColorsUsed, bmpWidth; 
     67  private int bmpCompression, bmpScanLineSize; 
    7868  private int bmpActualColorsUsed; 
    79   private short bmpPlanes, bmpBitsPerPixel; 
    80   private boolean bmpTopDown; 
    81   private byte[] rawData = null; 
     69  private short bmpBitsPerPixel; 
    8270  private byte[] pr = null; 
    8371  private byte[] pg = null; 
     
    9179  // -- FormatReader API methods -- 
    9280 
    93   /** Checks if the given block is a valid header for an AVI file. */ 
     81  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    9482  public boolean isThisType(byte[] block) { 
    9583    return false; 
    9684  } 
    9785 
    98   /** Determines the number of images in the given AVI file. */ 
     86  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    9987  public int getImageCount(String id) throws FormatException, IOException { 
    10088    if (!id.equals(currentId)) initFile(id); 
     
    10896  } 
    10997 
    110   /** Return true if the data is in little-endian format. */ 
     98  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    11199  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    112100    if (!id.equals(currentId)) initFile(id); 
     
    114102  } 
    115103 
    116   /** Returns whether or not the channels are interleaved. */ 
     104  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    117105  public boolean isInterleaved(String id, int subC) 
    118106    throws FormatException, IOException 
     
    121109  } 
    122110 
    123   /** Obtains the specified image from the given AVI file as a byte array. */ 
     111  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    124112  public byte[] openBytes(String id, int no) 
    125113    throws FormatException, IOException 
    126114  { 
    127115    if (!id.equals(currentId)) initFile(id); 
    128     byte[] buf = new byte[bmpHeight * bmpScanLineSize * (bmpBitsPerPixel / 8)]; 
     116    byte[] buf =  
     117      new byte[core.sizeX[0] * bmpScanLineSize * (bmpBitsPerPixel / 8)]; 
    129118    return openBytes(id, no, buf); 
    130119  } 
    131120 
     121  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    132122  public byte[] openBytes(String id, int no, byte[] buf) 
    133123    throws FormatException, IOException 
     
    138128    } 
    139129 
    140     if (buf.length < bmpHeight*bmpScanLineSize*(bmpBitsPerPixel / 8)) { 
     130    if (buf.length < core.sizeY[0]*bmpScanLineSize*(bmpBitsPerPixel / 8)) { 
    141131      throw new FormatException("Buffer too small."); 
    142132    } 
     
    145135    in.seek((int) fileOff); 
    146136 
    147     int pad = bmpScanLineSize - dwWidth*(bmpBitsPerPixel / 8); 
    148     int offset = 0; 
    149  
    150     for (int i=bmpHeight - 1; i>=0; i--) { 
    151       if (bmpBitsPerPixel == 8) { 
    152         in.read(buf, i*dwWidth, dwWidth); 
    153         in.skipBytes(pad);  
     137    int pad = bmpScanLineSize - core.sizeX[0]*(bmpBitsPerPixel / 8); 
     138    int scanline = core.sizeX[0] * (bmpBitsPerPixel / 8); 
     139 
     140    for (int i=core.sizeY[0] - 1; i>=0; i--) { 
     141      in.read(buf, i*scanline, scanline); 
     142      if (bmpBitsPerPixel != 8) { 
     143        for (int j=0; j<core.sizeX[0]; j++) { 
     144          byte r = buf[i*scanline + j*3 + 2]; 
     145          buf[i*scanline + j*3 + 2] = buf[i*scanline + j*3]; 
     146          buf[i*scanline + j*3] = r; 
     147        } 
    154148      } 
    155       else { 
    156         in.read(buf, i*dwWidth*3, dwWidth * 3); 
    157         for (int j=0; j<dwWidth; j++) { 
    158           byte r = buf[i*dwWidth*3 + j*3 + 2]; 
    159           buf[i*dwWidth*3 + j*3 + 2] = buf[i*dwWidth*3 + j*3]; 
    160           buf[i*dwWidth*3 + j*3] = r; 
    161         } 
    162         in.skipBytes(pad*3); 
    163       } 
     149      in.skipBytes(pad * (bmpBitsPerPixel / 8)); 
    164150    } 
    165151    return buf; 
    166152  } 
    167153 
    168   /** Obtains the specified image from the given AVI file. */ 
     154  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    169155  public BufferedImage openImage(String id, int no) 
    170156    throws FormatException, IOException 
    171157  { 
    172158    return ImageTools.makeImage(openBytes(id, no), 
    173       dwWidth, bmpHeight, sizeC[0], true); 
     159      core.sizeX[0], core.sizeY[0], core.sizeC[0], true); 
    174160  } 
    175161 
     
    182168  } 
    183169 
    184   /** Closes any open files. */ 
     170  /* @see loci.formats.IFormatReader#close() */  
    185171  public void close() throws FormatException, IOException { 
    186172    if (in != null) in.close(); 
     
    208194 
    209195    if (type.equals("RIFF")) { 
    210       bigChunkSize = size; 
    211196      if (!fcc.equals("AVI ")) whine("Sorry, AVI RIFF format not found."); 
    212197    } 
     
    250235                spos = in.getFilePointer(); 
    251236 
    252                 dwMicroSecPerFrame = in.readInt(); 
    253                 dwMaxBytesPerSec = in.readInt(); 
    254                 dwReserved1 = in.readInt(); 
    255                 dwFlags = in.readInt(); 
    256                 dwTotalFrames = in.readInt(); 
    257                 dwInitialFrames = in.readInt(); 
    258                 dwStreams = in.readInt(); 
    259                 dwSuggestedBufferSize = in.readInt(); 
    260                 dwWidth = in.readInt(); 
    261                 dwHeight = in.readInt(); 
    262                 dwScale= in.readInt(); 
    263                 dwRate = in.readInt(); 
    264                 dwStart = in.readInt(); 
    265                 dwLength = in.readInt(); 
    266  
    267                 addMeta("Microseconds per frame", 
    268                   new Integer(dwMicroSecPerFrame)); 
    269                 addMeta("Max. bytes per second", 
    270                   new Integer(dwMaxBytesPerSec)); 
    271                 addMeta("Total frames", new Integer(dwTotalFrames)); 
    272                 addMeta("Initial frames", new Integer(dwInitialFrames)); 
    273                 addMeta("Frame width", new Integer(dwWidth)); 
    274                 addMeta("Frame height", new Integer(dwHeight)); 
    275                 addMeta("Scale factor", new Integer(dwScale)); 
    276                 addMeta("Frame rate", new Integer(dwRate)); 
    277                 addMeta("Start time", new Integer(dwStart)); 
    278                 addMeta("Length", new Integer(dwLength)); 
     237                addMeta("Microseconds per frame", new Integer(in.readInt())); 
     238                addMeta("Max. bytes per second", new Integer(in.readInt())); 
     239 
     240                in.skipBytes(8);  
     241                
     242                addMeta("Total frames", new Integer(in.readInt())); 
     243                addMeta("Initial frames", new Integer(in.readInt())); 
     244 
     245                in.skipBytes(8);  
     246                core.sizeX[0] = in.readInt(); 
     247                 
     248                addMeta("Frame height", new Integer(in.readInt())); 
     249                addMeta("Scale factor", new Integer(in.readInt())); 
     250                addMeta("Frame rate", new Integer(in.readInt())); 
     251                addMeta("Start time", new Integer(in.readInt())); 
     252                addMeta("Length", new Integer(in.readInt())); 
     253 
     254                addMeta("Frame width", new Integer(core.sizeX[0])); 
    279255 
    280256                if (spos + size <= in.length()) { 
     
    307283                } 
    308284 
    309                 fccStreamHandler = readStringBytes(); 
    310  
    311                 dwStreamFlags = in.readInt(); 
    312                 dwStreamReserved1 = in.readInt(); 
    313                 dwStreamInitialFrames = in.readInt(); 
    314                 dwStreamScale = in.readInt(); 
    315                 dwStreamRate = in.readInt(); 
    316                 dwStreamStart = in.readInt(); 
    317                 dwStreamLength = in.readInt(); 
    318                 dwStreamSuggestedBufferSize = in.readInt(); 
    319                 dwStreamQuality = in.readInt(); 
    320                 dwStreamSampleSize = in.readInt(); 
    321  
    322                 addMeta("Stream quality", new Integer(dwStreamQuality)); 
    323                 addMeta("Stream sample size", new Integer(dwStreamSampleSize)); 
     285                in.skipBytes(36); 
     286 
     287                addMeta("Stream quality", new Integer(in.readInt())); 
     288                addMeta("Stream sample size", new Integer(in.readInt())); 
    324289 
    325290                if (spos + size <= in.length()) { 
     
    333298                spos = in.getFilePointer(); 
    334299 
    335                 bmpSize = in.readInt(); 
     300                in.skipBytes(4);  
    336301                bmpWidth = in.readInt(); 
    337                 bmpHeight = in.readInt(); 
    338                 bmpPlanes = in.readShort(); 
     302                core.sizeY[0] = in.readInt(); 
     303                in.skipBytes(2);  
    339304                bmpBitsPerPixel = in.readShort(); 
    340305                bmpCompression = in.readInt(); 
    341306                bmpSizeOfBitmap = in.readInt(); 
    342                 bmpHorzResolution = in.readInt(); 
    343                 bmpVertResolution = in.readInt(); 
     307                 
     308                addMeta("Horizontal resolution", new Integer(in.readInt()));  
     309                addMeta("Vertical resolution", new Integer(in.readInt()));  
     310                 
    344311                bmpColorsUsed = in.readInt(); 
    345                 bmpColorsImportant = in.readInt(); 
    346  
    347                 bmpTopDown = (bmpHeight < 0); 
    348                 bmpNoOfPixels = bmpWidth * bmpHeight; 
     312                in.skipBytes(4); 
    349313 
    350314                addMeta("Bitmap compression value", 
    351315                  new Integer(bmpCompression)); 
    352                 addMeta("Horizontal resolution", 
    353                   new Integer(bmpHorzResolution)); 
    354                 addMeta("Vertical resolution", 
    355                   new Integer(bmpVertResolution)); 
    356316                addMeta("Number of colors used", 
    357317                  new Integer(bmpColorsUsed)); 
     
    363323 
    364324                bmpScanLineSize = (bmpWidth + npad) * (bmpBitsPerPixel / 8); 
    365  
    366                 if (bmpSizeOfBitmap != 0) { 
    367                   bmpActualSize = bmpSizeOfBitmap; 
    368                 } 
    369                 else { 
    370                   // a value of 0 doesn't mean 0 -- it means we have 
    371                   // to calculate it 
    372                   bmpActualSize = bmpScanLineSize * bmpHeight; 
    373                 } 
    374325 
    375326                if (bmpColorsUsed != 0) { 
     
    469420                { 
    470421                  offsets.add(new Long(in.getFilePointer())); 
    471                   in.skipBytes(bmpHeight * bmpScanLineSize); 
     422                  in.skipBytes(core.sizeY[0] * bmpScanLineSize); 
    472423                } 
    473424 
     
    509460    numImages = offsets.size(); 
    510461 
    511     sizeX[0] = dwWidth; 
    512     sizeY[0] = bmpHeight; 
    513     sizeZ[0] = 1; 
    514     sizeC[0] = isRGB(id) ? 3 : 1; 
    515     sizeT[0] = numImages; 
    516     currentOrder[0] = sizeC[0] == 3 ? "XYCTZ" : "XYTCZ"; 
     462    core.sizeZ[0] = 1; 
     463    core.sizeC[0] = isRGB(id) ? 3 : 1; 
     464    core.sizeT[0] = numImages; 
     465    core.currentOrder[0] = core.sizeC[0] == 3 ? "XYCTZ" : "XYTCZ"; 
    517466 
    518467    int bitsPerPixel = ((Integer) getMeta("Bits per pixel")).intValue(); 
    519468    int bytesPerPixel = bitsPerPixel / 8; 
    520469 
    521     if (bitsPerPixel == 8) pixelType[0] = FormatTools.UINT8; 
    522     else if (bitsPerPixel == 16) pixelType[0] = FormatTools.UINT16; 
    523     else if (bitsPerPixel == 32) pixelType[0] = FormatTools.UINT32; 
    524     else if (bitsPerPixel == 24) pixelType[0] = FormatTools.UINT8; 
     470    if (bitsPerPixel == 8) core.pixelType[0] = FormatTools.UINT8; 
     471    else if (bitsPerPixel == 16) core.pixelType[0] = FormatTools.UINT16; 
     472    else if (bitsPerPixel == 32) core.pixelType[0] = FormatTools.UINT32; 
     473    else if (bitsPerPixel == 24) core.pixelType[0] = FormatTools.UINT8; 
    525474    else 
    526475      throw new FormatException( 
     
    528477 
    529478    MetadataStore store = getMetadataStore(currentId); 
    530     store.setPixels(new Integer(sizeX[0]), new Integer(sizeY[0]), 
    531       new Integer(1), // SizeZ 
    532       new Integer(sizeC[0]), // SizeC 
     479    store.setPixels(new Integer(core.sizeX[0]), new Integer(core.sizeY[0]), 
     480      new Integer(core.sizeZ[0]), // SizeZ 
     481      new Integer(core.sizeC[0]), // SizeC 
    533482      new Integer(numImages), // SizeT 
    534       new Integer(pixelType[0]), // PixelType 
     483      new Integer(core.pixelType[0]), // PixelType 
    535484      new Boolean(!little), // BigEndian 
    536       currentOrder[0], // DimensionOrder 
     485      core.currentOrder[0], // DimensionOrder 
    537486      null, // Use image index 0 
    538487      null); // Use pixels index 0 
    539488 
    540     for (int i=0; i<sizeC[0]; i++) { 
     489    for (int i=0; i<core.sizeC[0]; i++) { 
    541490      store.setLogicalChannel(i, null, null, null, null, 
    542         sizeC[0] == 1 ? "monochrome" : "RGB", null, null); 
     491        core.sizeC[0] == 1 ? "monochrome" : "RGB", null, null); 
    543492    } 
    544493  } 
     
    561510  } 
    562511 
    563   // -- Main method -- 
    564  
    565   public static void main(String[] args) throws FormatException, IOException { 
    566     new AVIReader().testRead(args); 
    567   } 
    568  
    569512} 
  • trunk/loci/formats/in/AliconaReader.java

    r2535 r2557  
    4141  protected int numImages = 0; 
    4242 
    43   /** Image width. */ 
    44   private int width; 
    45  
    46   /** Image height. */ 
    47   private int height; 
    48  
    49   /** Number of channels. */ 
    50   private int channels; 
    51  
    5243  /** Image offset. */ 
    5344  private int textureOffset; 
     
    6354  // -- FormatReader API methods -- 
    6455 
    65   /** Checks if the given block is a valid header for an Alicona file. */ 
     56  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    6657  public boolean isThisType(byte[] block) { 
    6758    return (new String(block)).indexOf("Alicona") != -1; 
    6859  } 
    69  
    70   /** Determines the number of images in the given Alicona file. */ 
     60  
     61  /* @see loci.formats.IFormatReader#getImageCount(String) */ 
    7162  public int getImageCount(String id) throws FormatException, IOException { 
    7263    if (!id.equals(currentId)) initFile(id); 
     
    7970  } 
    8071 
    81   /** Return true if the data is in little-endian format. */ 
     72  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    8273  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    8374    return true; 
    8475  } 
    8576 
    86   /** Returns whether or not the channels are interleaved. */ 
     77  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    8778  public boolean isInterleaved(String id, int subC) 
    8879    throws FormatException, IOException 
     
    9182  } 
    9283 
    93   /** 
    94    * Obtains the specified image from the 
    95    * given Alicona file as a byte array. 
    96    */ 
     84  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    9785  public byte[] openBytes(String id, int no) 
    9886    throws FormatException, IOException 
    9987  { 
    10088    if (!id.equals(currentId)) initFile(id); 
    101     byte[] buf = new byte[width * height * numBytes]; 
     89    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * numBytes]; 
    10290    return openBytes(id, no, buf); 
    10391  } 
    10492 
     93  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    10594  public byte[] openBytes(String id, int no, byte[] buf) 
    10695    throws FormatException, IOException 
     
    111100    } 
    112101 
    113     int pad = (8 - (width % 8)) % 8; 
    114  
    115     if (buf.length < width * height * numBytes) { 
     102    int pad = (8 - (core.sizeX[0] % 8)) % 8; 
     103 
     104    if (buf.length < core.sizeX[0] * core.sizeY[0] * numBytes) { 
    116105      throw new FormatException("Buffer to small."); 
    117106    } 
    118107 
    119108    for (int i=0; i<numBytes; i++) { 
    120       in.seek(textureOffset + (no * (width + pad) * height * (i+1))); 
    121       for (int j=0; j<width*height; j++) { 
     109      in.seek(textureOffset + (no * (core.sizeX[0] + pad)*core.sizeY[0]*(i+1))); 
     110      for (int j=0; j<core.sizeX[0] * core.sizeY[0]; j++) { 
    122111        buf[j*numBytes + i] = (byte) in.read(); 
    123         if (j % width == width - 1) in.skipBytes(pad); 
     112        if (j % core.sizeX[0] == core.sizeX[0] - 1) in.skipBytes(pad); 
    124113      } 
    125114    } 
     
    128117  } 
    129118 
    130   /** Obtains the specified image from the given Alicona file. */ 
     119  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    131120  public BufferedImage openImage(String id, int no) 
    132121    throws FormatException, IOException 
    133122  { 
    134     BufferedImage b = ImageTools.makeImage(openBytes(id, no), width, height, 1, 
    135       false, numBytes, true); 
    136     return b; 
     123    return ImageTools.makeImage(openBytes(id, no), core.sizeX[0], core.sizeY[0], 
     124      1, false, numBytes, true); 
    137125  } 
    138126 
     
    143131  } 
    144132 
    145   /** Closes any open files. */ 
     133  /* @see loci.formats.IFormatReader#close() */  
    146134  public void close() throws FormatException, IOException { 
    147135    if (in != null) in.close(); 
     
    189177 
    190178      if (key.equals("TagCount")) count += Integer.parseInt(value); 
    191       else if (key.equals("Rows")) height = Integer.parseInt(value); 
    192       else if (key.equals("Cols")) width = Integer.parseInt(value); 
     179      else if (key.equals("Rows")) core.sizeY[0] = Integer.parseInt(value); 
     180      else if (key.equals("Cols")) core.sizeX[0] = Integer.parseInt(value); 
    193181      else if (key.equals("NumberOfPlanes")) { 
    194182        numImages = Integer.parseInt(value); 
     
    201189    status("Populating metadata"); 
    202190 
    203     numBytes = 
    204       (int) (in.length() - textureOffset) / (width * height * numImages); 
     191    numBytes = (int) (in.length() - textureOffset) /  
     192      (core.sizeX[0] * core.sizeY[0] * numImages); 
    205193 
    206194    boolean hasC = !((String) getMeta("TexturePtr")).trim().equals("7"); 
    207195 
    208     sizeX[0] = width; 
    209     sizeY[0] = height; 
    210     sizeC[0] = hasC ? 3 : 1; 
    211     sizeZ[0] = 1; 
    212     sizeT[0] = numImages / sizeC[0]; 
    213  
    214     pixelType[0] = numBytes == 2 ? FormatTools.UINT16 : FormatTools.UINT8; 
    215     currentOrder[0] = "XYCTZ"; 
     196    core.sizeC[0] = hasC ? 3 : 1; 
     197    core.sizeZ[0] = 1; 
     198    core.sizeT[0] = numImages / core.sizeC[0]; 
     199 
     200    core.pixelType[0] = numBytes == 2 ? FormatTools.UINT16 : FormatTools.UINT8; 
     201    core.currentOrder[0] = "XYCTZ"; 
    216202 
    217203    MetadataStore store = getMetadataStore(id); 
    218204    store.setPixels( 
    219       new Integer(width), 
    220       new Integer(height), 
    221       new Integer(sizeZ[0]), 
    222       new Integer(sizeC[0]), 
    223       new Integer(sizeT[0]), 
    224       new Integer(pixelType[0]), 
     205      new Integer(core.sizeX[0]), 
     206      new Integer(core.sizeY[0]), 
     207      new Integer(core.sizeZ[0]), 
     208      new Integer(core.sizeC[0]), 
     209      new Integer(core.sizeT[0]), 
     210      new Integer(core.pixelType[0]), 
    225211      new Boolean(true), 
    226       "XYCTZ", 
     212      core.currentOrder[0], 
    227213      null, 
    228214      null 
     
    247233    } 
    248234 
    249     for (int i=0; i<sizeC[0]; i++) { 
     235    for (int i=0; i<core.sizeC[0]; i++) { 
    250236      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    251237    } 
    252238  } 
    253239 
    254   // -- Main method -- 
    255  
    256   public static void main(String[] args) throws FormatException, IOException { 
    257     new AliconaReader().testRead(args); 
    258   } 
    259  
    260240} 
  • trunk/loci/formats/in/BMPReader.java

    r2535 r2557  
    4343  protected RandomAccessStream in; 
    4444 
    45   /** Flag indicating whether current file is little endian. */ 
    46   protected boolean littleEndian; 
    47  
    4845  /** Offset to the image data. */ 
    4946  protected int offset; 
    50  
    51   /** Image width. */ 
    52   protected int width; 
    53  
    54   /** Image height. */ 
    55   protected int height; 
    5647 
    5748  /** Number of bits per pixel. */ 
     
    7364  private int global; 
    7465 
    75   /** The pixel type. */ 
    76   private int pixType; 
    77  
    7866  // -- Constructor -- 
    7967 
     
    8371  // -- FormatReader API methods -- 
    8472 
    85   /** Checks if the given block is a valid header for a BMP file. */ 
     73  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    8674  public boolean isThisType(byte[] block) { 
    8775    if (block.length != 14) { 
     
    9280  } 
    9381 
    94   /** Determines the number of images in the given BMP file. */ 
     82  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    9583  public int getImageCount(String id) throws FormatException, IOException { 
    96     if (!id.equals(currentId)) initFile(id); 
    9784    return 1; 
    9885  } 
     
    10491  } 
    10592 
    106   /** Return true if the data is in little-endian format. */ 
     93  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    10794  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    108     if (!id.equals(currentId)) initFile(id); 
    109     return littleEndian; 
    110   } 
    111  
    112   /** Returns whether or not the channels are interleaved. */ 
     95    return true; 
     96  } 
     97 
     98  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    11399  public boolean isInterleaved(String id, int subC) 
    114100    throws FormatException, IOException 
     
    117103  } 
    118104 
     105  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    119106  public byte[] openBytes(String id, int no, byte[] buf) 
    120107    throws FormatException, IOException 
     
    125112    } 
    126113 
    127     if (width % 2 == 1) width++; 
    128  
    129     if (buf.length < width * height * (bpp / 8)) { 
     114    int pixels = core.sizeX[0] * core.sizeY[0]; 
     115 
     116    if (buf.length < pixels * (bpp / 8)) { 
    130117      throw new FormatException("Buffer too small."); 
    131118    } 
     
    137124 
    138125    in.seek(global); 
    139     int pixels = width * height; 
    140126 
    141127    if (palette != null && palette[0].length > 0 && !ignoreColorTable) { 
    142       for (int y=height-1; y>=0; y--) { 
    143         for (int x=0; x<width; x++) { 
     128      for (int y=core.sizeY[0]-1; y>=0; y--) { 
     129        for (int x=0; x<core.sizeX[0]; x++) { 
    144130          int val = in.read(); 
    145131          if (val < 0) val += 127; 
    146           buf[y*width + x] = palette[0][val]; 
    147           buf[y*width + x + pixels] = palette[1][val]; 
    148           buf[y*width + x + 2*pixels] = palette[2][val]; 
     132          buf[y*core.sizeX[0] + x] = palette[0][val]; 
     133          buf[y*core.sizeX[0] + x + pixels] = palette[1][val]; 
     134          buf[y*core.sizeX[0] + x + 2*pixels] = palette[2][val]; 
    149135        } 
    150136      } 
     
    152138    else { 
    153139      if (bpp <= 8) { 
    154         for (int y=height-1; y>=0; y--) { 
    155           for (int x=0; x<width; x++) { 
    156             buf[y*width + x] = (byte) in.read(); 
     140        for (int y=core.sizeY[0]-1; y>=0; y--) { 
     141          for (int x=0; x<core.sizeX[0]; x++) { 
     142            buf[y*core.sizeX[0] + x] = (byte) in.read(); 
    157143          } 
    158144        } 
    159145      } 
    160146      else { 
    161         for (int y=height-1; y>=0; y--) { 
    162           for (int x=0; x<width; x++) { 
    163             buf[y*width + x + 2*pixels] = (byte) in.read(); 
    164             buf[y*width + x + pixels] = (byte) in.read(); 
    165             buf[y*width + x] = (byte) in.read(); 
     147        for (int y=core.sizeY[0]-1; y>=0; y--) { 
     148          for (int x=0; x<core.sizeX[0]; x++) { 
     149            buf[y*core.sizeX[0] + x + 2*pixels] = (byte) in.read(); 
     150            buf[y*core.sizeX[0] + x + pixels] = (byte) in.read(); 
     151            buf[y*core.sizeX[0] + x] = (byte) in.read(); 
    166152            for (int j=0; j<(bpp - 24) / 8; j++) in.read(); 
    167153          } 
     
    172158  } 
    173159 
    174   /** Obtains the specified image from the given BMP file as a byte array. */ 
     160  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    175161  public byte[] openBytes(String id, int no) 
    176162    throws FormatException, IOException 
    177163  { 
    178164    if (!id.equals(currentId)) initFile(id); 
    179     if (width % 2 == 1) width++; 
    180     byte[] buf = new byte[width * height * (bpp / 8)]; 
     165    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * (bpp / 8)]; 
    181166    return openBytes(id, no, buf); 
    182167  } 
    183168 
    184   /** Obtains the specified image from the given BMP file. */ 
     169  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    185170  public BufferedImage openImage(String id, int no) 
    186171    throws FormatException, IOException 
    187172  { 
    188     BufferedImage b = ImageTools.makeImage(openBytes(id, no), width, height, 
    189       !isRGB(id) ? 1 : 3, false); 
    190     return b; 
     173    return ImageTools.makeImage(openBytes(id, no), core.sizeX[0], core.sizeY[0],  
     174      core.sizeC[0], false); 
    191175  } 
    192176 
     
    197181  } 
    198182 
    199   /** Closes any open files. */ 
     183  /* @see loci.formats.IFormatReader#close() */  
    200184  public void close() throws FormatException, IOException { 
    201185    if (in != null) in.close(); 
     
    212196    status("Reading bitmap header"); 
    213197 
    214     littleEndian = true; 
    215     in.order(littleEndian); 
     198    in.order(true); 
    216199 
    217200    // read the first header - 14 bytes 
     
    233216    // get the dimensions 
    234217 
    235     width = in.readInt(); 
    236     height = in.readInt(); 
    237  
    238     if (width < 1 || height < 1) { 
     218    core.sizeX[0] = in.readInt(); 
     219    core.sizeY[0] = in.readInt(); 
     220 
     221    if (core.sizeX[0] < 1 || core.sizeY[0] < 1) { 
    239222      throw new FormatException("Invalid image dimensions: " + 
    240         width + " x " + height); 
    241     } 
    242     addMeta("Image width", "" + width); 
    243     addMeta("Image height", "" + height); 
     223        core.sizeX[0] + " x " + core.sizeY[0]); 
     224    } 
     225    addMeta("Image width", "" + core.sizeX[0]); 
     226    addMeta("Image height", "" + core.sizeY[0]); 
    244227 
    245228    addMeta("Color planes", "" + in.readShort()); 
     
    291274    status("Populating metadata"); 
    292275 
    293     int c = (palette == null & bpp == 8) ? 1 : 3; 
    294     int tbpp = bpp; 
    295     if (bpp > 8) tbpp /= 3; 
    296     while (tbpp % 8 != 0) tbpp++; 
    297  
    298     switch (tbpp) { 
     276    core.sizeC[0] = (palette == null & bpp == 8) ? 1 : 3; 
     277    if (bpp > 8) bpp /= 3; 
     278    while (bpp % 8 != 0) bpp++; 
     279 
     280    switch (bpp) { 
    299281      case 8: 
    300         pixType = FormatTools.UINT8; 
     282        core.pixelType[0] = FormatTools.UINT8; 
    301283        break; 
    302284      case 16: 
    303         pixType = FormatTools.UINT16; 
     285        core.pixelType[0] = FormatTools.UINT16; 
    304286        break; 
    305287      case 32: 
    306         pixType = FormatTools.UINT32; 
    307         break; 
    308     } 
    309  
    310     sizeX[0] = (width % 2 == 1) ? width + 1 : width; 
    311     sizeY[0] = height; 
    312     sizeZ[0] = 1; 
    313     sizeC[0] = isRGB(id) ? 3 : 1; 
    314     sizeT[0] = 1; 
    315     pixelType[0] = pixType; 
    316     currentOrder[0] = "XYCTZ"; 
     288        core.pixelType[0] = FormatTools.UINT32; 
     289        break; 
     290    } 
     291 
     292    if (core.sizeX[0] % 2 == 1) core.sizeX[0]++;  
     293    core.sizeZ[0] = 1; 
     294    core.sizeC[0] = isRGB(id) ? 3 : 1; 
     295    core.sizeT[0] = 1; 
     296    core.currentOrder[0] = "XYCTZ"; 
    317297 
    318298    // Populate metadata store. 
     
    322302 
    323303    store.setPixels( 
    324       new Integer(width),  // sizeX 
    325       new Integer(height), // sizeY 
    326       new Integer(1), // sizeZ 
    327       new Integer(c), // sizeC 
    328       new Integer(1), // sizeT 
    329       new Integer(pixType), 
    330       new Boolean(!littleEndian), // BigEndian 
    331       "XYCTZ", // Dimension order 
     304      new Integer(core.sizeX[0]),  // sizeX 
     305      new Integer(core.sizeY[0]), // sizeY 
     306      new Integer(core.sizeZ[0]), // sizeZ 
     307      new Integer(core.sizeC[0]), // sizeC 
     308      new Integer(core.sizeT[0]), // sizeT 
     309      new Integer(core.pixelType[0]), 
     310      new Boolean(false), // BigEndian 
     311      core.currentOrder[0], // Dimension order 
    332312      null, // Use image index 0 
    333313      null); // Use pixels index 0 
     
    345325      null, null, null); 
    346326 
    347     for (int i=0; i<sizeC[0]; i++) { 
     327    for (int i=0; i<core.sizeC[0]; i++) { 
    348328      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    349329    } 
    350330  } 
    351331 
    352   // -- Main method -- 
    353  
    354   public static void main(String[] args) throws FormatException, IOException { 
    355     new BMPReader().testRead(args); 
    356   } 
    357  
    358332} 
  • trunk/loci/formats/in/BaseTiffReader.java

    r2535 r2557  
    450450    } 
    451451 
    452     sizeX[0] = 
     452    core.sizeX[0] = 
    453453      TiffTools.getIFDIntValue(ifds[0], TiffTools.IMAGE_WIDTH, false, 0); 
    454     sizeY[0] = 
     454    core.sizeY[0] = 
    455455      TiffTools.getIFDIntValue(ifds[0], TiffTools.IMAGE_LENGTH, false, 0); 
    456     sizeZ[0] = 1; 
     456    core.sizeZ[0] = 1; 
    457457 
    458458    try { 
    459       sizeC[0] = isRGB(currentId) ? 3 : 1; 
     459      core.sizeC[0] = isRGB(currentId) ? 3 : 1; 
    460460    } 
    461461    catch (IOException e) { 
     
    463463    } 
    464464 
    465     sizeT[0] = ifds.length; 
     465    core.sizeT[0] = ifds.length; 
    466466 
    467467    int bitFormat = TiffTools.getIFDIntValue(ifds[0], 
     
    471471    if (bps == 24 || bps == 48) bps /= 3; 
    472472 
    473     if (bitFormat == 3) pixelType[0] = FormatTools.FLOAT; 
     473    if (bitFormat == 3) core.pixelType[0] = FormatTools.FLOAT; 
    474474    else if (bitFormat == 2) { 
    475475      switch (bps) { 
    476476        case 8: 
    477           pixelType[0] = FormatTools.UINT8; 
     477          core.pixelType[0] = FormatTools.UINT8; 
    478478          break; 
    479479        case 16: 
    480           pixelType[0] = FormatTools.INT16; 
     480          core.pixelType[0] = FormatTools.INT16; 
    481481          break; 
    482482        case 32: 
    483           pixelType[0] = FormatTools.INT32; 
     483          core.pixelType[0] = FormatTools.INT32; 
    484484          break; 
    485485        default: 
    486           pixelType[0] = FormatTools.UINT8; 
     486          core.pixelType[0] = FormatTools.UINT8; 
    487487      } 
    488488    } 
     
    490490      switch (bps) { 
    491491        case 8: 
    492           pixelType[0] = FormatTools.UINT8; 
     492          core.pixelType[0] = FormatTools.UINT8; 
    493493          break; 
    494494        case 16: 
    495           pixelType[0] = FormatTools.UINT16; 
     495          core.pixelType[0] = FormatTools.UINT16; 
    496496          break; 
    497497        case 32: 
    498           pixelType[0] = FormatTools.UINT32; 
     498          core.pixelType[0] = FormatTools.UINT32; 
    499499          break; 
    500500        default: 
    501           pixelType[0] = FormatTools.UINT8; 
    502       } 
    503     } 
    504  
    505     currentOrder[0] = "XYCZT"; 
     501          core.pixelType[0] = FormatTools.UINT8; 
     502      } 
     503    } 
     504 
     505    core.currentOrder[0] = "XYCZT"; 
    506506  } 
    507507 
     
    651651  } 
    652652 
    653   // -- FormatReader API methods -- 
    654  
    655   /** Checks if the given block is a valid header for a TIFF file. */ 
    656   public boolean isThisType(byte[] block) { 
    657     return TiffTools.isValidHeader(block); 
    658   } 
    659  
    660   /** Determines the number of images in the given TIFF file. */ 
    661   public int getImageCount(String id) throws FormatException, IOException { 
    662     if (!id.equals(currentId)) initFile(id); 
    663     return numImages; 
    664   } 
    665  
    666   /* @see loci.formats.IFormatReader#isRGB(String) */ 
    667   public boolean isRGB(String id) throws FormatException, IOException { 
    668     if (!id.equals(currentId)) initFile(id); 
    669     if (TiffTools.getIFDIntValue(ifds[0], 
    670       TiffTools.SAMPLES_PER_PIXEL, false, 1) > 1) 
    671     { 
    672       return true; 
    673     } 
    674     int p = TiffTools.getIFDIntValue(ifds[0], 
    675       TiffTools.PHOTOMETRIC_INTERPRETATION, true, 0); 
    676     return (!isColorTableIgnored() && (p == TiffTools.RGB_PALETTE || 
    677       p == TiffTools.CFA_ARRAY)) || p == TiffTools.RGB; 
    678   } 
    679  
    680   /** 
    681    * Obtains the specified metadata field's value for the given file. 
    682    * 
    683    * @param field the name associated with the metadata field 
    684    * @return the value, or null if the field doesn't exist 
    685    */ 
    686   public Object getMetadataValue(String id, String field) 
    687     throws FormatException, IOException 
    688   { 
    689     if (!id.equals(currentId) && !DataTools.samePrefix(id, currentId)) { 
    690       initFile(id); 
    691     } 
    692     return getMeta(field); 
    693   } 
    694  
    695   /** Return true if the data is in little-endian format. */ 
    696   public boolean isLittleEndian(String id) throws FormatException, IOException { 
    697     if (!id.equals(currentId)) initFile(id); 
    698     return TiffTools.isLittleEndian(ifds[0]); 
    699   } 
    700  
    701   /** Returns whether or not the channels are interleaved. */ 
    702   public boolean isInterleaved(String id, int subC) 
    703     throws FormatException, IOException 
    704   { 
    705     if (!id.equals(currentId)) initFile(id); 
    706     return TiffTools.getSamplesPerPixel(ifds[0]) > 1;  
    707   } 
    708  
    709   /* @see loci.formats.FormatReader#openBytes(String, int, byte[]) */ 
    710   public byte[] openBytes(String id, int no, byte[] buf) 
    711     throws FormatException, IOException 
    712   { 
    713     if (!id.equals(currentId)) initFile(id); 
    714  
    715     if (no < 0 || no >= getImageCount(id)) { 
    716       throw new FormatException("Invalid image number: " + no); 
    717     } 
    718  
    719     TiffTools.getSamples(ifds[no], in, ignoreColorTable, buf); 
    720     return swapIfRequired(buf); 
    721   } 
    722  
    723   /* @see loci.formats.FormatReader#openBytes(String, int) */ 
    724   public byte[] openBytes(String id, int no) 
    725     throws FormatException, IOException 
    726   { 
    727     if (!id.equals(currentId)) initFile(id); 
    728  
    729     if (no < 0 || no >= getImageCount(id)) { 
    730       throw new FormatException("Invalid image number: " + no); 
    731     } 
    732  
    733     int bytesPerPixel = FormatTools.getBytesPerPixel(getPixelType(id)); 
    734     byte[] buf = new byte[getSizeX(id) * getSizeY(id) * bytesPerPixel * 
    735       getRGBChannelCount(id)]; 
    736     return openBytes(id, no, buf); 
    737   } 
    738  
    739653  /** 
    740654   * Examines a byte array to see if it needs to be byte swapped and modifies 
     
    770684  } 
    771685 
    772   /** Obtains the specified image from the given TIFF file. */ 
     686  // -- FormatReader API methods -- 
     687 
     688  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
     689  public boolean isThisType(byte[] block) { 
     690    return TiffTools.isValidHeader(block); 
     691  } 
     692 
     693  /* @see loci.formats.IFormatReader#getImageCount(String) */  
     694  public int getImageCount(String id) throws FormatException, IOException { 
     695    if (!id.equals(currentId)) initFile(id); 
     696    return numImages; 
     697  } 
     698 
     699  /* @see loci.formats.IFormatReader#isRGB(String) */ 
     700  public boolean isRGB(String id) throws FormatException, IOException { 
     701    if (!id.equals(currentId)) initFile(id); 
     702    if (TiffTools.getIFDIntValue(ifds[0], 
     703      TiffTools.SAMPLES_PER_PIXEL, false, 1) > 1) 
     704    { 
     705      return true; 
     706    } 
     707    int p = TiffTools.getIFDIntValue(ifds[0], 
     708      TiffTools.PHOTOMETRIC_INTERPRETATION, true, 0); 
     709    return (!isColorTableIgnored() && (p == TiffTools.RGB_PALETTE || 
     710      p == TiffTools.CFA_ARRAY)) || p == TiffTools.RGB; 
     711  } 
     712 
     713  /* @see loci.formats.IFormatReader#getMetadataValue(String, String) */  
     714  public Object getMetadataValue(String id, String field) 
     715    throws FormatException, IOException 
     716  { 
     717    if (!id.equals(currentId) && !DataTools.samePrefix(id, currentId)) { 
     718      initFile(id); 
     719    } 
     720    return getMeta(field); 
     721  } 
     722 
     723  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
     724  public boolean isLittleEndian(String id) throws FormatException, IOException { 
     725    if (!id.equals(currentId)) initFile(id); 
     726    return TiffTools.isLittleEndian(ifds[0]); 
     727  } 
     728 
     729  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
     730  public boolean isInterleaved(String id, int subC) 
     731    throws FormatException, IOException 
     732  { 
     733    if (!id.equals(currentId)) initFile(id); 
     734    return TiffTools.getSamplesPerPixel(ifds[0]) > 1;  
     735  } 
     736 
     737  /* @see loci.formats.FormatReader#openBytes(String, int, byte[]) */ 
     738  public byte[] openBytes(String id, int no, byte[] buf) 
     739    throws FormatException, IOException 
     740  { 
     741    if (!id.equals(currentId)) initFile(id); 
     742 
     743    if (no < 0 || no >= getImageCount(id)) { 
     744      throw new FormatException("Invalid image number: " + no); 
     745    } 
     746 
     747    TiffTools.getSamples(ifds[no], in, ignoreColorTable, buf); 
     748    return swapIfRequired(buf); 
     749  } 
     750 
     751  /* @see loci.formats.FormatReader#openBytes(String, int) */ 
     752  public byte[] openBytes(String id, int no) 
     753    throws FormatException, IOException 
     754  { 
     755    if (!id.equals(currentId)) initFile(id); 
     756 
     757    if (no < 0 || no >= getImageCount(id)) { 
     758      throw new FormatException("Invalid image number: " + no); 
     759    } 
     760 
     761    int bytesPerPixel = FormatTools.getBytesPerPixel(getPixelType(id)); 
     762    byte[] buf = new byte[getSizeX(id) * getSizeY(id) * bytesPerPixel * 
     763      getRGBChannelCount(id)]; 
     764    return openBytes(id, no, buf); 
     765  } 
     766 
     767  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    773768  public BufferedImage openImage(String id, int no) 
    774769    throws FormatException, IOException 
     
    782777    } 
    783778 
    784     BufferedImage b = TiffTools.getImage(ifds[no], in, ignoreColorTable); 
    785     return b; 
     779    return TiffTools.getImage(ifds[no], in, ignoreColorTable); 
    786780  } 
    787781 
     
    792786  } 
    793787 
    794   /** Closes any open files. */ 
     788  /* @see loci.formats.IFormatReader#close() */  
    795789  public void close() throws FormatException, IOException { 
    796790    if (in != null) in.close(); 
     
    804798    super.initFile(id); 
    805799    in = new RandomAccessStream(id); 
    806     if (in.readShort() == 0x4949) in.order(true); 
     800    in.order(in.readShort() == 0x4949); 
    807801 
    808802    status("Reading IFDs"); 
  • trunk/loci/formats/in/BioRadReader.java

    r2535 r2557  
    6868  private RandomAccessStream in; 
    6969 
    70   /** Dimensions of each image in current Bio-Rad PIC. */ 
    71   private int nx, ny, nz, nt; 
    72  
    7370  /** Number of images in current Bio-Rad PIC. */ 
    7471  private int npic; 
     
    8481  // -- FormatReader API methods -- 
    8582 
    86   /** Checks if the given block is a valid header for a Bio-Rad PIC file. */ 
     83  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    8784  public boolean isThisType(byte[] block) { 
    8885    if (block.length < 56) return false; 
     
    9087  } 
    9188 
    92   /** Determines the number of images in the given Bio-Rad PIC file. */ 
     89  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    9390  public int getImageCount(String id) throws FormatException, IOException { 
    9491    if (!id.equals(currentId)) initFile(id); 
     
    10198  } 
    10299 
    103   /** Return true if the data is in little-endian format. */ 
     100  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    104101  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    105102    return LITTLE_ENDIAN; 
    106103  } 
    107104 
    108   /** Returns whether or not the channels are interleaved. */ 
     105  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    109106  public boolean isInterleaved(String id, int subC) 
    110107    throws FormatException, IOException 
     
    113110  } 
    114111 
    115   /** Obtains the specified image from the given file as a byte array. */ 
     112  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    116113  public byte[] openBytes(String id, int no) 
    117114    throws FormatException, IOException 
    118115  { 
    119116    if (!id.equals(currentId)) initFile(id); 
    120     byte[] buf = new byte[nx * ny * (byteFormat ? 1 : 2)]; 
     117    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * (byteFormat ? 1 : 2)]; 
    121118    return openBytes(id, no, buf); 
    122119  } 
    123120 
     121  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    124122  public byte[] openBytes(String id, int no, byte[] buf) 
    125123    throws FormatException, IOException 
     
    129127      throw new FormatException("Invalid image number: " + no); 
    130128    } 
    131     if (buf.length < nx * ny * (byteFormat ? 1 : 2)) { 
     129    if (buf.length < core.sizeX[0] * core.sizeY[0] * (byteFormat ? 1 : 2)) { 
    132130      throw new FormatException("Buffer too small."); 
    133131    } 
    134132 
    135     int offset = no * nx * ny * (byteFormat ? 1 : 2); 
     133    int offset = no * core.sizeX[0] * core.sizeY[0] * (byteFormat ? 1 : 2); 
    136134    in.seek(offset + 76); 
    137135    in.read(buf); 
     
    139137  } 
    140138 
    141   /** Obtains the specified image from the given Bio-Rad PIC file. */ 
     139  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    142140  public BufferedImage openImage(String id, int no) 
    143141    throws FormatException, IOException 
    144142  { 
    145     BufferedImage b = ImageTools.makeImage(openBytes(id, no), nx, ny, 1, false, 
    146       byteFormat ? 1 : 2, LITTLE_ENDIAN); 
     143    BufferedImage b = ImageTools.makeImage(openBytes(id, no), core.sizeX[0],  
     144      core.sizeY[0], 1, false, byteFormat ? 1 : 2, LITTLE_ENDIAN); 
    147145    return b; 
    148146  } 
     
    154152  } 
    155153 
    156   /** Closes any open files. */ 
     154  /* @see loci.formats.IFormatReader#close() */  
    157155  public void close() throws FormatException, IOException { 
    158156    currentId = null; 
     
    173171    // read header 
    174172 
    175     nx = in.readShort(); 
    176     ny = in.readShort(); 
     173    core.sizeX[0] = in.readShort(); 
     174    core.sizeY[0] = in.readShort(); 
    177175    npic = in.readShort(); 
    178176 
     
    201199 
    202200    // populate metadata fields 
    203     addMeta("nx", new Integer(nx)); 
    204     addMeta("ny", new Integer(ny)); 
     201    addMeta("nx", new Integer(core.sizeX[0])); 
     202    addMeta("ny", new Integer(core.sizeY[0])); 
    205203    addMeta("npic", new Integer(npic)); 
    206204    addMeta("ramp1_min", new Integer(ramp1min)); 
     
    221219 
    222220    // skip image data 
    223     int imageLen = nx * ny; 
     221    int imageLen = core.sizeX[0] * core.sizeY[0]; 
    224222    int bpp = byteFormat ? 1 : 2; 
    225223    in.skipBytes(bpp * npic * imageLen + 6); 
     
    227225    Vector pixelSize = new Vector(); 
    228226 
    229     int zSize = npic; 
    230     int cSize = 1; 
    231     int tSize = 1; 
    232  
    233     orderCertain[0] = false; 
     227    core.sizeZ[0] = npic; 
     228    core.sizeC[0] = 1; 
     229    core.sizeT[0] = 1; 
     230 
     231    core.orderCertain[0] = false; 
    234232 
    235233    status("Reading notes"); 
     
    504502                addMeta(key + " time (X) in seconds", params.get(0)); 
    505503                addMeta(key + " time (Y) in seconds", params.get(1)); 
    506                 zSize = 1; 
    507                 tSize = npic; 
    508                 orderCertain[0] = true; 
     504                core.sizeZ[0] = 1; 
     505                core.sizeT[0] = npic; 
     506                core.orderCertain[0] = true; 
    509507              } 
    510508              break; 
     
    625623    // populate Pixels element 
    626624    in.seek(14); 
    627     //int type = DataTools.bytesToInt(header, 14, 2, LITTLE_ENDIAN); 
    628     int type = in.readShort(); 
    629     if (type == 1) 
    630       pixelType[0] = FormatTools.UINT8; 
    631     else 
    632       pixelType[0] = FormatTools.UINT16; 
    633  
    634     String dimOrder = "XY"; 
    635     int[] dims = new int[] {zSize, cSize, tSize}; 
     625    core.pixelType[0] = in.readShort() == 1 ? FormatTools.UINT16 :  
     626      FormatTools.UINT8;  
     627 
     628    core.currentOrder[0] = "XY"; 
     629    int[] dims = new int[] {core.sizeZ[0], core.sizeC[0], core.sizeT[0]}; 
    636630    int max = 0; 
    637631    int min = Integer.MAX_VALUE; 
     
    646640    int[] orderedDims = new int[] {max, median, min}; 
    647641    for (int i=0; i<orderedDims.length; i++) { 
    648       if (orderedDims[i] == zSize && dimOrder.indexOf("Z") == -1) { 
    649         dimOrder += "Z"; 
     642      if (orderedDims[i] == core.sizeZ[0] &&  
     643        core.currentOrder[0].indexOf("Z") == -1)  
     644      { 
     645        core.currentOrder[0] += "Z"; 
    650646      } 
    651       else if (orderedDims[i] == cSize && dimOrder.indexOf("C") == -1) { 
    652         dimOrder += "C"; 
     647      else if (orderedDims[i] == core.sizeC[0] &&  
     648        core.currentOrder[0].indexOf("C") == -1)  
     649      { 
     650        core.currentOrder[0] += "C"; 
    653651      } 
    654       else dimOrder += "T"; 
    655     } 
    656  
    657     nz = zSize; 
    658     nt = tSize; 
    659  
    660     sizeX[0] = nx; 
    661     sizeY[0] = ny; 
    662     sizeZ[0] = zSize; 
    663     sizeC[0] = cSize; 
    664     sizeT[0] = tSize; 
    665     currentOrder[0] = dimOrder; 
     652      else core.currentOrder[0] += "T"; 
     653    } 
    666654 
    667655    store.setPixels( 
    668       new Integer(nx), // SizeX 
    669       new Integer(ny), // SizeY 
    670       new Integer(zSize), // SizeZ 
    671       new Integer(cSize), // SizeC 
    672       new Integer(tSize), // SizeT 
    673       new Integer(pixelType[0]), // PixelType 
     656      new Integer(core.sizeX[0]), // SizeX 
     657      new Integer(core.sizeY[0]), // SizeY 
     658      new Integer(core.sizeZ[0]), // SizeZ 
     659      new Integer(core.sizeC[0]), // SizeC 
     660      new Integer(core.sizeT[0]), // SizeT 
     661      new Integer(core.pixelType[0]), // PixelType 
    674662      Boolean.FALSE, // BigEndian 
    675       dimOrder, // DimensionOrder 
     663      core.currentOrder[0], // DimensionOrder 
    676664      null, // Use image index 0 
    677665      null); // Use pixels index 0 
     
    687675    store.setDefaultDisplaySettings(null); 
    688676 
    689     for (int i=0; i<sizeC[0]; i++) { 
     677    for (int i=0; i<core.sizeC[0]; i++) { 
    690678      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    691679      String black = (String) getMeta("PMT " + i + " Black level"); 
    692680      store.setDisplayChannel(new Integer(i), black == null ? null : 
    693         new Double(black), new Double(Math.pow(2, type == 1 ? 8 : 16)), 
     681        new Double(black), new Double(Math.pow(2,  
     682        core.pixelType[0] == FormatTools.UINT8 ? 8 : 16)), 
    694683        null, null); 
    695684    } 
     
    698687    String zstop = (String) getMeta("Z stop"); 
    699688    store.setDisplayOptions(zoom == null ? null : new Float(zoom), 
    700       new Boolean(sizeC[0] > 1), new Boolean(sizeC[0] >= 2), 
    701       new Boolean(sizeC[0] >= 3), Boolean.FALSE, null, zstart == null ? null : 
     689      new Boolean(core.sizeC[0] > 1), new Boolean(core.sizeC[0] >= 2), 
     690      new Boolean(core.sizeC[0] >= 3), Boolean.FALSE, null, 
     691      zstart == null ? null : 
    702692      new Integer((int) (new Double(zstart).doubleValue())), zstop == null ? 
    703693      null : new Integer((int) (new Double(zstop).doubleValue())), null, null, 
    704       null, null, sizeC[0] > 1 ? new Integer(0) : null, 
    705       sizeC[0] > 1 ? new Integer(1) : null, 
    706       sizeC[0] > 1 ? new Integer(2) : null, new Integer(0)); 
     694      null, null, core.sizeC[0] > 1 ? new Integer(0) : null, 
     695      core.sizeC[0] > 1 ? new Integer(1) : null, 
     696      core.sizeC[0] > 1 ? new Integer(2) : null, new Integer(0)); 
     697     
    707698    for (int i=0; i<3; i++) { 
    708699      String prefix = "Transmission detector " + (i+1) + " - "; 
     
    747738  } 
    748739 
    749   // -- Main method -- 
    750  
    751   public static void main(String[] args) throws FormatException, IOException { 
    752     new BioRadReader().testRead(args); 
    753   } 
    754740} 
  • trunk/loci/formats/in/DeltavisionReader.java

    r2535 r2557  
    5757  protected byte[] extHeader; 
    5858 
    59   /** Image width. */ 
    60   private int width; 
    61  
    62   /** Image height. */ 
    63   private int height; 
    64  
    6559  /** Bytes per pixel. */ 
    6660  private int bytesPerPixel; 
     
    6963  protected int initExtHdrOffset = 1024; 
    7064 
    71   /** Dimension order. */ 
    72   private String order; 
    73  
    7465  /** Size of one wave in the extended header. */ 
    7566  protected int wSize; 
     
    8071  /** Size of one time element in the extended header. */ 
    8172  protected int tSize; 
    82  
    83   protected int numT; 
    84   protected int numW; 
    85   protected int numZ; 
    8673 
    8774  /** 
     
    10491  // -- FormatReader API methods -- 
    10592 
    106   /** Checks if the given block is a valid header for a Deltavision file. */ 
     93  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    10794  public boolean isThisType(byte[] block) { 
    10895    return (DataTools.bytesToShort(block, 0, 2, little) == LITTLE_ENDIAN); 
    10996  } 
    11097 
    111   /** Determines the number of images in the given Deltavision file. */ 
     98  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    11299  public int getImageCount(String id) throws FormatException, IOException { 
    113100    if (!id.equals(currentId)) initFile(id); 
     
    115102  } 
    116103 
    117   /** Get the size of the X dimension. */ 
    118   public int getSizeX(String id) throws FormatException, IOException { 
    119     if (!id.equals(currentId)) initFile(id); 
    120     return width; 
    121   } 
    122  
    123   /** Get the size of the Y dimension. */ 
    124   public int getSizeY(String id) throws FormatException, IOException { 
    125     if (!id.equals(currentId)) initFile(id); 
    126     return height; 
    127   } 
    128  
    129   /** Get the size of the Z dimension. */ 
    130   public int getSizeZ(String id) throws FormatException, IOException { 
    131     if (!id.equals(currentId)) initFile(id); 
    132     return numZ; 
    133   } 
    134  
    135   /** Get the size of the C dimension. */ 
    136   public int getSizeC(String id) throws FormatException, IOException { 
    137     if (!id.equals(currentId)) initFile(id); 
    138     return numW; 
    139   } 
    140  
    141   /** Get the size of the T dimension. */ 
    142   public int getSizeT(String id) throws FormatException, IOException { 
    143     if (!id.equals(currentId)) initFile(id); 
    144     return numT; 
    145   } 
    146  
    147104  /* @see loci.formats.IFormatReader#isRGB(String) */ 
    148105  public boolean isRGB(String id) throws FormatException, IOException { 
     
    150107  } 
    151108 
    152   /** Return true if the data is in little-endian format. */ 
     109  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    153110  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    154111    if (!id.equals(currentId)) initFile(id); 
     
    156113  } 
    157114 
    158   /** Returns whether or not the channels are interleaved. */ 
     115  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    159116  public boolean isInterleaved(String id, int subC) 
    160117    throws FormatException, IOException 
     
    163120  } 
    164121 
    165   /** Obtains the specified image from the given file as a byte array. */ 
     122  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    166123  public byte[] openBytes(String id, int no) 
    167124    throws FormatException, IOException 
    168125  { 
    169126    if (!id.equals(currentId)) initFile(id); 
    170     byte[] buf = new byte[width * height * bytesPerPixel]; 
     127    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bytesPerPixel]; 
    171128    return openBytes(id, no, buf); 
    172129  } 
     
    184141    // read the image plane's pixel data 
    185142    int offset = header.length + extHeader.length; 
    186     offset += width * height * bytesPerPixel * no; 
     143    offset += core.sizeX[0] * core.sizeY[0] * bytesPerPixel * no; 
    187144 
    188145    in.seek(offset); 
     
    191148  } 
    192149 
    193   /** Obtains the specified image from the given Deltavision file. */ 
     150  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    194151  public BufferedImage openImage(String id, int no) 
    195152    throws FormatException, IOException 
    196153  { 
    197     BufferedImage b = ImageTools.makeImage(openBytes(id, no), width, height, 1, 
    198       false, bytesPerPixel, little); 
    199     return b; 
     154    return ImageTools.makeImage(openBytes(id, no), core.sizeX[0],  
     155      core.sizeY[0], 1, false, bytesPerPixel, little); 
    200156  } 
    201157 
     
    206162  } 
    207163 
    208   /** Closes any open files. */ 
     164  /* @see loci.formats.IFormatReader#close() */  
    209165  public void close() throws FormatException, IOException { 
    210166    if (in != null) in.close(); 
     
    234190    in.read(extHeader); 
    235191 
    236     width = DataTools.bytesToInt(header, 0, 4, little); 
    237     height = DataTools.bytesToInt(header, 4, 4, little); 
    238  
    239     Integer xSize = new Integer(width); 
    240     Integer ySize = new Integer(height); 
     192    core.sizeX[0] = DataTools.bytesToInt(header, 0, 4, little); 
     193    core.sizeY[0] = DataTools.bytesToInt(header, 4, 4, little); 
     194 
     195    Integer xSize = new Integer(core.sizeX[0]); 
     196    Integer ySize = new Integer(core.sizeY[0]); 
    241197    addMeta("ImageWidth", xSize); 
    242198    addMeta("ImageHeight", ySize); 
     
    249205      case 0: 
    250206        pixel = "8 bit unsigned integer"; 
    251         pixelType[0] = FormatTools.UINT8; 
     207        core.pixelType[0] = FormatTools.UINT8; 
    252208        bytesPerPixel = 1; 
    253209        break; 
    254210      case 1: 
    255211        pixel = "16 bit signed integer"; 
    256         pixelType[0] = FormatTools.UINT16; 
     212        core.pixelType[0] = FormatTools.UINT16; 
    257213        bytesPerPixel = 2; 
    258214        break; 
    259215      case 2: 
    260216        pixel = "32 bit floating point"; 
    261         pixelType[0] = FormatTools.FLOAT; 
     217        core.pixelType[0] = FormatTools.FLOAT; 
    262218        bytesPerPixel = 4; 
    263219        break; 
    264220      case 3: 
    265221        pixel = "32 bit complex"; 
    266         pixelType[0] = FormatTools.UINT32; 
     222        core.pixelType[0] = FormatTools.UINT32; 
    267223        bytesPerPixel = 4; 
    268224        break; 
    269225      case 4: 
    270226        pixel = "64 bit complex"; 
    271         pixelType[0] = FormatTools.FLOAT; 
     227        core.pixelType[0] = FormatTools.FLOAT; 
    272228        bytesPerPixel = 8; 
    273229        break; 
    274230      case 6: 
    275231        pixel = "16 bit unsigned integer"; 
    276         pixelType[0] = FormatTools.UINT16; 
     232        core.pixelType[0] = FormatTools.UINT16; 
    277233        bytesPerPixel = 2; 
    278234        break; 
    279235      default: 
    280236        pixel = "unknown"; 
    281         pixelType[0] = FormatTools.UINT8; 
     237        core.pixelType[0] = FormatTools.UINT8; 
    282238        bytesPerPixel = 1; 
    283239    } 
     
    384340    addMeta("Wavelength 5 max. intensity", wave5Max); 
    385341 
    386     numT = DataTools.bytesToShort(header, 180, 2, little); 
    387     addMeta("Number of timepoints", new Integer(numT)); 
     342    core.sizeT[0] = DataTools.bytesToShort(header, 180, 2, little); 
     343    addMeta("Number of timepoints", new Integer(core.sizeT[0])); 
    388344 
    389345    int sequence = DataTools.bytesToInt(header, 182, 4, little); 
    390346    String imageSequence; 
    391     String dimOrder; 
    392347    switch (sequence) { 
    393348      case 0: 
    394         imageSequence = "ZTW"; dimOrder = "XYZTC"; 
     349        imageSequence = "ZTW"; core.currentOrder[0] = "XYZTC"; 
    395350        break; 
    396351      case 1: 
    397         imageSequence = "WZT"; dimOrder = "XYCZT"; 
     352        imageSequence = "WZT"; core.currentOrder[0] = "XYCZT"; 
    398353        break; 
    399354      case 2: 
    400         imageSequence = "ZWT"; dimOrder = "XYZCT"; 
     355        imageSequence = "ZWT"; core.currentOrder[0] = "XYZCT"; 
    401356        break; 
    402357      case 65536: 
    403         imageSequence = "WZT"; dimOrder = "XYCZT"; 
     358        imageSequence = "WZT"; core.currentOrder[0] = "XYCZT"; 
    404359        break; 
    405360      default: 
    406         imageSequence = "unknown"; dimOrder = "XYZTC"; 
     361        imageSequence = "unknown"; core.currentOrder[0] = "XYZTC"; 
    407362    } 
    408363    addMeta("Image sequence", imageSequence); 
     
    415370      DataTools.bytesToInt(header, 192, 4, little)))); 
    416371 
    417     numW = DataTools.bytesToShort(header, 196, 2, little); 
    418     addMeta("Number of wavelengths", new Integer(numW)); 
    419     numZ = numImages / (numW * numT); 
    420     addMeta("Number of focal planes", new Integer(numZ)); 
     372    core.sizeC[0] = DataTools.bytesToShort(header, 196, 2, little); 
     373    addMeta("Number of wavelengths", new Integer(core.sizeC[0])); 
     374    core.sizeZ[0] = numImages / (core.sizeC[0] * core.sizeT[0]); 
     375    addMeta("Number of focal planes", new Integer(core.sizeZ[0])); 
    421376 
    422377    addMeta("Wavelength 1 (in nm)", new Integer(DataTools.bytesToShort( 
     
    437392      DataTools.bytesToInt(header, 216, 4, little)))); 
    438393 
    439     order = dimOrder; 
    440  
    441394    // The metadata store we're working with. 
    442395    MetadataStore store = getMetadataStore(id); 
     
    449402    } 
    450403 
    451     sizeX[0] = width; 
    452     sizeY[0] = height; 
    453     sizeZ[0] = numZ; 
    454     sizeC[0] = numW; 
    455     sizeT[0] = numT; 
    456     currentOrder[0] = order; 
    457  
    458404    // ----- The Extended Header data handler begins here ------ 
    459405 
     
    462408    numIntsPerSection = DataTools.bytesToInt(header, 128, 2, little); 
    463409    numFloatsPerSection = DataTools.bytesToInt(header, 130, 2, little); 
    464     setOffsetInfo(sequence, numZ, numW, numT); 
    465     extHdrFields = new DVExtHdrFields[numZ][numW][numT]; 
    466  
    467     store.setPixels(new Integer(width), new Integer(height), new Integer(numZ), 
    468       new Integer(numW), new Integer(numT), new Integer(pixelType[0]), 
    469       new Boolean(!little), dimOrder, null, null); 
     410    setOffsetInfo(sequence, core.sizeZ[0], core.sizeC[0], core.sizeT[0]); 
     411    extHdrFields =  
     412      new DVExtHdrFields[core.sizeZ[0]][core.sizeC[0]][core.sizeT[0]]; 
     413 
     414    store.setPixels(new Integer(core.sizeX[0]), new Integer(core.sizeY[0]),  
     415      new Integer(core.sizeZ[0]), new Integer(core.sizeC[0]),  
     416      new Integer(core.sizeT[0]), new Integer(core.pixelType[0]), 
     417      new Boolean(!little), core.currentOrder[0], null, null); 
    470418 
    471419    store.setDimensions( 
     
    482430    // Run through every timeslice, for each wavelength, for each z section 
    483431    // and fill in the Extended Header information array for that image 
    484     for (int z = 0; z < numZ; z++) { 
    485       for (int t = 0; t < numT; t++) { 
    486         for (int w = 0; w < numW; w++) { 
     432    for (int z = 0; z < core.sizeZ[0]; z++) { 
     433      for (int t = 0; t < core.sizeT[0]; t++) { 
     434        for (int w = 0; w < core.sizeC[0]; w++) { 
    487435          extHdrFields[z][w][t] = new DVExtHdrFields(getTotalOffset(z, w, t), 
    488436            numIntsPerSection, extHeader, little); 
     
    497445    status("Populating metadata"); 
    498446 
    499     for (int w=0; w<numW; w++) { 
     447    for (int w=0; w<core.sizeC[0]; w++) { 
    500448      store.setLogicalChannel(w, null, 
    501449        new Float(extHdrFields[0][w][0].getNdFilter()), 
     
    510458      new Float(extHdrFields[0][0][0].getStageZCoord()), null); 
    511459 
    512     if (numW > 0) { 
     460    if (core.sizeC[0] > 0) { 
    513461      store.setChannelGlobalMinMax(0, new Double(wave1Min.floatValue()), 
    514462        new Double(wave1Max.floatValue()), null); 
    515463    } 
    516     if (numW > 1) { 
     464    if (core.sizeC[0] > 1) { 
    517465      store.setChannelGlobalMinMax(1, new Double(wave2Min.floatValue()), 
    518466        new Double(wave2Max.floatValue()), null); 
    519467    } 
    520     if (numW > 2) { 
     468    if (core.sizeC[0] > 2) { 
    521469      store.setChannelGlobalMinMax(2, new Double(wave3Min.floatValue()), 
    522470        new Double(wave3Max.floatValue()), null); 
    523471    } 
    524     if (numW > 3) { 
     472    if (core.sizeC[0] > 3) { 
    525473      store.setChannelGlobalMinMax(3, new Double(wave4Min.floatValue()), 
    526474        new Double(wave4Max.floatValue()), null); 
    527475    } 
    528     if (numW > 4) { 
     476    if (core.sizeC[0] > 4) { 
    529477      store.setChannelGlobalMinMax(4, new Double(wave5Min.floatValue()), 
    530478        new Double(wave5Max.floatValue()), null); 
     
    767715  } 
    768716 
    769   // -- Main method -- 
    770  
    771   public static void main(String[] args) throws FormatException, IOException { 
    772     new DeltavisionReader().testRead(args); 
    773   } 
    774  
    775717} 
  • trunk/loci/formats/in/DicomReader.java

    r2535 r2557  
    8181  protected int numImages = 0; 
    8282 
    83   /** Image width. */ 
    84   protected int width; 
    85  
    86   /** Image height. */ 
    87   protected int height; 
    88  
    8983  /** Bits per pixel. */ 
    9084  protected int bitsPerPixel; 
     
    113107  // -- FormatReader API methods -- 
    114108 
    115   /** Checks if the given block is a valid header for a DICOM file. */ 
     109  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    116110  public boolean isThisType(byte[] block) { 
    117111    return false; 
    118112  } 
    119113 
    120   /** Determines the number of images in the given DICOM file. */ 
     114  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    121115  public int getImageCount(String id) throws FormatException, IOException { 
    122116    if (!id.equals(currentId)) initFile(id); 
     
    124118  } 
    125119 
    126   /** Checks if the images in the file are RGB. */ 
     120  /* @see loci.formats.IFormatReader#isRGB(String) */  
    127121  public boolean isRGB(String id) throws FormatException, IOException { 
    128122    return false; 
    129123  } 
    130124 
    131   /** Return true if the data is in little-endian format. */ 
     125  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    132126  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    133127    if (!id.equals(currentId)) initFile(id); 
     
    135129  } 
    136130 
    137   /** Returns whether or not the channels are interleaved. */ 
     131  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    138132  public boolean isInterleaved(String id, int subC) 
    139133    throws FormatException, IOException 
     
    142136  } 
    143137 
    144   /** Obtains the specified image from the given file as a byte array. */ 
     138  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    145139  public byte[] openBytes(String id, int no) 
    146140    throws FormatException, IOException 
    147141  { 
    148142    if (!id.equals(currentId)) initFile(id); 
    149     byte[] buf = new byte[width * height * (bitsPerPixel / 8)]; 
     143    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8)]; 
    150144    return openBytes(id, no, buf); 
    151145  } 
    152146 
     147  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    153148  public byte[] openBytes(String id, int no, byte[] buf) 
    154149    throws FormatException, IOException 
     
    158153      throw new FormatException("Invalid image number: " + no); 
    159154    } 
    160     if (buf.length < width * height * (bitsPerPixel / 8)) { 
     155     
     156    int bytes = core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8);  
     157     
     158    if (buf.length < bytes) { 
    161159      throw new FormatException("Buffer too small."); 
    162160    } 
    163161 
    164     in.seek(offsets + (width * height * (bitsPerPixel / 8) * no)); 
     162    in.seek(offsets + bytes * no); 
    165163    in.read(buf); 
    166164    return buf; 
    167165  } 
    168166 
    169   /** Obtains the specified image from the given DICOM file. */ 
     167  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    170168  public BufferedImage openImage(String id, int no) 
    171169    throws FormatException, IOException 
    172170  { 
    173     BufferedImage b = ImageTools.makeImage(openBytes(id, no), width, height, 
     171    return ImageTools.makeImage(openBytes(id, no), core.sizeX[0], core.sizeY[0], 
    174172      1, false, bitsPerPixel / 8, little); 
    175     return b; 
    176173  } 
    177174 
     
    182179  } 
    183180 
    184   /** Closes any open files. */ 
     181  /* @see loci.formats.IFormatReader#close() */  
    185182  public void close() throws FormatException, IOException { 
    186183    if (in != null) in.close(); 
     
    272269          break; 
    273270        case ROWS: 
    274           height = in.readShort(); 
    275           addInfo(tag, height); 
     271          core.sizeY[0] = in.readShort(); 
     272          addInfo(tag, core.sizeY[0]); 
    276273          break; 
    277274        case COLUMNS: 
    278           width = in.readShort(); 
    279           addInfo(tag, width); 
     275          core.sizeX[0] = in.readShort(); 
     276          addInfo(tag, core.sizeX[0]); 
    280277          break; 
    281278        case PIXEL_SPACING: 
     
    333330    status("Populating metadata"); 
    334331 
    335     sizeX[0] = width; 
    336     sizeY[0] = height; 
    337     sizeZ[0] = numImages; 
    338     sizeC[0] = 1; 
    339     sizeT[0] = 1; 
    340     currentOrder[0] = "XYZTC"; 
     332    core.sizeZ[0] = numImages; 
     333    core.sizeC[0] = 1; 
     334    core.sizeT[0] = 1; 
     335    core.currentOrder[0] = "XYZTC"; 
    341336 
    342337    // The metadata store we're working with. 
     
    348343    switch (bitsPerPixel) { 
    349344      case 8: 
    350         pixelType[0] = FormatTools.UINT8; 
     345        core.pixelType[0] = FormatTools.UINT8; 
    351346        break; 
    352347      case 16: 
    353         pixelType[0] = FormatTools.UINT16; 
     348        core.pixelType[0] = FormatTools.UINT16; 
    354349        break; 
    355350      case 32: 
    356         pixelType[0] = FormatTools.UINT32; 
     351        core.pixelType[0] = FormatTools.UINT32; 
    357352        break; 
    358353    } 
     
    360355    // populate OME-XML node 
    361356    store.setPixels( 
    362       new Integer((String) getMeta("Columns")), // SizeX 
    363       new Integer((String) getMeta("Rows")), // SizeY 
    364       new Integer(numImages), // SizeZ 
    365       new Integer(1), // SizeC 
    366       new Integer(1), // SizeT 
    367       new Integer(pixelType[0]),  // PixelType 
     357      new Integer(core.sizeX[0]), // SizeX 
     358      new Integer(core.sizeY[0]), // SizeY 
     359      new Integer(core.sizeZ[0]), // SizeZ 
     360      new Integer(core.sizeC[0]), // SizeC 
     361      new Integer(core.sizeT[0]), // SizeT 
     362      new Integer(core.pixelType[0]),  // PixelType 
    368363      new Boolean(!little),  // BigEndian 
    369       "XYZTC", // Dimension order 
     364      core.currentOrder[0], // Dimension order 
    370365      null, // Use image index 0 
    371366      null); // Use pixels index 0 
     
    396391      null, null, null); 
    397392 
    398     for (int i=0; i<sizeC[0]; i++) { 
     393    for (int i=0; i<core.sizeC[0]; i++) { 
    399394      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    400395    } 
     
    12031198  } 
    12041199 
    1205   // -- Main method -- 
    1206  
    1207   public static void main(String[] args) throws FormatException, IOException { 
    1208     new DicomReader().testRead(args); 
    1209   } 
    1210  
    12111200} 
  • trunk/loci/formats/in/EPSReader.java

    r2535 r2557  
    4343  protected RandomAccessStream in; 
    4444 
    45   /** Image width. */ 
    46   private int width; 
    47  
    48   /** Image height. */ 
    49   private int height; 
    50  
    5145  /** Bits per sample. */ 
    5246  private int bps; 
    53  
    54   /** Number of channels. */ 
    55   private int channels = 1; 
    5647 
    5748  /** Starting line of pixel data. */ 
     
    7061  // -- FormatReader API methods -- 
    7162 
    72   /** Checks if the given block is a valid header for an EPS file. */ 
     63  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    7364  public boolean isThisType(byte[] block) { 
    7465    return false; 
    7566  } 
    7667 
    77   /** Determines the number of images in the given EPS file. */ 
     68  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    7869  public int getImageCount(String id) throws FormatException, IOException { 
    79     if (!id.equals(currentId)) initFile(id); 
    8070    return 1; 
    8171  } 
    8272 
    83   /** Checks if the images in the file are RGB. */ 
     73  /* @see loci.formats.IFormatReader#isRGB(String) */  
    8474  public boolean isRGB(String id) throws FormatException, IOException { 
    8575    if (!id.equals(currentId)) initFile(id); 
    86     return channels == 3; 
    87   } 
    88  
    89   /** Return true if the data is in little-endian format. */ 
     76    return core.sizeC[0] == 3; 
     77  } 
     78 
     79  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    9080  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    9181    return true; 
    9282  } 
    9383 
    94   /** Returns whether or not the channels are interleaved. */ 
     84  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    9585  public boolean isInterleaved(String id, int subC) 
    9686    throws FormatException, IOException 
     
    9989  } 
    10090 
    101   /** 
    102    * Obtains the specified image from the given EPS file as a byte array. 
    103    */ 
     91  /* @see loci.formats.IFormatRaeder#openBytes(String, int) */  
    10492  public byte[] openBytes(String id, int no) 
    10593    throws FormatException, IOException 
    10694  { 
    10795    if (!id.equals(currentId)) initFile(id); 
    108     byte[] buf = new byte[width * height * channels * (bps / 8)]; 
     96    byte[] buf =  
     97      new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * (bps / 8)]; 
    10998    return openBytes(id, no, buf); 
    11099  } 
    111100 
     101  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    112102  public byte[] openBytes(String id, int no, byte[] buf) 
    113103    throws FormatException, IOException 
     
    117107      throw new FormatException("Invalid image number: " + no); 
    118108    } 
    119     if (buf.length < width * height * channels * (bps / 8)) { 
     109    if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0] * (bps / 8)) { 
    120110      throw new FormatException("Buffer too small."); 
    121111    } 
     
    138128      int numLines = buf.length / len.trim().length(); 
    139129 
     130      char[] chars = new char[2]; 
     131 
    140132      for (int i=0; i<buf.length; i++) { 
    141         char msb = (char) ras.read(); 
    142         while (msb == '\n') msb = (char) ras.read(); 
    143         char lsb = (char) ras.read(); 
    144         while (lsb == '\n') lsb = (char) ras.read(); 
    145         String s = new String(new char[] {msb, lsb}); 
     133        chars[0] = (char) ras.read(); 
     134        while (chars[0] == '\n') chars[0] = (char) ras.read(); 
     135        chars[1] = (char) ras.read(); 
     136        while (chars[1] == '\n') chars[1] = (char) ras.read(); 
     137        String s = new String(chars); 
    146138        buf[i] = (byte) Integer.parseInt(s, 16); 
    147139      } 
     
    151143  } 
    152144 
    153   /** Obtains the specified image from the given EPS file. */ 
     145  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    154146  public BufferedImage openImage(String id, int no) 
    155147    throws FormatException, IOException 
    156148  { 
    157     BufferedImage b = ImageTools.makeImage(openBytes(id, no), width, height, 
    158       !isRGB(id) ? 1 : 3, true); 
    159     return b; 
     149    return ImageTools.makeImage(openBytes(id, no), core.sizeX[0], core.sizeY[0],  
     150      isRGB(id) ? 3 : 1, true); 
    160151  } 
    161152 
     
    166157  } 
    167158 
    168   /** Closes any open files. */ 
     159  /* @see loci.formats.IFormatReader#close() */  
    169160  public void close() throws FormatException, IOException { 
    170161    if (in != null) in.close(); 
     
    198189      if (line.trim().equals(image) || line.trim().endsWith(image)) { 
    199190        if (line.trim().endsWith(image) && !line.trim().startsWith(image)) { 
    200           if (line.indexOf("colorimage") != -1) channels = 3; 
     191          if (line.indexOf("colorimage") != -1) core.sizeC[0] = 3; 
    201192          StringTokenizer t = new StringTokenizer(line, " "); 
    202193          try { 
    203             width = Integer.parseInt(t.nextToken()); 
    204             height = Integer.parseInt(t.nextToken()); 
     194            core.sizeX[0] = Integer.parseInt(t.nextToken()); 
     195            core.sizeY[0] = Integer.parseInt(t.nextToken()); 
    205196            bps = Integer.parseInt(t.nextToken()); 
    206197          } 
     
    208199            // CTR TODO - eliminate catch-all exception handling 
    209200            if (debug) exc.printStackTrace(); 
    210             channels = Integer.parseInt(t.nextToken()); 
     201            core.sizeC[0] = Integer.parseInt(t.nextToken()); 
    211202          } 
    212203        } 
     
    221212          int originX = Integer.parseInt(t.nextToken()); 
    222213          int originY = Integer.parseInt(t.nextToken()); 
    223           width = Integer.parseInt(t.nextToken()) - originX; 
    224           height = Integer.parseInt(t.nextToken()) - originY; 
     214          core.sizeX[0] = Integer.parseInt(t.nextToken()) - originX; 
     215          core.sizeY[0] = Integer.parseInt(t.nextToken()) - originY; 
    225216 
    226217          addMeta("X-coordinate of origin", new Integer(originX)); 
     
    244235        line = line.substring(11); 
    245236        StringTokenizer t = new StringTokenizer(line, " "); 
    246         width = Integer.parseInt(t.nextToken()); 
    247         height = Integer.parseInt(t.nextToken()); 
     237        core.sizeX[0] = Integer.parseInt(t.nextToken()); 
     238        core.sizeY[0] = Integer.parseInt(t.nextToken()); 
    248239        bps = Integer.parseInt(t.nextToken()); 
    249         channels = Integer.parseInt(t.nextToken()); 
     240        core.sizeC[0] = Integer.parseInt(t.nextToken()); 
    250241        while (t.hasMoreTokens()) { 
    251242          image = t.nextToken().trim(); 
     
    263254    if (bps == 0) bps = 8; 
    264255 
    265     sizeX[0] = width; 
    266     sizeY[0] = height; 
    267     sizeZ[0] = 1; 
    268     sizeC[0] = isRGB(id) ? 3 : 1; 
    269     sizeT[0] = 1; 
    270     currentOrder[0] = "XYCZT"; 
     256    core.sizeZ[0] = 1; 
     257    core.sizeT[0] = 1; 
     258    core.currentOrder[0] = "XYCZT"; 
     259    core.pixelType[0] = FormatTools.UINT8; 
    271260 
    272261    // Populate metadata store 
     
    275264    MetadataStore store = getMetadataStore(id); 
    276265 
    277     pixelType[0] = FormatTools.UINT8; 
    278266    store.setPixels( 
    279       new Integer(width), 
    280       new Integer(height), 
    281       new Integer(1), 
    282       new Integer(channels), 
    283       new Integer(1), 
    284       new Integer(pixelType[0]), 
    285       new Boolean(false), 
    286       "XYCZT", 
     267      new Integer(core.sizeX[0]), 
     268      new Integer(core.sizeY[0]), 
     269      new Integer(core.sizeZ[0]), 
     270      new Integer(core.sizeC[0]), 
     271      new Integer(core.sizeT[0]), 
     272      new Integer(core.pixelType[0]), 
     273      Boolean.FALSE,  
     274      core.currentOrder[0],  
    287275      null, 
    288276      null); 
    289     for (int i=0; i<sizeC[0]; i++) { 
     277    for (int i=0; i<core.sizeC[0]; i++) { 
    290278      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    291279    } 
    292280  } 
    293281 
    294   // -- Main method -- 
    295  
    296   public static void main(String[] args) throws FormatException, IOException { 
    297     new EPSReader().testRead(args); 
    298   } 
    299  
    300282} 
  • trunk/loci/formats/in/FluoviewReader.java

    r2535 r2557  
    6969  // -- FormatReader API methods -- 
    7070 
    71   /** Checks if the given block is a valid header for a Fluoview TIFF file. */ 
     71  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    7272  public boolean isThisType(byte[] block) { 
    7373    if (!TiffTools.isValidHeader(block)) return false; 
     
    100100  // -- IFormatHandler API methods -- 
    101101 
    102   /** 
    103    * Checks if the given string is a valid filename for an Fluoview TIFF file. 
    104    * @param open If true, the (existing) file is opened for further analysis, 
    105    *   since the file extension is insufficient to confirm that the file is in 
    106    *   Fluoview TIFF format. 
    107    */ 
     102  /* @see loci.formats.IFormatHandler#isThisType(String, boolean) */  
    108103  public boolean isThisType(String name, boolean open) { 
    109104    if (!super.isThisType(name, open)) return false; // check extension 
     
    220215    // calculate the dimension order and axis sizes 
    221216 
    222     sizeZ[0] = sizeC[0] = sizeT[0] = 1; 
    223     currentOrder[0] = "XY"; 
     217    core.sizeZ[0] = core.sizeC[0] = core.sizeT[0] = 1; 
     218    core.currentOrder[0] = "XY"; 
    224219 
    225220    for (int i=0; i<10; i++) { 
     
    232227 
    233228      if (name.equals("x")) { 
    234         sizeX[0] = size.intValue(); 
     229        core.sizeX[0] = size.intValue(); 
    235230        if (voxel != null) voxelX = voxel.floatValue(); 
    236231      } 
    237232      else if (name.equals("y")) { 
    238         sizeY[0] = size.intValue(); 
     233        core.sizeY[0] = size.intValue(); 
    239234        if (voxel != null) voxelY = voxel.floatValue(); 
    240235      } 
    241236      else if (name.equals("z") || name.equals("event")) { 
    242         sizeZ[0] *= size.intValue(); 
    243         if (currentOrder[0].indexOf("Z") == -1) currentOrder[0] += "Z"; 
     237        core.sizeZ[0] *= size.intValue(); 
     238        if (core.currentOrder[0].indexOf("Z") == -1) core.currentOrder[0] += "Z"; 
    244239        if (voxel != null) voxelZ = voxel.floatValue(); 
    245240      } 
    246241      else if (name.equals("ch") || name.equals("wavelength")) { 
    247         sizeC[0] *= size.intValue(); 
    248         if (currentOrder[0].indexOf("C") == -1) currentOrder[0] += "C"; 
     242        core.sizeC[0] *= size.intValue(); 
     243        if (core.currentOrder[0].indexOf("C") == -1) core.currentOrder[0] += "C"; 
    249244        if (voxel != null) voxelC = voxel.floatValue(); 
    250245      } 
    251246      else { 
    252         sizeT[0] *= size.intValue(); 
    253         if (currentOrder[0].indexOf("T") == -1) currentOrder[0] += "T"; 
     247        core.sizeT[0] *= size.intValue(); 
     248        if (core.currentOrder[0].indexOf("T") == -1) core.currentOrder[0] += "T"; 
    254249        if (voxel != null) voxelT = voxel.floatValue(); 
    255250      } 
    256251    } 
    257252 
    258     if (currentOrder[0].indexOf("Z") == -1) currentOrder[0] += "Z"; 
    259     if (currentOrder[0].indexOf("T") == -1) currentOrder[0] += "T"; 
    260     if (currentOrder[0].indexOf("C") == -1) currentOrder[0] += "C"; 
     253    if (core.currentOrder[0].indexOf("Z") == -1) core.currentOrder[0] += "Z"; 
     254    if (core.currentOrder[0].indexOf("T") == -1) core.currentOrder[0] += "T"; 
     255    if (core.currentOrder[0].indexOf("C") == -1) core.currentOrder[0] += "C"; 
    261256 
    262257    numImages = ifds.length; 
     
    299294  } 
    300295 
     296  /* @see loci.formats.in.BaseTiffReader#initMetadataStore() */ 
    301297  protected void initMetadataStore() { 
    302298    super.initMetadataStore(); 
     
    307303 
    308304      Double gamma = (Double) getMeta("Gamma"); 
    309       for (int i=0; i<sizeC[0]; i++) { 
     305      for (int i=0; i<core.sizeC[0]; i++) { 
    310306        store.setDisplayChannel(new Integer(i), null, null, 
    311307          gamma == null ? null : new Float(gamma.floatValue()), null); 
     
    340336  } 
    341337 
    342   // -- Main method -- 
    343  
    344   public static void main(String[] args) throws FormatException, IOException { 
    345     new FluoviewReader().testRead(args); 
    346   } 
    347  
    348338} 
  • trunk/loci/formats/in/GIFReader.java

    r2535 r2557  
    5858  private int status; 
    5959 
    60   /** Full image width. */ 
    61   private int width; 
    62  
    63   /** Full image height. */ 
    64   private int height; 
    65  
    6660  /** Global color table used. */ 
    6761  private boolean gctFlag; 
     
    144138  // -- FormatReader API methods -- 
    145139 
    146   /** Checks if the given block is a valid header for a GIF file. */ 
     140  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    147141  public boolean isThisType(byte[] block) { return false; } 
    148142 
    149   /** Determines the number of images in the given GIF file. */ 
     143  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    150144  public int getImageCount(String id) throws FormatException, IOException { 
    151145    if (!id.equals(currentId)) initFile(id); 
     
    153147  } 
    154148 
    155   /** Checks if the images in the file are RGB. */ 
     149  /* @see loci.formats.IFormatReader#isRGB(String) */  
    156150  public boolean isRGB(String id) throws FormatException, IOException { 
     151    if (!id.equals(currentId)) initFile(id);  
    157152    return !ignoreColorTable; 
    158153  } 
    159154 
    160   /** Return true if the data is in little-endian format. */ 
     155  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    161156  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    162157    return true; 
    163158  } 
    164159 
    165   /** Returns whether or not the channels are interleaved. */ 
     160  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    166161  public boolean isInterleaved(String id, int subC) 
    167162    throws FormatException, IOException 
     
    170165  } 
    171166 
    172   /** Obtains the specified image from the given GIF file as a byte array. */ 
     167  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    173168  public byte[] openBytes(String id, int no) throws FormatException, IOException 
    174169  { 
    175170    if (!id.equals(currentId)) initFile(id); 
    176     byte[] buf = new byte[width * height * sizeC[0]]; 
     171    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * core.sizeC[0]]; 
    177172    return openBytes(id, no, buf); 
    178173  } 
    179174 
     175  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    180176  public byte[] openBytes(String id, int no, byte[] buf) 
    181177    throws FormatException, IOException 
     
    185181      throw new FormatException("Invalid image number: " + no); 
    186182    } 
    187     if (buf.length < width * height * sizeC[0]) { 
     183    if (buf.length < core.sizeX[0] * core.sizeY[0] * core.sizeC[0]) { 
    188184      throw new FormatException("Buffer too small."); 
    189185    } 
     
    204200  } 
    205201 
    206   /** Obtains the specified image from the given GIF file. */ 
     202  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    207203  public BufferedImage openImage(String id, int no) 
    208204    throws FormatException, IOException 
    209205  { 
    210206    byte[] bytes = openBytes(id, no); 
    211     BufferedImage b = ImageTools.makeImage(bytes, width, height, 
    212       bytes.length / (width * height), false, 1, true); 
    213     return b; 
     207    return ImageTools.makeImage(bytes, core.sizeX[0], core.sizeY[0], 
     208      bytes.length / (core.sizeX[0] * core.sizeY[0]), false, 1, true); 
    214209  } 
    215210 
     
    220215  } 
    221216 
    222   /** Closes any open files. */ 
     217  /* @see loci.formats.IFormatReader#close() */  
    223218  public void close() throws FormatException, IOException { 
    224219    if (in != null) in.close(); 
     
    250245    status("Reading dimensions"); 
    251246 
    252     width = DataTools.read2UnsignedBytes(in, true); 
    253     height = DataTools.read2UnsignedBytes(in, true); 
     247    core.sizeX[0] = DataTools.read2UnsignedBytes(in, true); 
     248    core.sizeY[0] = DataTools.read2UnsignedBytes(in, true); 
    254249 
    255250    int packed = DataTools.readUnsignedByte(in); 
     
    267262      int i = 0; 
    268263      int j = 0; 
     264      int r, g, b;  
    269265      while (i < gctSize) { 
    270         int r = ((int) c[j++]) & 0xff; 
    271         int g = ((int) c[j++]) & 0xff; 
    272         int b = ((int) c[j++]) & 0xff; 
     266        r = ((int) c[j++]) & 0xff; 
     267        g = ((int) c[j++]) & 0xff; 
     268        b = ((int) c[j++]) & 0xff; 
    273269        gct[i++] = 0xff000000 | (r << 16) | (g << 8) | b; 
    274270      } 
     
    399395    status("Populating metadata"); 
    400396 
    401     sizeX[0] = width; 
    402     sizeY[0] = height; 
    403     sizeZ[0] = 1; 
    404     sizeC[0] = ignoreColorTable ? 1 : 3; 
    405     sizeT[0] = numFrames; 
    406     currentOrder[0] = "XYCTZ"; 
     397    core.sizeZ[0] = 1; 
     398    core.sizeC[0] = ignoreColorTable ? 1 : 3; 
     399    core.sizeT[0] = numFrames; 
     400    core.currentOrder[0] = "XYCTZ"; 
    407401 
    408402    // populate metadata store 
     
    410404    MetadataStore store = getMetadataStore(id); 
    411405 
    412     pixelType[0] = FormatTools.UINT8; 
     406    core.pixelType[0] = FormatTools.UINT8; 
    413407    store.setPixels( 
    414       new Integer(width), 
    415       new Integer(height), 
    416       new Integer(getSizeZ(id)), 
    417       new Integer(3), 
    418       new Integer(getSizeT(id)), 
    419       new Integer(pixelType[0]), 
    420       new Boolean(false), 
    421       getDimensionOrder(id), 
     408      new Integer(core.sizeX[0]), 
     409      new Integer(core.sizeY[0]), 
     410      new Integer(core.sizeZ[0]), 
     411      new Integer(core.sizeC[0]), 
     412      new Integer(core.sizeT[0]), 
     413      new Integer(core.pixelType[0]), 
     414      Boolean.FALSE, 
     415      core.currentOrder[0], 
    422416      null, 
    423417      null); 
    424     for (int i=0; i<sizeC[0]; i++) { 
     418    for (int i=0; i<core.sizeC[0]; i++) { 
    425419      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    426420    } 
     
    558552  private void setPixels() { 
    559553    // expose destination image's pixels as an int array 
    560     int[] dest = new int[width * height]; 
     554    int[] dest = new int[core.sizeX[0] * core.sizeY[0]]; 
    561555    int lastImage = -1; 
    562556 
     
    570564      if (lastImage != -1) { 
    571565        int[] prev = (int[]) images.get(lastImage); 
    572         System.arraycopy(prev, 0, dest, 0, width * height); 
     566        System.arraycopy(prev, 0, dest, 0, core.sizeX[0] * core.sizeY[0]); 
    573567      } 
    574568    } 
     
    602596      } 
    603597      line += iy; 
    604       if (line < height) { 
    605         int k = line * width; 
     598      if (line < core.sizeY[0]) { 
     599        int k = line * core.sizeX[0]; 
    606600        int dx = k + ix; // start of line in dest 
    607601        int dlim = dx + iw; // end of dest line 
    608         if ((k + width) < dlim) dlim = k + width; // past dest edge 
     602        if ((k + core.sizeX[0]) < dlim) dlim = k + core.sizeX[0]; 
    609603        int sx = i * iw; // start of line in source 
    610604        while (dx < dlim) { 
     
    619613  } 
    620614 
    621   // -- Main method -- 
    622  
    623   public static void main(String[] args) throws FormatException, IOException { 
    624     new GIFReader().testRead(args); 
    625   } 
    626  
    627615} 
  • trunk/loci/formats/in/GatanReader.java

    r2535 r2557  
    5555  private Vector pixelSizes; 
    5656 
    57   /** Dimensions -- width, height, bytes per pixel. */ 
    58   protected int[] dims = new int[3]; 
     57  private int bytesPerPixel; 
    5958 
    6059  protected int pixelDataNum = 0; 
     
    6766  // -- FormatReader API methods -- 
    6867 
    69   /** Checks if the given block is a valid header for a Gatan file. */ 
     68  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    7069  public boolean isThisType(byte[] block) { 
    7170    if (block == null) return false; 
     
    7776  } 
    7877 
    79   /** Determines the number of images in the given Gatan file. */ 
     78  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    8079  public int getImageCount(String id) throws FormatException, IOException { 
    81     if (!id.equals(currentId)) initFile(id); 
    8280    // every Gatan file has only one image 
    8381    return 1; 
    8482  } 
    8583 
    86   /** Checks if the images in the file are RGB. */ 
     84  /* @see loci.formats.IFormatReader#isRGB(String) */  
    8785  public boolean isRGB(String id) throws FormatException, IOException { 
    8886    return false; 
    8987  } 
    9088 
    91   /** Return true if the data is in little-endian format. */ 
     89  /* @see loci.formats.IFormatReader#isLittleEndian(String) */   
    9290  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    9391    if (!id.equals(currentId)) initFile(id); 
     
    9593  } 
    9694 
    97   /** Returns whether or not the channels are interleaved. */ 
     95  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */ 
    9896  public boolean isInterleaved(String id, int subC) 
    9997    throws FormatException, IOException 
     
    102100  } 
    103101 
    104   /** Obtains the specified image from the given Gatan file as a byte array. */ 
     102  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    105103  public byte[] openBytes(String id, int no) 
    106104    throws FormatException, IOException 
    107105  { 
    108106    if (!id.equals(currentId)) initFile(id); 
    109     byte[] buf = new byte[dims[0] * dims[1] * dims[2]]; 
     107    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bytesPerPixel]; 
    110108    return openBytes(id, no, buf); 
    111109  } 
    112110 
     111  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    113112  public byte[] openBytes(String id, int no, byte[] buf) 
    114113    throws FormatException, IOException 
     
    118117      throw new FormatException("Invalid image number: " + no); 
    119118    } 
    120     if (buf.length < dims[0] * dims[1] * dims[2]) { 
     119    if (buf.length < core.sizeX[0] * core.sizeY[0] * bytesPerPixel) { 
    121120      throw new FormatException("Buffer too small."); 
    122121    } 
     
    127126  } 
    128127 
    129   /** Obtains the specified image from the given Gatan file. */ 
     128  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    130129  public BufferedImage openImage(String id, int no) 
    131130    throws FormatException, IOException 
     
    137136    } 
    138137 
    139     BufferedImage b = ImageTools.makeImage(openBytes(id, no), dims[0], dims[1], 
    140       1, false, dims[2], littleEndian); 
    141     return b; 
     138    return ImageTools.makeImage(openBytes(id, no), core.sizeX[0], core.sizeY[0], 
     139      1, false, bytesPerPixel, littleEndian); 
    142140  } 
    143141 
     
    148146  } 
    149147 
    150   /** Closes any open files. */ 
     148  /* @see loci.formats.IFormatReader#close() */  
    151149  public void close() throws FormatException, IOException { 
    152150    if (in != null) in.close(); 
     
    170168    in.read(temp); 
    171169    // only support version 3 
    172     if(!isThisType(temp)) { 
     170    if (!isThisType(temp)) { 
    173171      throw new FormatException("invalid header"); 
    174172    } 
     
    178176    in.skipBytes(4); 
    179177    in.read(temp); 
    180     if (DataTools.bytesToInt(temp, littleEndian) == 1) littleEndian = true; 
     178    littleEndian = DataTools.bytesToInt(temp, littleEndian) == 1; 
    181179 
    182180    // TagGroup instance 
     
    190188    status("Populating metadata"); 
    191189 
    192     pixelType[0] = FormatTools.INT8; 
    193190    switch (datatype) { 
    194191      case 1: 
    195         pixelType[0] = FormatTools.UINT16; 
     192        core.pixelType[0] = FormatTools.UINT16; 
    196193        break; 
    197194      case 2: 
    198         pixelType[0] = FormatTools.FLOAT; 
     195        core.pixelType[0] = FormatTools.FLOAT; 
    199196        break; 
    200197      case 3: 
    201         pixelType[0] = FormatTools.FLOAT; 
     198        core.pixelType[0] = FormatTools.FLOAT; 
    202199        break; 
    203200      // there is no case 4 
    204201      case 5: 
    205         pixelType[0] = FormatTools.FLOAT; 
     202        core.pixelType[0] = FormatTools.FLOAT; 
    206203        break; 
    207204      case 6: 
    208         pixelType[0] = FormatTools.UINT8; 
     205        core.pixelType[0] = FormatTools.UINT8; 
    209206        break; 
    210207      case 7: 
    211         pixelType[0] = FormatTools.INT32; 
     208        core.pixelType[0] = FormatTools.INT32; 
    212209        break; 
    213210      case 8: 
    214         pixelType[0] = FormatTools.UINT32; 
     211        core.pixelType[0] = FormatTools.UINT32; 
    215212        break; 
    216213      case 9: 
    217         pixelType[0] = FormatTools.INT8; 
     214        core.pixelType[0] = FormatTools.INT8; 
    218215        break; 
    219216      case 10: 
    220         pixelType[0] = FormatTools.UINT16; 
     217        core.pixelType[0] = FormatTools.UINT16; 
    221218        break; 
    222219      case 11: 
    223         pixelType[0] = FormatTools.UINT32; 
     220        core.pixelType[0] = FormatTools.UINT32; 
    224221        break; 
    225222      case 12: 
    226         pixelType[0] = FormatTools.FLOAT; 
     223        core.pixelType[0] = FormatTools.FLOAT; 
    227224        break; 
    228225      case 13: 
    229         pixelType[0] = FormatTools.FLOAT; 
     226        core.pixelType[0] = FormatTools.FLOAT; 
    230227        break; 
    231228      case 14: 
    232         pixelType[0] = FormatTools.UINT8; 
     229        core.pixelType[0] = FormatTools.UINT8; 
    233230        break; 
    234231      case 23: 
    235         pixelType[0] = FormatTools.INT32; 
    236         break; 
    237     } 
    238  
    239     sizeX[0] = dims[0]; 
    240     sizeY[0] = dims[1]; 
    241     sizeZ[0] = 1; 
    242     sizeC[0] = 1; 
    243     sizeT[0] = 1; 
    244     currentOrder[0] = "XYZTC"; 
     232        core.pixelType[0] = FormatTools.INT32; 
     233        break; 
     234      default: core.pixelType[0] = FormatTools.INT8;  
     235    } 
     236 
     237    core.sizeZ[0] = 1; 
     238    core.sizeC[0] = 1; 
     239    core.sizeT[0] = 1; 
     240    core.currentOrder[0] = "XYZTC"; 
    245241 
    246242    // The metadata store we're working with. 
     
    248244 
    249245    store.setPixels( 
    250       new Integer(dims[0]), // SizeX 
    251       new Integer(dims[1]), // SizeY 
    252       new Integer(1), // SizeZ 
    253       new Integer(1), // SizeC 
    254       new Integer(1), // SizeT 
    255       new Integer(pixelType[0]), // PixelType 
     246      new Integer(core.sizeX[0]), // SizeX 
     247      new Integer(core.sizeY[0]), // SizeY 
     248      new Integer(core.sizeZ[0]), // SizeZ 
     249      new Integer(core.sizeC[0]), // SizeC 
     250      new Integer(core.sizeT[0]), // SizeT 
     251      new Integer(core.pixelType[0]), // PixelType 
    256252      new Boolean(!littleEndian), // BigEndian 
    257       "XYZTC", // DimensionOrder 
     253      core.currentOrder[0], // DimensionOrder 
    258254      null, // Use image index 0 
    259255      null); // Use pixels index 0 
     
    276272 
    277273    String gamma = (String) getMeta("Gamma"); 
    278     for (int i=0; i<sizeC[0]; i++) { 
     274    for (int i=0; i<core.sizeC[0]; i++) { 
    279275      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    280276      store.setDisplayChannel(new Integer(i), null, null, 
     
    353349          } 
    354350          if (parent.equals("Dimensions")) { 
    355             if (i == 0) dims[0] = Integer.parseInt(data); 
    356             else if (i == 1) dims[1] = Integer.parseInt(data); 
     351            if (i == 0) core.sizeX[0] = Integer.parseInt(data); 
     352            else if (i == 1) core.sizeY[0] = Integer.parseInt(data); 
    357353          } 
    358354          if (labelString.equals("PixelDepth")) { 
    359             dims[2] = Integer.parseInt(data); 
     355            bytesPerPixel = Integer.parseInt(data); 
    360356          } 
    361357          else if (labelString.equals("Scale")) { 
     
    526522  } 
    527523 
    528   // -- Main method -- 
    529  
    530   public static void main(String[] args) throws FormatException, IOException { 
    531     new GatanReader().testRead(args); 
    532   } 
    533  
    534524} 
  • trunk/loci/formats/in/GelReader.java

    r2377 r2557  
    5656  // -- FormatReader API methods -- 
    5757 
    58   /** Checks if the given block is a valid header for a GEL TIFF file. */ 
     58  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    5959  public boolean isThisType(byte[] block) { return false; } 
    6060 
     
    9696    addMeta("File units", units == null ? "unknown" : units); 
    9797 
    98     sizeT[series] = numImages; 
     98    core.sizeT[series] = numImages; 
    9999 
    100100    MetadataStore store = getMetadataStore(currentId); 
     
    103103  } 
    104104 
    105   // -- Main method -- 
    106  
    107   public static void main(String[] args) throws FormatException, IOException { 
    108     new GelReader().testRead(args); 
    109   } 
    110  
    111105} 
  • trunk/loci/formats/in/ICSReader.java

    r2535 r2557  
    7979  protected int numImages; 
    8080 
    81   /** 
    82    * Dimensions in the following order: 
    83    * 1) bits per pixel, 
    84    * 2) width, 
    85    * 3) height, 
    86    * 4) z, 
    87    * 5) channels, 
    88    * 6) timepoints. 
    89    */ 
    90   protected int[] dimensions = new int[6]; 
     81  /** Number of bits per pixel. */ 
     82  protected int bitsPerPixel; 
    9183 
    9284  /** Flag indicating whether current file is v2.0. */ 
     
    9587  /** Image data. */ 
    9688  protected byte[] data; 
    97  
    98   /** Dimension order. */ 
    99   private String order; 
    10089 
    10190  /** Flag indicating that the images are RGB. */ 
     
    111100  // -- FormatReader API methods -- 
    112101 
    113   /** Checks if the given block is a valid header for an ICS file. */ 
     102  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    114103  public boolean isThisType(byte[] block) { 
    115104    return false; 
    116105  } 
    117106 
    118   /** Determines the number of images in the given ICS file. */ 
     107  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    119108  public int getImageCount(String id) throws FormatException, IOException { 
    120109    if (!id.equals(currentIdsId) && !id.equals(currentIcsId)) initFile(id); 
    121110    if (numImages == 1) return 1; 
    122     return numImages / (rgb ? dimensions[4] : 1); 
    123   } 
    124  
    125   /** Checks if the images in the file are RGB. */ 
     111    return numImages / (rgb ? core.sizeC[0] : 1); 
     112  } 
     113 
     114  /* @see loci.formats.IFormatReader#isRGB(String) */  
    126115  public boolean isRGB(String id) throws FormatException, IOException { 
    127116    if (!id.equals(currentIdsId) && !id.equals(currentIcsId)) initFile(id); 
    128     return rgb && sizeC[0] > 1; 
    129   } 
    130  
    131   /** Return true if the data is in little-endian format. */ 
     117    return rgb && core.sizeC[0] > 1; 
     118  } 
     119 
     120  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    132121  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    133122    if (!id.equals(currentIdsId) && !id.equals(currentIcsId)) initFile(id); 
     
    135124  } 
    136125 
    137   /** Returns whether or not the channels are interleaved. */ 
     126  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */ 
    138127  public boolean isInterleaved(String id, int subC) 
    139128    throws FormatException, IOException 
     
    143132  } 
    144133 
    145   /** Obtains the specified image from the given ICS file, as a byte array. */ 
     134  /* @see loci.formats.IFormatReader#openBytes(String, int) */ 
    146135  public byte[] openBytes(String id, int no) 
    147136    throws FormatException, IOException 
    148137  { 
    149138    if (!id.equals(currentId)) initFile(id); 
    150     byte[] buf = new byte[sizeX[0] * sizeY[0] * (dimensions[0] / 8) * 
     139    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8) * 
    151140      getRGBChannelCount(id)]; 
    152141    return openBytes(id, no, buf); 
    153142  } 
    154143 
     144  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    155145  public byte[] openBytes(String id, int no, byte[] buf) 
    156146    throws FormatException, IOException 
     
    160150      throw new FormatException("Invalid image number: " + no); 
    161151    } 
    162     if (buf.length < sizeX[0] * sizeY[0] * (dimensions[0] / 8) * 
     152    if (buf.length < core.sizeX[0] * core.sizeY[0] * (bitsPerPixel / 8) * 
    163153      getRGBChannelCount(id)) 
    164154    { 
     
    166156    } 
    167157 
    168     int bpp = dimensions[0] / 8; 
    169  
    170     int len = sizeX[0] * sizeY[0] * bpp * getRGBChannelCount(id); 
     158    int bpp = bitsPerPixel / 8; 
     159 
     160    int len = core.sizeX[0] * core.sizeY[0] * bpp * getRGBChannelCount(id); 
    171161    int offset = len * no; 
    172     if (!rgb && sizeC[0] > 4) { 
     162    if (!rgb && core.sizeC[0] > 4) { 
    173163      int pt = 0; 
    174       for (int i=no*bpp; i<data.length; i+=sizeC[0]*bpp) { 
     164      for (int i=no*bpp; i<data.length; i+=core.sizeC[0]*bpp) { 
    175165        System.arraycopy(data, i, buf, pt, bpp); 
    176166        pt += bpp; 
     
    181171    // if it's version two, we need to flip the plane upside down 
    182172    if (versionTwo) { 
    183       int scanline = sizeX[0] * bpp * sizeC[0]; 
    184       for (int y=0; y<sizeY[0]; y++) { 
     173      int scanline = core.sizeX[0] * bpp * core.sizeC[0]; 
     174      for (int y=0; y<core.sizeY[0]; y++) { 
    185175        for (int x=0; x<scanline; x++) { 
    186176          byte bottom = buf[y*scanline + x]; 
    187           buf[y*scanline + x] = buf[(sizeY[0] - y - 1)*scanline + x]; 
    188           buf[(sizeY[0] - y - 1)*scanline + x] = bottom; 
     177          buf[y*scanline + x] = buf[(core.sizeY[0] - y - 1)*scanline + x]; 
     178          buf[(core.sizeY[0] - y - 1)*scanline + x] = bottom; 
    189179        } 
    190180      } 
     
    193183  } 
    194184 
    195   /** Obtains the specified image from the given ICS file. */ 
     185  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    196186  public BufferedImage openImage(String id, int no) 
    197187    throws FormatException, IOException 
     
    200190 
    201191    byte[] plane = openBytes(id, no); 
    202     int width = dimensions[1]; 
    203     int height = dimensions[2]; 
    204     int channels = rgb ? dimensions[4] : 1; 
    205  
    206     int bytes = dimensions[0] / 8; 
     192    int channels = rgb ? core.sizeC[0] : 1; 
     193 
     194    int bytes = bitsPerPixel / 8; 
    207195 
    208196    if (bytes == 4) { 
    209       float[] f = new float[width * height * channels]; 
     197      float[] f = new float[core.sizeX[0] * core.sizeY[0] * channels]; 
    210198      int pt = 0; 
    211199      for (int i=0; i<f.length; i++) { 
     
    216204      if (normalizeData) f = DataTools.normalizeFloats(f); 
    217205 
    218       BufferedImage b = ImageTools.makeImage(f, width, height, channels, true); 
    219       return b; 
    220     } 
    221  
    222     BufferedImage b = ImageTools.makeImage(plane, width, height, channels, true, 
    223       bytes, littleEndian); 
    224     return b; 
     206      return ImageTools.makeImage(f, core.sizeX[0], core.sizeY[0],  
     207        channels, true); 
     208    } 
     209 
     210    return ImageTools.makeImage(plane, core.sizeX[0], core.sizeY[0], channels,  
     211      true, bytes, littleEndian); 
    225212  } 
    226213 
     
    240227  } 
    241228 
    242   /** Closes any open files. */ 
     229  /* @see loci.formats.IFormatReader#close() */  
    243230  public void close() throws FormatException, IOException { 
    244231    if (idsIn != null) idsIn.close(); 
     
    355342    StringTokenizer t2 = new StringTokenizer(ord); 
    356343 
    357     for(int i=0; i<dimensions.length; i++) { 
    358       dimensions[i] = 1; 
    359     } 
    360  
    361344    rgb = ord.indexOf("ch") >= 0 && ord.indexOf("ch") < ord.indexOf("x"); 
    362345 
     
    367350      orderToken = t2.nextToken().trim(); 
    368351      if (orderToken.equals("bits")) { 
    369         dimensions[0] = Integer.parseInt(imageToken); 
     352        bitsPerPixel = Integer.parseInt(imageToken); 
    370353      } 
    371354      else if(orderToken.equals("x")) { 
    372         dimensions[1] = Integer.parseInt(imageToken); 
     355        core.sizeX[0] = Integer.parseInt(imageToken); 
    373356      } 
    374357      else if(orderToken.equals("y")) { 
    375         dimensions[2] = Integer.parseInt(imageToken); 
     358        core.sizeY[0] = Integer.parseInt(imageToken); 
    376359      } 
    377360      else if(orderToken.equals("z")) { 
    378         dimensions[3] = Integer.parseInt(imageToken); 
     361        core.sizeZ[0] = Integer.parseInt(imageToken); 
    379362      } 
    380363      else if(orderToken.equals("ch")) { 
    381         dimensions[4] = Integer.parseInt(imageToken); 
    382         if (dimensions[4] > 4) rgb = false; 
     364        core.sizeC[0] = Integer.parseInt(imageToken); 
     365        if (core.sizeC[0] > 4) rgb = false; 
    383366      } 
    384367      else { 
    385         dimensions[5] = Integer.parseInt(imageToken); 
    386       } 
    387     } 
    388  
    389     int width = dimensions[1]; 
    390     int height = dimensions[2]; 
    391  
    392     numImages = dimensions[3] * dimensions[4] * dimensions[5]; 
     368        core.sizeT[0] = Integer.parseInt(imageToken); 
     369      } 
     370    } 
     371 
     372    numImages = core.sizeZ[0] * core.sizeC[0] * core.sizeT[0]; 
    393373    if (numImages == 0) numImages++; 
    394374 
     
    416396    // extra check is because some of our datasets are labeled as 'gzip', and 
    417397    // have a valid GZIP header, but are actually uncompressed 
    418     if (gzip && 
    419       ((data.length / (numImages) < (width * height * dimensions[0]/8)))) 
     398    if (gzip && ((data.length / (numImages) <  
     399      (core.sizeX[0] * core.sizeY[0] * bitsPerPixel / 8)))) 
    420400    { 
    421401      status("Decompressing pixel data");  
     
    464444    if (o.indexOf("C") == -1) o = o + "C"; 
    465445 
    466     int bitsPerPixel = 
    467       Integer.parseInt((String) getMeta("layout significant_bits")); 
    468446    String fmt = (String) getMeta("representation format"); 
    469447    String sign = (String) getMeta("representation sign"); 
     
    471449    if (bitsPerPixel < 32) littleEndian = !littleEndian; 
    472450 
    473     if (fmt.equals("real")) pixelType[0] = FormatTools.FLOAT; 
     451    if (fmt.equals("real")) core.pixelType[0] = FormatTools.FLOAT; 
    474452    else if (fmt.equals("integer")) { 
    475453      while (bitsPerPixel % 8 != 0) bitsPerPixel++; 
     
    478456      switch (bitsPerPixel) { 
    479457        case 8: 
    480           pixelType[0] = FormatTools.UINT8; 
     458          core.pixelType[0] = FormatTools.UINT8; 
    481459          break; 
    482460        case 16: 
    483           pixelType[0] = FormatTools.UINT16; 
     461          core.pixelType[0] = FormatTools.UINT16; 
    484462          break; 
    485463        case 32: 
    486           pixelType[0] = FormatTools.UINT32; 
     464          core.pixelType[0] = FormatTools.UINT32; 
    487465          break; 
    488466      } 
     
    492470    } 
    493471 
    494     order = o; 
    495  
    496     sizeX[0] = dimensions[1]; 
    497     sizeY[0] = dimensions[2]; 
    498     sizeZ[0] = dimensions[3]; 
    499     sizeC[0] = dimensions[4]; 
    500     sizeT[0] = dimensions[5]; 
    501     currentOrder[0] = order.trim(); 
     472    core.currentOrder[0] = o.trim(); 
    502473 
    503474    store.setPixels( 
    504       new Integer(dimensions[1]), // SizeX 
    505       new Integer(dimensions[2]), // SizeY 
    506       new Integer(dimensions[3]), // SizeZ 
    507       new Integer(dimensions[4]), // SizeC 
    508       new Integer(dimensions[5]), // SizeT 
    509       new Integer(pixelType[0]), // PixelType 
     475      new Integer(core.sizeX[0]), // SizeX 
     476      new Integer(core.sizeY[0]), // SizeY 
     477      new Integer(core.sizeZ[0]), // SizeZ 
     478      new Integer(core.sizeC[0]), // SizeC 
     479      new Integer(core.sizeT[0]), // SizeT 
     480      new Integer(core.pixelType[0]), // PixelType 
    510481      new Boolean(!littleEndian), // BigEndian 
    511       order.trim(), // DimensionOrder 
     482      core.currentOrder[0], // DimensionOrder 
    512483      null, // Use image index 0 
    513484      null); // Use pixels index 0 
     
    535506    String em = (String) getMeta("sensor s_params LambdaEm"); 
    536507    String ex = (String) getMeta("sensor s_params LambdaEx"); 
    537     int[] emWave = new int[sizeC[0]]; 
    538     int[] exWave = new int[sizeC[0]]; 
     508    int[] emWave = new int[core.sizeC[0]]; 
     509    int[] exWave = new int[core.sizeC[0]]; 
    539510    if (em != null) { 
    540511      StringTokenizer emTokens = new StringTokenizer(em); 
    541       for (int i=0; i<sizeC[0]; i++) { 
     512      for (int i=0; i<core.sizeC[0]; i++) { 
    542513        emWave[i] = (int) Float.parseFloat(emTokens.nextToken().trim()); 
    543514      } 
     
    545516    if (ex != null) { 
    546517      StringTokenizer exTokens = new StringTokenizer(ex); 
    547       for (int i=0; i<sizeC[0]; i++) { 
     518      for (int i=0; i<core.sizeC[0]; i++) { 
    548519        exWave[i] = (int) Float.parseFloat(exTokens.nextToken().trim()); 
    549520      } 
    550521    } 
    551522 
    552     for (int i=0; i<sizeC[0]; i++) { 
     523    for (int i=0; i<core.sizeC[0]; i++) { 
    553524      store.setLogicalChannel(i, null, null, new Integer(emWave[i]), 
    554525        new Integer(exWave[i]), null, null, null); 
     
    556527  } 
    557528 
    558   // -- Main method -- 
    559  
    560   public static void main(String[] args) throws FormatException, IOException { 
    561     new ICSReader().testRead(args); 
    562   } 
    563  
    564529} 
  • trunk/loci/formats/in/IPLabReader.java

    r2535 r2557  
    4848  private int numImages; 
    4949 
    50   /** Image width. */ 
    51   private int width; 
    52  
    53   /** Image height. */ 
    54   private int height; 
    55  
    5650  /** Bytes per pixel. */ 
    5751  private int bps; 
    5852 
    59   /** Number of channels. */ 
    60   private int c; 
    61  
    6253  /** Total number of pixel bytes. */ 
    6354  private int dataSize; 
    6455 
    65   /** Dimension order. */ 
    66   private String order; 
    67  
    6856  // -- Constructor -- 
    6957 
     
    7361  // -- FormatReader API methods -- 
    7462 
    75   /** Checks if the given block is a valid header for an IPLab file. */ 
     63  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    7664  public boolean isThisType(byte[] block) { 
    7765    if (block.length < 12) return false; // block length too short 
     
    8775  } 
    8876 
    89   /** Determines the number of images in the given IPLab file. */ 
     77  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    9078  public int getImageCount(String id) throws FormatException, IOException { 
    9179    if (!id.equals(currentId)) initFile(id); 
     
    9381  } 
    9482 
    95   /** Checks if the images in the file are RGB. */ 
     83  /* @see loci.formats.IFormatReader#isRGB(String) */  
    9684  public boolean isRGB(String id) throws FormatException, IOException { 
    9785    if (!id.equals(currentId)) initFile(id); 
    98     return c > 1; 
    99   } 
    100  
    101   /** Return true if the data is in little-endian format. */ 
     86    return core.sizeC[0] > 1; 
     87  } 
     88 
     89  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    10290  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    10391    if (!id.equals(currentId)) initFile(id); 
     
    10593  } 
    10694 
    107   /** Returns whether or not the channels are interleaved. */ 
     95  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    10896  public boolean isInterleaved(String id, int subC) 
    10997    throws FormatException, IOException 
     
    112100  } 
    113101 
    114   /** Obtains the specified image from the given IPLab file as a byte array. */ 
     102  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    115103  public byte[] openBytes(String id, int no) 
    116104    throws FormatException, IOException 
    117105  { 
    118106    if (!id.equals(currentId)) initFile(id); 
    119     byte[] buf = new byte[width * height * bps * c]; 
     107    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * bps * core.sizeC[0]]; 
    120108    return openBytes(id, no, buf); 
    121109  } 
    122110 
     111  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    123112  public byte[] openBytes(String id, int no, byte[] buf) 
    124113    throws FormatException, IOException 
     
    129118    } 
    130119 
    131     int numPixels = width * height * c; 
     120    int numPixels = core.sizeX[0] * core.sizeY[0] * core.sizeC[0]; 
    132121    if (buf.length < numPixels * bps) { 
    133122      throw new FormatException("Buffer too small."); 
    134123    } 
    135     in.seek(numPixels * bps * (no / c) + 44); 
     124    in.seek(numPixels * bps * (no / core.sizeC[0]) + 44); 
    136125 
    137126    in.read(buf); 
     
    139128  } 
    140129 
    141   /** Obtains the specified image from the given IPLab file. */ 
     130  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    142131  public BufferedImage openImage(String id, int no) 
    143132    throws FormatException, IOException 
    144133  { 
    145     BufferedImage b = ImageTools.makeImage(openBytes(id, no), width, height, 
    146       !isRGB(id) ? 1 : c, false, bps, littleEndian); 
    147     return b; 
     134    return ImageTools.makeImage(openBytes(id, no), core.sizeX[0], core.sizeY[0], 
     135      isRGB(id) ? core.sizeC[0] : 1, false, bps, littleEndian); 
    148136  } 
    149137 
     
    154142  } 
    155143 
    156   /** Closes any open files. */ 
     144  /* @see loci.formats.IFormatReader#close() */  
    157145  public void close() throws FormatException, IOException { 
    158146    if (in != null) in.close(); 
     
    179167 
    180168    dataSize = in.readInt() - 28; 
    181     width = in.readInt(); 
    182     height = in.readInt(); 
    183     c = in.readInt(); 
    184     int zDepth = in.readInt(); 
    185     int tDepth = in.readInt(); 
     169    core.sizeX[0] = in.readInt(); 
     170    core.sizeY[0] = in.readInt(); 
     171    core.sizeC[0] = in.readInt(); 
     172    core.sizeZ[0] = in.readInt(); 
     173    core.sizeT[0] = in.readInt(); 
    186174    int filePixelType = in.readInt(); 
    187175 
    188     numImages = zDepth * tDepth; 
    189  
    190     addMeta("Width", new Long(width)); 
    191     addMeta("Height", new Long(height)); 
    192     addMeta("Channels", new Long(c)); 
    193     addMeta("ZDepth", new Long(zDepth)); 
    194     addMeta("TDepth", new Long(tDepth)); 
     176    numImages = core.sizeZ[0] * core.sizeT[0]; 
     177 
     178    addMeta("Width", new Long(core.sizeX[0])); 
     179    addMeta("Height", new Long(core.sizeY[0])); 
     180    addMeta("Channels", new Long(core.sizeC[0])); 
     181    addMeta("ZDepth", new Long(core.sizeZ[0])); 
     182    addMeta("TDepth", new Long(core.sizeT[0])); 
    195183 
    196184    String ptype; 
     
    199187      case 0: 
    200188        ptype = "8 bit unsigned"; 
    201         pixelType[0] = FormatTools.UINT8; 
     189        core.pixelType[0] = FormatTools.UINT8; 
    202190        bps = 1; 
    203191        break; 
    204192      case 1: 
    205193        ptype = "16 bit signed short"; 
    206         pixelType[0] = FormatTools.INT16; 
     194        core.pixelType[0] = FormatTools.INT16; 
    207195        bps = 2; 
    208196        break; 
    209197      case 2: 
    210198        ptype = "16 bit unsigned short"; 
    211         pixelType[0] = FormatTools.UINT16; 
     199        core.pixelType[0] = FormatTools.UINT16; 
    212200        bps = 2; 
    213201        break; 
    214202      case 3: 
    215203        ptype = "32 bit signed long"; 
    216         pixelType[0] = FormatTools.INT32; 
     204        core.pixelType[0] = FormatTools.INT32; 
    217205        bps = 4; 
    218206        break; 
    219207      case 4: 
    220208        ptype = "32 bit single-precision float"; 
    221         pixelType[0] = FormatTools.FLOAT; 
     209        core.pixelType[0] = FormatTools.FLOAT; 
    222210        bps = 4; 
    223211        break; 
    224212      case 5: 
    225213        ptype = "Color24"; 
    226         pixelType[0] = FormatTools.INT32; 
     214        core.pixelType[0] = FormatTools.INT32; 
    227215        bps = 1; 
    228216        break; 
    229217      case 6: 
    230218        ptype = "Color48"; 
    231         pixelType[0] = FormatTools.INT32; 
     219        core.pixelType[0] = FormatTools.INT32; 
    232220        bps = 2; 
    233221        break; 
    234222      case 10: 
    235223        ptype = "64 bit double-precision float"; 
    236         pixelType[0] = FormatTools.DOUBLE; 
     224        core.pixelType[0] = FormatTools.DOUBLE; 
    237225        bps = 8; 
    238226        break; 
     
    244232    in.skipBytes(dataSize); 
    245233 
    246     order = "XY"; 
    247     if (c > 1) order += "CZT"; 
    248     else order += "ZTC"; 
     234    core.currentOrder[0] = "XY"; 
     235    if (core.sizeC[0] > 1) core.currentOrder[0] += "CZT"; 
     236    else core.currentOrder[0] += "ZTC"; 
    249237 
    250238    // The metadata store we're working with. 
     
    252240 
    253241    store.setPixels( 
    254       new Integer((int) width), // SizeX 
    255       new Integer((int) height), // SizeY 
    256       new Integer((int) zDepth), // SizeZ 
    257       new Integer((int) c), // SizeC 
    258       new Integer((int) tDepth), // SizeT 
    259       new Integer(pixelType[0]), // PixelType 
     242      new Integer(core.sizeX[0]), // SizeX 
     243      new Integer(core.sizeY[0]), // SizeY 
     244      new Integer(core.sizeZ[0]), // SizeZ 
     245      new Integer(core.sizeC[0]), // SizeC 
     246      new Integer(core.sizeT[0]), // SizeT 
     247      new Integer(core.pixelType[0]), // PixelType 
    260248      new Boolean(!littleEndian), // BigEndian 
    261       order, // DimensionOrder 
     249      core.currentOrder[0], // DimensionOrder 
    262250      null, // Use image index 0 
    263251      null); // Use pixels index 0 
    264252 
    265     for (int i=0; i<sizeC[0]; i++) { 
     253    for (int i=0; i<core.sizeC[0]; i++) { 
    266254      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    267255    } 
     
    335323        // error checking 
    336324 
    337         if (size != (44 * c)) { 
     325        if (size != (44 * core.sizeC[0])) { 
    338326          throw new FormatException("Bad normalization settings"); 
    339327        } 
    340328 
    341         for (int i=0; i<c; i++) { 
     329        for (int i=0; i<core.sizeC[0]; i++) { 
    342330          long source = in.readInt(); 
    343331 
     
    383371            new Double(max), null); 
    384372 
    385           store.setDisplayChannel(new Integer(c), new Double(black), 
     373          store.setDisplayChannel(new Integer(core.sizeC[0]), new Double(black), 
    386374            new Double(white), new Float(gamma), null); 
    387375        } 
     
    482470      } 
    483471    } 
    484  
    485     sizeX[0] = width; 
    486     sizeY[0] = height; 
    487     sizeZ[0] = (int) ((Long) getMeta("ZDepth")).longValue(); 
    488     sizeC[0] = c; 
    489     sizeT[0] = (int) ((Long) getMeta("TDepth")).longValue(); 
    490     currentOrder[0] = order; 
    491  
    492   } 
    493  
    494   // -- Main method -- 
    495  
    496   public static void main(String[] args) throws FormatException, IOException { 
    497     new IPLabReader().testRead(args); 
    498472  } 
    499473 
  • trunk/loci/formats/in/IPWReader.java

    r2535 r2557  
    7272  private boolean rgb; 
    7373  private boolean little; 
    74   private int totalBytes= 0; 
    7574 
    7675  // -- Constructor -- 
     
    8180  // -- FormatReader API methods -- 
    8281 
    83   /** Checks if the given block is a valid header for an IPW file. */ 
     82  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    8483  public boolean isThisType(byte[] block) { 
    8584    // all of our samples begin with 0xd0cf11e0 
     
    8887  } 
    8988 
    90   /** Determines the number of images in the given IPW file. */ 
     89  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    9190  public int getImageCount(String id) throws FormatException, IOException { 
    9291    if (!id.equals(currentId)) initFile(id); 
     
    9493  } 
    9594 
    96   /** Checks if the images in the file are RGB. */ 
     95  /* @see loci.formats.IFormatReader#isRGB(String) */  
    9796  public boolean isRGB(String id) throws FormatException, IOException { 
    9897    if (!id.equals(currentId)) initFile(id); 
     
    10099  } 
    101100 
    102   /** Return true if the data is in little-endian format. */ 
     101  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    103102  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    104103    if (!id.equals(currentId)) initFile(id); 
     
    106105  } 
    107106 
    108   /** Obtains the specified image from the given IPW file, as a byte array. */ 
     107  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    109108  public byte[] openBytes(String id, int no) 
    110109    throws FormatException, IOException 
     
    113112    int c = getRGBChannelCount(id); 
    114113    if (c == 2) c++; 
    115     byte[] buf = new byte[sizeX[0] * sizeY[0] * c * 
    116       FormatTools.getBytesPerPixel(pixelType[0])]; 
     114    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0] * c * 
     115      FormatTools.getBytesPerPixel(core.pixelType[0])]; 
    117116    return openBytes(id, no, buf); 
    118117  } 
    119118 
     119  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    120120  public byte[] openBytes(String id, int no, byte[] buf) 
    121121    throws FormatException, IOException 
     
    163163  } 
    164164 
    165   /** Obtains the specified image from the given IPW file. */ 
     165  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    166166  public BufferedImage openImage(String id, int no) 
    167167    throws FormatException, IOException 
     
    173173 
    174174    byte[] b = openBytes(id, no); 
    175     int bytes = b.length / (sizeX[0] * sizeY[0]); 
    176     BufferedImage bi = ImageTools.makeImage(b, sizeX[0], sizeY[0], 
     175    int bytes = b.length / (core.sizeX[0] * core.sizeY[0]); 
     176    return ImageTools.makeImage(b, core.sizeX[0], core.sizeY[0], 
    177177      bytes == 3 ? 3 : 1, false, bytes == 3 ? 1 : bytes, little); 
    178     return bi; 
    179178  } 
    180179 
     
    185184  } 
    186185 
    187   /** Closes any open files. */ 
     186  /* @see loci.formats.IFormatReader#close() */  
    188187  public void close() throws FormatException, IOException { 
    189188    if (in != null) in.close(); 
     
    230229  // -- Internal BaseTiffReader API methods -- 
    231230 
    232   /** Initialize metadata hashtable and OME-XML structure. */ 
     231  /* @see loci.formats.in.BaseTiffReader#initMetadata(String) */  
    233232  public void initMetadata(String id) 
    234233    throws FormatException, IOException 
     
    284283 
    285284    // parse the description to get channels/slices/times where applicable 
    286     // basically the same as in ImageProSeqForm 
     285    // basically the same as in SEQReader  
    287286    if (description != null) { 
    288287      StringTokenizer tokenizer = new StringTokenizer(description, "\n"); 
     
    304303    addMeta("Version", new String(header).trim()); 
    305304 
    306     Integer tSize = Integer.valueOf((String) getMeta("slices")); 
    307     Integer cSize = Integer.valueOf((String) getMeta("channels")); 
    308     Integer zSize = Integer.valueOf(getMeta("frames").toString()); 
    309  
    310305    Hashtable h = ifds[0]; 
    311     sizeX[0] = TiffTools.getIFDIntValue(h, TiffTools.IMAGE_WIDTH); 
    312     sizeY[0] = TiffTools.getIFDIntValue(h, TiffTools.IMAGE_LENGTH); 
    313     sizeZ[0] = Integer.valueOf(getMeta("frames").toString()).intValue(); 
    314     sizeC[0] = Integer.parseInt((String) getMeta("channels")); 
    315     sizeT[0] = Integer.parseInt((String) getMeta("slices")); 
    316     currentOrder[0] = "XY"; 
    317  
    318     if (rgb) sizeC[0] *= 3; 
    319     if (ignoreColorTable) sizeC[0] = 1; 
     306    core.sizeX[0] = TiffTools.getIFDIntValue(h, TiffTools.IMAGE_WIDTH); 
     307    core.sizeY[0] = TiffTools.getIFDIntValue(h, TiffTools.IMAGE_LENGTH); 
     308    core.sizeZ[0] = Integer.parseInt((String) getMeta("frames")); 
     309    core.sizeC[0] = Integer.parseInt((String) getMeta("channels")); 
     310    core.sizeT[0] = Integer.parseInt((String) getMeta("slices")); 
     311    core.currentOrder[0] = "XY"; 
     312 
     313    if (rgb) core.sizeC[0] *= 3; 
     314    if (ignoreColorTable) core.sizeC[0] = 1; 
    320315 
    321316    int maxNdx = 0, max = 0; 
    322     int[] dims = {sizeZ[0], sizeC[0], sizeT[0]}; 
     317    int[] dims = {core.sizeZ[0], core.sizeC[0], core.sizeT[0]}; 
    323318    String[] axes = {"Z", "C", "T"}; 
    324319 
     
    330325    } 
    331326 
    332     currentOrder[0] += axes[maxNdx]; 
     327    core.currentOrder[0] += axes[maxNdx]; 
    333328 
    334329    if (maxNdx != 1) { 
    335       if (sizeC[0] > 1) { 
    336         currentOrder[0] += "C"; 
    337         currentOrder[0] += (maxNdx == 0 ? axes[2] : axes[0]); 
    338       } 
    339       else currentOrder[0] += (maxNdx == 0 ? axes[2] : axes[0]) + "C"; 
     330      if (core.sizeC[0] > 1) { 
     331        core.currentOrder[0] += "C"; 
     332        core.currentOrder[0] += (maxNdx == 0 ? axes[2] : axes[0]); 
     333      } 
     334      else core.currentOrder[0] += (maxNdx == 0 ? axes[2] : axes[0]) + "C"; 
    340335    } 
    341336    else { 
    342       if (sizeZ[0] > sizeT[0]) currentOrder[0] += "ZT"; 
    343       else currentOrder[0] += "TZ"; 
    344     } 
     337      if (core.sizeZ[0] > core.sizeT[0]) core.currentOrder[0] += "ZT"; 
     338      else core.currentOrder[0] += "TZ"; 
     339    } 
     340 
     341    // TODO : look into removing this logic, as it appears to be copied directly 
     342    // from BaseTiffReader 
    345343 
    346344    int bitsPerSample = TiffTools.getIFDIntValue(ifds[0], 
     
    351349    if (bitsPerSample == 24 || bitsPerSample == 48) bitsPerSample /= 3; 
    352350 
    353     pixelType[0] = FormatTools.UINT8; 
    354  
    355     if (bitFormat == 3) pixelType[0] = FormatTools.FLOAT; 
     351    core.pixelType[0] = FormatTools.UINT8; 
     352 
     353    if (bitFormat == 3) core.pixelType[0] = FormatTools.FLOAT; 
    356354    else if (bitFormat == 2) { 
    357355      switch (bitsPerSample) { 
    358356        case 8: 
    359           pixelType[0] = FormatTools.INT8; 
     357          core.pixelType[0] = FormatTools.INT8; 
    360358          break; 
    361359        case 16: 
    362           pixelType[0] = FormatTools.INT16; 
     360          core.pixelType[0] = FormatTools.INT16; 
    363361          break; 
    364362        case 32: 
    365           pixelType[0] = FormatTools.INT32; 
     363          core.pixelType[0] = FormatTools.INT32; 
    366364          break; 
    367365      } 
     
    370368      switch (bitsPerSample) { 
    371369        case 8: 
    372           pixelType[0] = FormatTools.UINT8; 
     370          core.pixelType[0] = FormatTools.UINT8; 
    373371          break; 
    374372        case 16: 
    375           pixelType[0] = FormatTools.UINT16; 
     373          core.pixelType[0] = FormatTools.UINT16; 
    376374          break; 
    377375        case 32: 
    378           pixelType[0] = FormatTools.UINT32; 
     376          core.pixelType[0] = FormatTools.UINT32; 
    379377          break; 
    380378      } 
     
    384382    MetadataStore store = getMetadataStore(id); 
    385383 
    386     store.setPixels(null, null, zSize, cSize, tSize, new Integer(pixelType[0]), 
    387       new Boolean(!isLittleEndian(id)), getDimensionOrder(id), null, null); 
     384    store.setPixels(null, null, new Integer(core.sizeZ[0]),  
     385      new Integer(core.sizeC[0]), new Integer(core.sizeT[0]),  
     386      new Integer(core.pixelType[0]), new Boolean(!isLittleEndian(id)),  
     387      core.currentOrder[0], null, null); 
    388388    store.setImage(null, null, (String) getMeta("Version"), null); 
    389     for (int i=0; i<sizeC[0]; i++) { 
     389    for (int i=0; i<core.sizeC[0]; i++) { 
    390390      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    391391    } 
     
    428428 
    429429        boolean isContents = entryName.equals("CONTENTS"); 
    430         totalBytes += data.length + entryName.length(); 
    431430 
    432431        if (isContents) { 
     
    483482  } 
    484483 
    485   // -- Main method -- 
    486  
    487   public static void main(String[] args) throws FormatException, IOException { 
    488     new IPWReader().testRead(args); 
    489   } 
    490  
    491484} 
  • trunk/loci/formats/in/ImageIOReader.java

    r2535 r2557  
    5757  // -- FormatReader API methods -- 
    5858 
    59   /** Checks if the given block is a valid header for an image file. */ 
     59  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    6060  public boolean isThisType(byte[] block) { return false; } 
    6161 
    62   /** Determines the number of images in the given image file. */ 
     62  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    6363  public int getImageCount(String id) throws FormatException, IOException { 
    6464    return 1; 
    6565  } 
    6666 
    67   /** Checks if the images in the file are RGB. */ 
     67  /* @see loci.formats.IFormatReader#isRGB(String) */  
    6868  public boolean isRGB(String id) throws FormatException, IOException { 
    6969    if (!id.equals(currentId)) initFile(id); 
     
    7171  } 
    7272 
    73   /** Return true if the data is in little-endian format. */ 
     73  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    7474  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    7575    return false; 
    7676  } 
    7777 
    78   /** Returns whether or not the channels are interleaved. */ 
     78  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    7979  public boolean isInterleaved(String id, int subC) 
    8080    throws FormatException, IOException 
     
    8383  } 
    8484 
    85   /** Obtains the specified image from the given file as a byte array. */ 
     85  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    8686  public byte[] openBytes(String id, int no) 
    8787    throws FormatException, IOException 
    8888  { 
    8989    byte[] b = ImageTools.getBytes(openImage(id, no), false, no); 
    90     int bytesPerChannel = getSizeX(id) * getSizeY(id); 
     90    int bytesPerChannel = core.sizeX[0] * core.sizeY[0]; 
    9191    if (b.length > bytesPerChannel) { 
    9292      byte[] tmp = b; 
     
    100100  } 
    101101 
    102   /** Obtains the image from the given image file. */ 
     102  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    103103  public BufferedImage openImage(String id, int no) 
    104104    throws FormatException, IOException 
     
    120120  public void close(boolean fileOnly) throws FormatException, IOException { } 
    121121 
    122   /** Closes any open files. */ 
     122  /* @see loci.formats.IFormatReader#close() */  
    123123  public void close() throws FormatException, IOException { } 
    124124 
     
    131131    BufferedImage img = openImage(id, 0); 
    132132 
    133     sizeX[0] = img.getWidth(); 
    134     sizeY[0] = img.getHeight(); 
     133    core.sizeX[0] = img.getWidth(); 
     134    core.sizeY[0] = img.getHeight(); 
    135135 
    136136    rgb = img.getRaster().getNumBands() > 1; 
    137137 
    138     sizeZ[0] = 1; 
    139     sizeC[0] = rgb ? 3 : 1; 
    140     sizeT[0] = 1; 
    141     currentOrder[0] = "XYCZT"; 
    142     pixelType[0] = ImageTools.getPixelType(img); 
     138    core.sizeZ[0] = 1; 
     139    core.sizeC[0] = rgb ? 3 : 1; 
     140    core.sizeT[0] = 1; 
     141    core.currentOrder[0] = "XYCZT"; 
     142    core.pixelType[0] = ImageTools.getPixelType(img); 
    143143 
    144144    // populate the metadata store 
     
    147147 
    148148    store.setPixels( 
    149       new Integer(getSizeX(id)), 
    150       new Integer(getSizeY(id)), 
    151       new Integer(1), 
    152       new Integer(sizeC[0]), 
    153       new Integer(1), 
    154       new Integer(pixelType[0]), 
     149      new Integer(core.sizeX[0]), 
     150      new Integer(core.sizeY[0]), 
     151      new Integer(core.sizeZ[0]), 
     152      new Integer(core.sizeC[0]), 
     153      new Integer(core.sizeT[0]), 
     154      new Integer(core.pixelType[0]), 
    155155      new Boolean(false), 
    156       getDimensionOrder(id), 
     156      core.currentOrder[0],  
    157157      null, 
    158158      null); 
    159     for (int i=0; i<sizeC[0]; i++) { 
     159    for (int i=0; i<core.sizeC[0]; i++) { 
    160160      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    161161    } 
  • trunk/loci/formats/in/ImarisReader.java

    r2535 r2557  
    5353  /** Number of image planes in the file. */ 
    5454  protected int numImages = 0; 
    55  
    56   /** Image dimensions: width, height, z, channels. */ 
    57   private int[] dims; 
    5855 
    5956  /** Offsets to each image. */ 
     
    7774    in.order(IS_LITTLE); 
    7875 
    79     dims = new int[4]; 
    80  
    8176    long magic = in.readInt(); 
    8277    if (magic != IMARIS_MAGIC_NUMBER) { 
     
    9590    addMeta("Image name", iName); 
    9691 
    97     dims[0] = in.readShort(); 
    98     dims[1] = in.readShort(); 
    99     dims[2] = in.readShort(); 
     92    core.sizeX[0] = in.readShort(); 
     93    core.sizeY[0] = in.readShort(); 
     94    core.sizeZ[0] = in.readShort(); 
    10095 
    10196    in.skipBytes(2); 
    10297 
    103     dims[3] = in.readInt(); 
     98    core.sizeC[0] = in.readInt(); 
    10499    in.skipBytes(2); 
    105100 
     
    123118    status("Calculating image offsets"); 
    124119 
    125     numImages = dims[2] * dims[3]; 
     120    numImages = core.sizeZ[0] * core.sizeC[0];  
    126121    offsets = new int[numImages]; 
    127122 
    128     for (int i=0; i<dims[3]; i++) { 
    129       int offset = 332 + ((i + 1) * 168) + (i * dims[0] * dims[1] * dims[2]); 
    130       for (int j=0; j<dims[2]; j++) { 
    131         offsets[i*dims[2] + j] = offset + (j * dims[0] * dims[1]); 
     123    for (int i=0; i<core.sizeC[0]; i++) { 
     124      int offset = 332 + ((i + 1) * 168) + (i * core.sizeX[0] *  
     125        core.sizeY[0] * core.sizeZ[0]); 
     126      for (int j=0; j<core.sizeZ[0]; j++) { 
     127        offsets[i*core.sizeZ[0] + j] =  
     128          offset + (j * core.sizeX[0] * core.sizeY[0]); 
    132129      } 
    133130    } 
     
    135132    status("Populating metadata"); 
    136133 
    137     sizeX[0] = dims[0]; 
    138     sizeY[0] = dims[1]; 
    139     sizeZ[0] = dims[2]; 
    140     sizeC[0] = dims[3]; 
    141     sizeT[0] = numImages / (dims[2] * dims[3]); 
    142     currentOrder[0] = "XYZCT"; 
     134    core.sizeT[0] = numImages / (core.sizeC[0] * core.sizeZ[0]); 
     135    core.currentOrder[0] = "XYZCT"; 
    143136 
    144137    // The metadata store we're working with. 
    145138    MetadataStore store = getMetadataStore(id); 
    146139 
    147     pixelType[0] = FormatTools.UINT8; 
     140    core.pixelType[0] = FormatTools.UINT8; 
    148141    store.setPixels( 
    149       new Integer(dims[0]), 
    150       new Integer(dims[1]), 
    151       new Integer(dims[2]), 
    152       new Integer(dims[3]), 
    153       new Integer(1), 
    154       new Integer(pixelType[0]), 
     142      new Integer(core.sizeX[0]), 
     143      new Integer(core.sizeY[0]), 
     144      new Integer(core.sizeZ[0]), 
     145      new Integer(core.sizeC[0]), 
     146      new Integer(core.sizeT[0]), 
     147      new Integer(core.pixelType[0]), 
    155148      new Boolean(!IS_LITTLE), 
    156       "XYZCT", 
     149      core.currentOrder[0], 
    157150      null, 
    158151      null); 
     
    174167    store.setObjective(null, null, null, null, new Float(mag), null, null); 
    175168 
    176     for (int i=0; i<sizeC[0]; i++) { 
     169    for (int i=0; i<core.sizeC[0]; i++) { 
    177170      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    178171    } 
     
    181174  // -- IFormatReader API methods -- 
    182175 
    183   /** Checks if the given block is a valid header for an Imaris file. */ 
     176  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    184177  public boolean isThisType(byte[] block) { 
    185178    return DataTools.bytesToInt(block, 0, 4, IS_LITTLE) == IMARIS_MAGIC_NUMBER; 
    186179  } 
    187180 
    188   /** Determines the number of images in the given Imaris file. */ 
     181  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    189182  public int getImageCount(String id) throws FormatException, IOException { 
    190183    if (!id.equals(currentId)) initFile(id); 
     
    192185  } 
    193186 
    194   /** Checks if the images in the file are RGB. */ 
     187  /* @see loci.formats.IFormatReader#isRGB(String) */  
    195188  public boolean isRGB(String id) throws FormatException, IOException { 
    196189    return false; 
    197190  } 
    198191 
    199   /** Return true if the data is in little-endian format. */ 
     192  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    200193  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    201194    return IS_LITTLE; 
    202195  } 
    203196 
    204   /** Returns whether or not the channels are interleaved. */ 
     197  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    205198  public boolean isInterleaved(String id, int subC) 
    206199    throws FormatException, IOException 
     
    209202  } 
    210203 
    211   /** 
    212    * Obtains the specified image from the 
    213    * given Imaris file as a byte array. 
    214    */ 
     204  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    215205  public byte[] openBytes(String id, int no) 
    216206    throws FormatException, IOException 
    217207  { 
    218208    if (!id.equals(currentId)) initFile(id); 
    219     byte[] buf = new byte[dims[0] * dims[1]]; 
     209    byte[] buf = new byte[core.sizeX[0] * core.sizeY[0]]; 
    220210    return openBytes(id, no, buf); 
    221211  } 
    222212 
     213  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    223214  public byte[] openBytes(String id, int no, byte[] buf) 
    224215    throws FormatException, IOException 
     
    228219      throw new FormatException("Invalid image number: " + no); 
    229220    } 
    230     if (buf.length < dims[0] * dims[1]) { 
     221    if (buf.length < core.sizeX[0] * core.sizeY[0]) { 
    231222      throw new FormatException("Buffer too small."); 
    232223    } 
    233224 
    234225    in.seek(offsets[no]); 
    235     int row = dims[1] - 1; 
    236     for (int i=0; i<dims[1]; i++) { 
    237       in.read(buf, row*dims[0], dims[0]); 
     226    int row = core.sizeY[0] - 1; 
     227    for (int i=0; i<core.sizeY[0]; i++) { 
     228      in.read(buf, row*core.sizeX[0], core.sizeX[0]); 
    238229      row--; 
    239230    } 
     
    241232  } 
    242233 
    243   /** Obtains the specified image from the given Imaris file. */ 
     234  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    244235  public BufferedImage openImage(String id, int no) 
    245236    throws FormatException, IOException 
    246237  { 
    247     BufferedImage b = ImageTools.makeImage(openBytes(id, no), dims[0], 
    248       dims[1], 1, false); 
    249     return b; 
     238    return ImageTools.makeImage(openBytes(id, no), core.sizeX[0], 
     239      core.sizeY[0], 1, false); 
    250240  } 
    251241 
     
    256246  } 
    257247 
    258   /** Closes any open files. */ 
     248  /* @see loci.formats.IFormatReader#close() */  
    259249  public void close() throws FormatException, IOException { 
    260250    if (in != null) in.close(); 
     
    279269  } 
    280270 
    281   // -- Main method -- 
    282  
    283   public static void main(String[] args) throws FormatException, IOException { 
    284     new ImarisReader().testRead(args); 
    285   } 
    286  
    287271} 
  • trunk/loci/formats/in/ImarisTiffReader.java

    r2523 r2557  
    4646  // -- FormatReader API methods -- 
    4747 
    48   /** Checks if the given block is a valid header for an Imaris TIFF file. */ 
     48  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    4949  public boolean isThisType(byte[] block) { 
    5050    // adapted from MetamorphReader.isThisType(byte[]) 
     
    7979  // -- IFormatHandler API methods -- 
    8080 
    81   /** 
    82    * Checks if the given string is a valid filename for an Imaris TIFF file. 
    83    * @param open If true, and the file extension is insufficient to determine 
    84    *  the file type, the (existing) file is opened for further analysis. 
    85    */ 
     81  /* @see loci.formats.IFormatHandler#isThisType(String, boolean) */  
    8682  public boolean isThisType(String name, boolean open) { 
    8783    if (!super.isThisType(name, open)) return false; // check extension 
     
    144140    status("Populating metadata"); 
    145141 
    146     sizeC[0] = ifds.length - 1; 
    147     sizeZ[0] = tmp.size() / sizeC[0]; 
    148     sizeT[0] = 1; 
    149     sizeX[0] = 
     142    core.sizeC[0] = ifds.length - 1; 
     143    core.sizeZ[0] = tmp.size() / core.sizeC[0]; 
     144    core.sizeT[0] = 1; 
     145    core.sizeX[0] = 
    150146      TiffTools.getIFDIntValue(ifds[1], TiffTools.IMAGE_WIDTH, false, 0); 
    151     sizeY[0] = 
     147    core.sizeY[0] = 
    152148      TiffTools.getIFDIntValue(ifds[1], TiffTools.IMAGE_LENGTH, false, 0); 
    153149 
    154150    ifds = (Hashtable[]) tmp.toArray(new Hashtable[0]); 
    155     numImages = sizeC[0] * sizeZ[0]; 
    156     currentOrder[0] = "XYZCT"; 
     151    numImages = core.sizeC[0] * core.sizeZ[0]; 
     152    core.currentOrder[0] = "XYZCT"; 
    157153 
    158154    int bitsPerSample = TiffTools.getIFDIntValue(ifds[0], 
     
    160156    int bitFormat = TiffTools.getIFDIntValue(ifds[0], TiffTools.SAMPLE_FORMAT); 
    161157 
     158    // TODO : look into removing this logic, since it's copied directly from 
     159    // BaseTiffReader 
     160 
    162161    while (bitsPerSample % 8 != 0) bitsPerSample++; 
    163162    if (bitsPerSample == 24 || bitsPerSample == 48) bitsPerSample /= 3; 
    164163 
    165     if (bitFormat == 3) pixelType[0] = FormatTools.FLOAT; 
     164    if (bitFormat == 3) core.pixelType[0] = FormatTools.FLOAT; 
    166165    else if (bitFormat == 2) { 
    167166      switch (bitsPerSample) { 
    168167        case 8: 
    169           pixelType[0] = FormatTools.INT8; 
     168          core.pixelType[0] = FormatTools.INT8; 
    170169          break; 
    171170        case 16: 
    172           pixelType[0] = FormatTools.INT16; 
     171          core.pixelType[0] = FormatTools.INT16; 
    173172          break; 
    174173        case 32: 
    175           pixelType[0] = FormatTools.INT32; 
     174          core.pixelType[0] = FormatTools.INT32; 
    176175          break; 
    177176      } 
     
    180179      switch (bitsPerSample) { 
    181180        case 8: 
    182           pixelType[0] = FormatTools.UINT8; 
     181          core.pixelType[0] = FormatTools.UINT8; 
    183182          break; 
    184183        case 16: 
    185           pixelType[0] = FormatTools.UINT16; 
     184          core.pixelType[0] = FormatTools.UINT16; 
    186185          break; 
    187186        case 32: 
    188           pixelType[0] = FormatTools.UINT32; 
     187          core.pixelType[0] = FormatTools.UINT32; 
    189188          break; 
    190189      } 
     
    213212    MetadataStore store = getMetadataStore(currentId); 
    214213 
    215     store.setPixels(new Integer(sizeX[0]), new Integer(sizeY[0]), 
    216       new Integer(sizeZ[0]), new Integer(sizeC[0]), new Integer(sizeT[0]), 
    217       new Integer(pixelType[0]), null, currentOrder[0], 
    218       null, null); 
    219  
    220   } 
    221  
    222   // -- Main method -- 
    223  
    224   public static void main(String[] args) throws FormatException, IOException { 
    225     new ImarisTiffReader().testRead(args); 
     214    store.setPixels(new Integer(core.sizeX[0]), new Integer(core.sizeY[0]), 
     215      new Integer(core.sizeZ[0]), new Integer(core.sizeC[0]),  
     216      new Integer(core.sizeT[0]), new Integer(core.pixelType[0]), null,  
     217      core.currentOrder[0], null, null); 
     218 
    226219  } 
    227220 
  • trunk/loci/formats/in/JPEGReader.java

    r2178 r2557  
    2525package loci.formats.in; 
    2626 
    27 import java.io.IOException; 
    28 import loci.formats.*; 
    29  
    3027/** 
    3128 * JPEGReader is the file format reader for JPEG images. 
     
    4340  } 
    4441 
    45   // -- Main method -- 
    46  
    47   public static void main(String[] args) throws FormatException, IOException { 
    48     new JPEGReader().testRead(args); 
    49   } 
    50  
    5142} 
  • trunk/loci/formats/in/LIFReader.java

    r2535 r2557  
    8787  // -- FormatReader API methods -- 
    8888 
    89   /** Checks if the given block is a valid header for a LIF file. */ 
     89  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    9090  public boolean isThisType(byte[] block) { 
    9191    return block[0] == 0x70; 
    9292  } 
    9393 
    94   /** Determines the number of images in the given LIF file. */ 
     94  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    9595  public int getImageCount(String id) throws FormatException, IOException { 
    9696    if (!id.equals(currentId)) initFile(id); 
     
    9999  } 
    100100 
    101   /** Checks if the images in the file are RGB. */ 
     101  /* @see loci.formats.IFormatReader#isRGB(String) */  
    102102  public boolean isRGB(String id) throws FormatException, IOException { 
    103103    if (!id.equals(currentId)) initFile(id); 
     
    105105  } 
    106106 
    107   /** Return true if the data is in little-endian format. */ 
     107  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    108108  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    109109    if (!id.equals(currentId)) initFile(id); 
     
    111111  } 
    112112 
    113   /** Returns whether or not the channels are interleaved. */ 
     113  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    114114  public boolean isInterleaved(String id, int subC) 
    115115    throws FormatException, IOException 
     
    118118  } 
    119119 
    120   /** Return the number of series in this file. */ 
     120  /* @see loci.formats.IFormatReader#getSeriesCount(String) */  
    121121  public int getSeriesCount(String id) throws FormatException, IOException { 
    122122    if (!id.equals(currentId)) initFile(id); 
     
    124124  } 
    125125 
    126   /** Obtains the specified image from the given LIF file as a byte array. */ 
     126  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    127127  public byte[] openBytes(String id, int no) 
    128128    throws FormatException, IOException 
     
    131131    bpp = dims[series][5]; 
    132132    while (bpp % 8 != 0) bpp++; 
    133     byte[] buf = new byte[sizeX[series] * sizeY[series] * 
     133    byte[] buf = new byte[core.sizeX[series] * core.sizeY[series] * 
    134134      (bpp / 8) * getRGBChannelCount(id)]; 
    135135    return openBytes(id, no, buf); 
    136136  } 
    137137 
     138  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    138139  public byte[] openBytes(String id, int no, byte[] buf) 
    139140    throws FormatException, IOException 
     
    146147    while (bpp % 8 != 0) bpp++; 
    147148    int bytes = bpp / 8; 
    148     if (buf.length < sizeX[series] * sizeY[series] * bytes *  
     149    if (buf.length < core.sizeX[series] * core.sizeY[series] * bytes *  
    149150      getRGBChannelCount(id))  
    150151    { 
     
    153154 
    154155    int offset = ((Long) offsets.get(series)).intValue(); 
    155     in.seek(offset + 
    156       sizeX[series] * sizeY[series] * bytes * no * getRGBChannelCount(id)); 
     156    in.seek(offset + core.sizeX[series] * core.sizeY[series] *  
     157      bytes * no * getRGBChannelCount(id)); 
    157158    
    158159    in.read(buf); 
     
    160161  } 
    161162 
    162   /** Obtains the specified image from the given LIF file. */ 
     163  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    163164  public BufferedImage openImage(String id, int no) 
    164165    throws FormatException, IOException 
    165166  { 
    166     BufferedImage b = ImageTools.makeImage(openBytes(id, no), sizeX[series], 
    167       sizeY[series], isRGB(id) ? sizeC[series] : 1, false, bpp / 8, 
     167    return ImageTools.makeImage(openBytes(id, no), core.sizeX[series], 
     168      core.sizeY[series], isRGB(id) ? core.sizeC[series] : 1, false, bpp / 8, 
    168169      littleEndian, validBits[series]); 
    169     return b; 
    170170  } 
    171171 
     
    176176  } 
    177177 
    178   /** Closes any open files. */ 
     178  /* @see loci.formats.IFormatReader#close() */  
    179179  public void close() throws FormatException, IOException { 
    180180    if (in != null) in.close(); 
     
    489489    MetadataStore store = getMetadataStore(currentId); 
    490490 
    491     sizeX = new int[numDatasets]; 
    492     sizeY = new int[numDatasets]; 
    493     sizeZ = new int[numDatasets]; 
    494     sizeC = new int[numDatasets]; 
    495     sizeT = new int[numDatasets]; 
    496     pixelType = new int[numDatasets]; 
    497     currentOrder = new String[numDatasets]; 
    498     orderCertain = new boolean[numDatasets]; 
    499     Arrays.fill(orderCertain, true); 
    500     validBits = new int[numDatasets][1]; 
    501     cLengths = new int[numDatasets][]; 
    502     cTypes = new String[numDatasets][]; 
     491    core = new CoreMetadata(numDatasets); 
     492    Arrays.fill(core.orderCertain, true); 
     493    validBits = new int[numDatasets][]; 
    503494 
    504495    for (int i=0; i<numDatasets; i++) { 
    505       sizeX[i] = dims[i][0]; 
    506       sizeY[i] = dims[i][1]; 
    507       sizeZ[i] = dims[i][2]; 
    508       sizeC[i] = dims[i][4]; 
    509       sizeT[i] = dims[i][3]; 
    510       currentOrder[i] = (sizeZ[i] > sizeT[i]) ? "XYCZT" : "XYCTZ"; 
    511  
    512       validBits[i] = new int[sizeC[i] != 2 ? sizeC[i] : 3]; 
     496      core.sizeX[i] = dims[i][0]; 
     497      core.sizeY[i] = dims[i][1]; 
     498      core.sizeZ[i] = dims[i][2]; 
     499      core.sizeC[i] = dims[i][4]; 
     500      core.sizeT[i] = dims[i][3]; 
     501      core.currentOrder[i] =  
     502        (core.sizeZ[i] > core.sizeT[i]) ? "XYCZT" : "XYCTZ"; 
     503 
     504      validBits[i] = new int[core.sizeC[i] != 2 ? core.sizeC[i] : 3]; 
    513505      for (int j=0; j<validBits[i].length; j++) { 
    514506        validBits[i][j] = dims[i][5]; 
     
    518510      switch (dims[i][5]) { 
    519511        case 8: 
    520           pixelType[i] = FormatTools.UINT8; 
     512          core.pixelType[i] = FormatTools.UINT8; 
    521513          break; 
    522514        case 16: 
    523           pixelType[i] = FormatTools.UINT16; 
     515          core.pixelType[i] = FormatTools.UINT16; 
    524516          break; 
    525517        case 32: 
    526           pixelType[i] = FormatTools.FLOAT; 
     518          core.pixelType[i] = FormatTools.FLOAT; 
    527519          break; 
    528520      } 
     
    533525 
    534526      store.setPixels( 
    535         new Integer(dims[i][0]), // SizeX 
    536         new Integer(dims[i][1]), // SizeY 
    537         new Integer(dims[i][2]), // SizeZ 
    538         new Integer(dims[i][4]), // SizeC 
    539         new Integer(dims[i][3]), // SizeT 
    540         new Integer(pixelType[i]), // PixelType 
     527        new Integer(core.sizeX[0]), // SizeX 
     528        new Integer(core.sizeY[0]), // SizeY 
     529        new Integer(core.sizeZ[0]), // SizeZ 
     530        new Integer(core.sizeC[0]), // SizeC 
     531        new Integer(core.sizeT[0]), // SizeT 
     532        new Integer(core.pixelType[i]), // PixelType 
    541533        new Boolean(!littleEndian), // BigEndian 
    542         getDimensionOrder(currentId), // DimensionOrder 
     534        core.currentOrder[i], // DimensionOrder 
    543535        ii, // Image index 
    544536        null); // Pixels index 
     
    549541 
    550542      store.setDimensions(xf, yf, zf, null, null, ii); 
    551       for (int j=0; j<sizeC[i]; j++) { 
     543      for (int j=0; j<core.sizeC[i]; j++) { 
    552544        store.setLogicalChannel(j, null, null, null, null, null, null, ii); 
    553545      } 
     
    556548        (String) getMeta((String) seriesNames.get(i) + " - dblZoom"); 
    557549      store.setDisplayOptions(zoom == null ? null : new Float(zoom), 
    558         new Boolean(sizeC[i] > 1), new Boolean(sizeC[i] > 1), 
    559         new Boolean(sizeC[i] > 2), new Boolean(isRGB(currentId)), null, null, 
    560         null, null, null, ii, null, null, null, null, null); 
    561  
    562     } 
    563   } 
    564  
    565   // -- Main method -- 
    566  
    567   public static void main(String[] args) throws FormatException, IOException { 
    568     new LIFReader().testRead(args); 
     550        new Boolean(core.sizeC[i] > 1), new Boolean(core.sizeC[i] > 1), 
     551        new Boolean(core.sizeC[i] > 2), new Boolean(isRGB(currentId)), null,  
     552        null, null, null, null, ii, null, null, null, null, null); 
     553    } 
    569554  } 
    570555 
  • trunk/loci/formats/in/LegacyPictReader.java

    r2535 r2557  
    4747  // -- FormatReader API methods -- 
    4848 
    49   /** Checks if the given block is a valid header for a PICT file. */ 
     49  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    5050  public boolean isThisType(byte[] block) { 
    5151    return false; 
    5252  } 
    5353 
    54   /** Determines the number of images in the given PICT file. */ 
     54  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    5555  public int getImageCount(String id) throws FormatException, IOException { 
    5656    return 1; 
    5757  } 
    5858 
    59   /** Checks if the images in the file are RGB. */ 
     59  /* @see loci.formats.IFormatReader#isRGB(String) */  
    6060  public boolean isRGB(String id) throws FormatException, IOException { 
    6161    if (!id.equals(currentId)) initFile(id); 
    62     return sizeC[0] > 1; 
     62    return core.sizeC[0] > 1; 
    6363  } 
    6464 
    65   /** Return true if the data is in little-endian format. */ 
     65  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    6666  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    6767    return false; 
    6868  } 
    6969 
    70   /** Returns whether or not the channels are interleaved. */ 
     70  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    7171  public boolean isInterleaved(String id, int subC) 
    7272    throws FormatException, IOException 
     
    7575  } 
    7676 
    77   /** Obtains the specified image from the given file as a byte array. */ 
     77  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    7878  public byte[] openBytes(String id, int no) 
    7979    throws FormatException, IOException 
    8080  { 
    81     byte[] b = ImageTools.getBytes(openImage(id, no), false, 3); 
    82     return b; 
     81    return ImageTools.getBytes(openImage(id, no), false, 3); 
    8382  } 
    8483 
    85   /** Obtains the specified image from the given PICT file. */ 
     84  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    8685  public BufferedImage openImage(String id, int no) 
    8786    throws FormatException, IOException 
     
    105104    } 
    106105    fin.close(); 
    107     BufferedImage b = ImageTools.makeBuffered(qtTools.pictToImage(bytes)); 
    108     return b; 
     106    return ImageTools.makeBuffered(qtTools.pictToImage(bytes)); 
    109107  } 
    110108 
     
    115113    status("Populating metadata");  
    116114    BufferedImage img = openImage(id, 0); 
    117     sizeX[0] = img.getWidth(); 
    118     sizeY[0] = img.getHeight(); 
    119     sizeZ[0] = 1; 
    120     sizeC[0] = img.getRaster().getNumBands(); 
    121     sizeT[0] = 1; 
    122     pixelType[0] = FormatTools.INT8; 
    123     currentOrder[0] = "XYCZT"; 
     115    core.sizeX[0] = img.getWidth(); 
     116    core.sizeY[0] = img.getHeight(); 
     117    core.sizeZ[0] = 1; 
     118    core.sizeC[0] = img.getRaster().getNumBands(); 
     119    core.sizeT[0] = 1; 
     120    core.pixelType[0] = FormatTools.INT8; 
     121    core.currentOrder[0] = "XYCZT"; 
    124122 
    125123    MetadataStore store = getMetadataStore(id); 
    126     store.setPixels(new Integer(sizeX[0]), new Integer(sizeY[0]), 
    127       new Integer(1), new Integer(sizeC[0]), new Integer(1), 
    128       new Integer(pixelType[0]), Boolean.TRUE, currentOrder[0], null, null); 
     124    store.setPixels(new Integer(core.sizeX[0]), new Integer(core.sizeY[0]), 
     125      new Integer(core.sizeZ[0]), new Integer(core.sizeC[0]),  
     126      new Integer(core.sizeT[0]), new Integer(core.pixelType[0]), Boolean.TRUE, 
     127      core.currentOrder[0], null, null); 
    129128 
    130     for (int i=0; i<sizeC[0]; i++) { 
     129    for (int i=0; i<core.sizeC[0]; i++) { 
    131130      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    132131    } 
     
    136135  public void close(boolean fileOnly) throws FormatException, IOException { } 
    137136 
    138   /** Closes any open files. */ 
     137  /* @see loci.formats.IFormatReader#close() */  
    139138  public void close() throws FormatException, IOException { } 
    140139 
    141   // -- Main method -- 
    142  
    143   public static void main(String[] args) throws FormatException, IOException { 
    144     new LegacyPictReader().testRead(args); 
    145   } 
    146  
    147140} 
  • trunk/loci/formats/in/LegacyQTReader.java

    r2535 r2557  
    7171  // -- FormatReader API methods -- 
    7272 
    73   /** Checks if the given block is a valid header for a QuickTime file. */ 
     73  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    7474  public boolean isThisType(byte[] block) { return false; } 
    7575 
    76   /** Determines the number of images in the given QuickTime file. */ 
     76  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    7777  public int getImageCount(String id) throws FormatException, IOException { 
    7878    if (!id.equals(currentId)) initFile(id); 
     
    8080  } 
    8181 
    82   /** Checks if the images in the file are RGB. */ 
     82  /* @see loci.formats.IFormatReader#isRGB(String) */  
    8383  public boolean isRGB(String id) throws FormatException, IOException { 
    8484    return true; 
    8585  } 
    8686 
    87   /** Return true if the data is in little-endian format. */ 
     87  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    8888  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    8989    return false; 
    9090  } 
    9191 
    92   /** Returns whether or not the channels are interleaved. */ 
     92  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    9393  public boolean isInterleaved(String id, int subC) 
    9494    throws FormatException, IOException 
     
    9797  } 
    9898 
    99   /** Obtains the specified image from the given QuickTime file. */ 
     99  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    100100  public byte[] openBytes(String id, int no) 
    101101    throws FormatException, IOException 
    102102  { 
    103     byte[] b = ImageTools.getBytes(openImage(id, no), false, 3); 
    104     return b; 
    105   } 
    106  
    107   /** Obtains the specified image from the given QuickTime file. */ 
     103    return ImageTools.getBytes(openImage(id, no), false, 3); 
     104  } 
     105 
     106  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    108107  public BufferedImage openImage(String id, int no) 
    109108    throws FormatException, IOException 
     
    131130    } 
    132131 
    133     BufferedImage b = ImageTools.makeBuffered(image); 
    134     return b; 
     132    return ImageTools.makeBuffered(image); 
    135133  } 
    136134 
     
    148146  } 
    149147 
    150   /** Closes any open files. */ 
     148  /* @see loci.formats.IFormatReader#close() */  
    151149  public void close() throws FormatException, IOException { 
    152150    if (currentId == null) return; 
     
    241239      BufferedImage img = ImageTools.makeBuffered(image); 
    242240 
    243       sizeX[0] = img.getWidth(); 
    244       sizeY[0] = img.getHeight(); 
    245       sizeZ[0] = 1; 
    246       sizeC[0] = img.getRaster().getNumBands(); 
    247       sizeT[0] = numImages; 
    248       pixelType[0] = ImageTools.getPixelType(img); 
    249       currentOrder[0] = "XYCTZ"; 
     241      core.sizeX[0] = img.getWidth(); 
     242      core.sizeY[0] = img.getHeight(); 
     243      core.sizeZ[0] = 1; 
     244      core.sizeC[0] = img.getRaster().getNumBands(); 
     245      core.sizeT[0] = numImages; 
     246      core.pixelType[0] = ImageTools.getPixelType(img); 
     247      core.currentOrder[0] = "XYCTZ"; 
    250248 
    251249      MetadataStore store = getMetadataStore(id); 
    252       store.setPixels(new Integer(sizeX[0]), new Integer(sizeY[0]), 
    253         new Integer(1), new Integer(sizeC[0]), new Integer(sizeT[0]), 
    254         new Integer(pixelType[0]), Boolean.TRUE, currentOrder[0], null, null); 
    255  
    256       for (int i=0; i<sizeC[0]; i++) { 
     250      store.setPixels(new Integer(core.sizeX[0]), new Integer(core.sizeY[0]), 
     251        new Integer(core.sizeZ[0]), new Integer(core.sizeC[0]),  
     252        new Integer(core.sizeT[0]), new Integer(core.pixelType[0]),  
     253        Boolean.TRUE, core.currentOrder[0], null, null); 
     254 
     255      for (int i=0; i<core.sizeC[0]; i++) { 
    257256        store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    258257      } 
     
    264263  } 
    265264 
    266   // -- Main method -- 
    267  
    268   public static void main(String[] args) throws FormatException, IOException { 
    269     new LegacyQTReader().testRead(args); 
    270   } 
    271  
    272265} 
  • trunk/loci/formats/in/LegacyZVIReader.java

    r2535 r2557  
    7878  private int numZ = 0, numC = 0, numT = 0; 
    7979 
    80   /** dimension order within file */ 
    81   private String dimensionOrder  = "XYCZT"; 
    8280  private int cFlag = 0, zFlag = 0, tFlag = 0; 
    8381 
     
    8987  // -- FormatReader API methods -- 
    9088 
    91   /** Checks if the given block is a valid header for a ZVI file. */ 
     89  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    9290  public boolean isThisType(byte[] block) { 
    9391    if (block == null) return false; 
     
    9997  } 
    10098 
    101   /** Checks if the images in the file are RGB. */ 
     99  /* @see loci.formats.IFormatReader#isRGB(String) */  
    102100  public boolean isRGB(String id) throws FormatException, IOException { 
    103101    if (!id.equals(currentId)) initFile(id); 
     
    105103  } 
    106104 
    107   /** Return true if the data is in little-endian format. */ 
     105  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    108106  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    109107    return true; 
    110108  } 
    111109 
    112   /** Returns whether or not the channels are interleaved. */ 
     110  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    113111  public boolean isInterleaved(String id, int subC) 
    114112    throws FormatException, IOException 
     
    117115  } 
    118116 
    119   /** Obtains the specified image from the given ZVI file, as a byte array. */ 
     117  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    120118  public byte[] openBytes(String id, int no) throws FormatException, IOException 
    121119  { 
     
    125123  } 
    126124 
     125  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    127126  public byte[] openBytes(String id, int no, byte[] buf) 
    128127    throws FormatException, IOException 
     
    138137  } 
    139138 
    140   /** Determines the number of images in the given ZVI file. */ 
     139  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    141140  public int getImageCount(String id) throws FormatException, IOException { 
    142141    if (!id.equals(currentId)) initFile(id); 
     
    144143  } 
    145144 
    146   /** Obtains the specified image from the given ZVI file. */ 
     145  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    147146  public BufferedImage openImage(String id, int no) 
    148147    throws FormatException, IOException 
     
    157156 
    158157    ZVIBlock zviBlock = (ZVIBlock) blockList.elementAt(no); 
    159  
    160     BufferedImage b = zviBlock.readImage(in); 
    161     return b; 
     158    return zviBlock.readImage(in); 
    162159  } 
    163160 
     
    168165  } 
    169166 
    170   /** Closes any open files. */ 
     167  /* @see loci.formats.IFormatReader#close() */  
    171168  public void close() throws FormatException, IOException { 
    172169    if (in != null) in.close(); 
     
    289286 
    290287      // everything checks out; looks like an image header to me 
    291 //+ (mb) decoding strategy modification 
     288      //+ (mb) decoding strategy modification 
    292289      //      Some zvi images have the following structure: 
    293290      //        ZVI_SIG                    Decoding: 
     
    332329 
    333330      // read more header information 
    334       int width = (int) DataTools.read4UnsignedBytes(in, true); 
    335       int height = (int) DataTools.read4UnsignedBytes(in, true); 
     331      core.sizeX[0] = (int) DataTools.read4UnsignedBytes(in, true); 
     332      core.sizeY[0] = (int) DataTools.read4UnsignedBytes(in, true); 
    336333      // don't know what this is for 
    337334      int alwaysOne = (int) DataTools.read4UnsignedBytes(in, true); 
     
    347344        case 1: 
    348345          type = "8 bit rgb tuple, 24 bpp"; 
    349           pixelType[0] = FormatTools.INT8; 
     346          core.pixelType[0] = FormatTools.INT8; 
    350347          break; 
    351348        case 2: 
    352349          type = "8 bit rgb quad, 32 bpp"; 
    353           pixelType[0] = FormatTools.INT8; 
     350          core.pixelType[0] = FormatTools.INT8; 
    354351          break; 
    355352        case 3: 
    356353          type = "8 bit grayscale"; 
    357           pixelType[0] = FormatTools.INT8; 
     354          core.pixelType[0] = FormatTools.INT8; 
    358355          break; 
    359356        case 4: 
    360357          type = "16 bit signed int, 16 bpp"; 
    361           pixelType[0] = FormatTools.INT16; 
     358          core.pixelType[0] = FormatTools.INT16; 
    362359          break; 
    363360        case 5: 
    364361          type = "32 bit int, 32 bpp"; 
    365           pixelType[0] = FormatTools.INT32; 
     362          core.pixelType[0] = FormatTools.INT32; 
    366363          break; 
    367364        case 6: 
    368365          type = "32 bit float, 32 bpp"; 
    369           pixelType[0] = FormatTools.FLOAT; 
     366          core.pixelType[0] = FormatTools.FLOAT; 
    370367          break; 
    371368        case 7: 
    372369          type = "64 bit float, 64 bpp"; 
    373           pixelType[0] = FormatTools.DOUBLE; 
     370          core.pixelType[0] = FormatTools.DOUBLE; 
    374371          break; 
    375372        case 8: 
    376373          type = "16 bit unsigned short triple, 48 bpp"; 
    377           pixelType[0] = FormatTools.INT16; 
     374          core.pixelType[0] = FormatTools.INT16; 
    378375          break; 
    379376        case 9: 
    380377          type = "32 bit int triple, 96 bpp"; 
    381           pixelType[0] = FormatTools.INT32; 
     378          core.pixelType[0] = FormatTools.INT32; 
    382379          break; 
    383380        default: 
     
    385382      } 
    386383 
    387       addMeta("Width", new Integer(width)); 
    388       addMeta("Height", new Integer(height)); 
     384      addMeta("Width", new Integer(core.sizeX[0])); 
     385      addMeta("Height", new Integer(core.sizeY[0])); 
    389386      addMeta("PixelType", type); 
    390387      addMeta("BPP", new Integer(bytesPerPixel)); 
    391388 
    392       ZVIBlock zviBlock = new ZVIBlock(theZ, theC, theT, width, height, 
    393         alwaysOne, bytesPerPixel, pixType, bitDepth, pos); 
     389      ZVIBlock zviBlock = new ZVIBlock(theZ, theC, theT, core.sizeX[0],  
     390        core.sizeY[0], alwaysOne, bytesPerPixel, pixType, bitDepth, pos); 
    394391      if (debug) debug(zviBlock.toString()); 
    395392 
     
    407404 
    408405      if ((numI % 3 == 0) && (zSet.size() > 1) && (cFlag == 1)) { 
    409         dimensionOrder = "XYCZT"; 
     406        core.currentOrder[0] = "XYCZT"; 
    410407      } 
    411408      if ((numI % 3 == 0) && (tSet.size() > 1) && (cFlag == 1)) { 
    412         dimensionOrder = "XYCTZ"; 
     409        core.currentOrder[0] = "XYCTZ"; 
    413410      } 
    414411      if ((numI % 3 == 0) && (cSet.size() > 1) && (zFlag == 1)) { 
    415         dimensionOrder = "XYZCT"; 
     412        core.currentOrder[0] = "XYZCT"; 
    416413      } 
    417414      if ((numI % 3 == 0) && (tSet.size() > 1) && (zFlag == 1)) { 
    418         dimensionOrder = "XYZTC"; 
     415        core.currentOrder[0] = "XYZTC"; 
    419416      } 
    420417      if ((numI % 3 == 0) && (cSet.size() > 1) && (tFlag == 1)) { 
    421         dimensionOrder = "XYTCZ"; 
     418        core.currentOrder[0] = "XYTCZ"; 
    422419      } 
    423420      if ((numI % 3 == 0) && (zSet.size() > 1) && (tFlag == 1)) { 
    424         dimensionOrder = "XYTZC"; 
     421        core.currentOrder[0] = "XYTZC"; 
    425422      } 
    426423 
    427424      // save this image block's position 
    428425      blockList.add(zviBlock); 
    429       pos += width * height * bytesPerPixel; 
    430  
    431       sizeX[0] = openImage(id, 0).getWidth(); 
    432       sizeY[0] = openImage(id, 0).getHeight(); 
    433       sizeZ[0] = zSet.size(); 
    434       sizeC[0] = cSet.size(); 
    435       sizeT[0] = tSet.size(); 
    436       currentOrder[0] = dimensionOrder; 
     426      pos += core.sizeX[0] * core.sizeY[0] * bytesPerPixel; 
     427 
     428      core.sizeX[0] = openImage(id, 0).getWidth(); 
     429      core.sizeY[0] = openImage(id, 0).getHeight(); 
     430      core.sizeZ[0] = zSet.size(); 
     431      core.sizeC[0] = cSet.size(); 
     432      core.sizeT[0] = tSet.size(); 
    437433 
    438434      // Populate metadata store 
    439435 
    440       // The metadata store we're working with. 
    441436      MetadataStore store = getMetadataStore(id); 
    442437 
    443438      store.setPixels( 
    444         new Integer(width), // SizeX 
    445         new Integer(height), // SizeY 
    446         new Integer(getSizeZ(id)), // SizeZ 
    447         new Integer(getSizeC(id)), // SizeC 
    448         new Integer(getSizeT(id)), // SizeT 
    449         new Integer(pixelType[0]), // PixelType 
     439        new Integer(core.sizeX[0]), // SizeX 
     440        new Integer(core.sizeY[0]), // SizeY 
     441        new Integer(core.sizeZ[0]), // SizeZ 
     442        new Integer(core.sizeC[0]), // SizeC 
     443        new Integer(core.sizeT[0]), // SizeT 
     444        new Integer(core.pixelType[0]), // PixelType 
    450445        Boolean.FALSE, // BigEndian 
    451         new String(dimensionOrder), // DimensionOrder 
     446        core.currentOrder[0], // DimensionOrder 
    452447        null, // Use image index 0 
    453448        null); // Use pixels index 0 
    454449 
    455       for (int i=0; i<sizeC[0]; i++) { 
     450      for (int i=0; i<core.sizeC[0]; i++) { 
    456451        store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    457452      } 
  • trunk/loci/formats/in/LeicaReader.java

    r2535 r2557  
    6060  protected TiffReader[][] tiff; 
    6161 
    62   /** Number of channels in the current series. */ 
    63   protected int[] numChannels; 
    64  
    6562  /** Array of image file names. */ 
    6663  protected Vector[] files; 
     
    6865  /** Number of series in the file. */ 
    6966  private int numSeries; 
    70  
    71   /** Image widths. */ 
    72   private int[] widths; 
    73  
    74   /** Image heights. */ 
    75   private int[] heights; 
    76  
    77   /** Number of Z slices. */ 
    78   private int[] zs; 
    7967 
    8068  /** Total number of planes in each series. */ 
     
    9684  // -- FormatReader API methods -- 
    9785 
    98   /** Checks if the given block is a valid header for a Leica file. */ 
     86  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    9987  public boolean isThisType(byte[] block) { 
    10088    if (block.length < 4) return false; 
     
    125113  } 
    126114 
    127   /** Determines the number of images in the given Leica file. */ 
     115  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    128116  public int getImageCount(String id) throws FormatException, IOException { 
    129117    if (!id.equals(currentId) && !usedFile(id) && !id.equals(leiFilename)) { 
     
    133121  } 
    134122 
    135   /** Return the number of series in the given Leica file. */ 
     123  /* @see loci.formats.IFormatReader#getSeriesCount(String) */  
    136124  public int getSeriesCount(String id) throws FormatException, IOException { 
    137125    if (!id.equals(currentId) && !usedFile(id) && !id.equals(leiFilename)) { 
     
    141129  } 
    142130 
    143   /** Checks if the images in the file are RGB. */ 
     131  /* @see loci.formats.IFormatReader#isRGB(String) */  
    144132  public boolean isRGB(String id) throws FormatException, IOException { 
    145133    if (!id.equals(currentId) && !usedFile(id) && !id.equals(leiFilename)) { 
     
    149137  } 
    150138 
    151   /** Return true if the data is in little-endian format. */ 
     139  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    152140  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    153141    if (!id.equals(currentId) && !usedFile(id) && !id.equals(leiFilename)) { 
     
    157145  } 
    158146 
    159   /** Returns whether or not the channels are interleaved. */ 
     147  /* @see loci.formats.IFormatReader#isInterleaved(String, int) */  
    160148  public boolean isInterleaved(String id, int subC) 
    161149    throws FormatException, IOException 
     
    164152  } 
    165153 
    166   /** Obtains the specified image from the given Leica file as a byte array. */ 
     154  /* @see loci.formats.IFormatReader#openBytes(String, int) */ 
    167155  public byte[] openBytes(String id, int no) 
    168156    throws FormatException, IOException 
     
    180168  } 
    181169 
     170  /* @see loci.formats.IFormatReader#openBytes(String, int, byte[]) */ 
    182171  public byte[] openBytes(String id, int no, byte[] buf) 
    183172    throws FormatException, IOException 
     
    192181  } 
    193182 
    194   /** Obtains the specified image from the given Leica file. */ 
     183  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    195184  public BufferedImage openImage(String id, int no) 
    196185    throws FormatException, IOException 
     
    245234  } 
    246235 
    247   /** Closes any open files. */ 
     236  /* @see loci.formats.IFormatReader#close() */  
    248237  public void close() throws FormatException, IOException { 
    249238    if (in != null) in.close(); 
     
    400389      if (v.size() < numSeries) numSeries = v.size(); 
    401390 
    402       numChannels = new int[numSeries]; 
    403       widths = new int[numSeries]; 
    404       heights = new int[numSeries]; 
    405       zs = new int[numSeries]; 
     391      core = new CoreMetadata(numSeries); 
     392 
    406393      headerIFDs = new Hashtable[numSeries]; 
    407394      files = new Vector[numSeries]; 
    408395      numPlanes = new int[numSeries]; 
    409       cLengths = new int[numSeries][]; 
    410       cTypes = new String[numSeries][]; 
    411396 
    412397      v.copyInto(headerIFDs); 
     
    688673        // ID_IMAGES 
    689674 
    690         zs[i] = DataTools.bytesToInt(temp, 0, 4, littleEndian); 
    691         widths[i] = DataTools.bytesToInt(temp, 4, 4, littleEndian); 
    692         heights[i] = DataTools.bytesToInt(temp, 8, 4, littleEndian); 
    693  
    694         addMeta("Number of images", new Integer(zs[i])); 
    695         addMeta("Image width", new Integer(widths[i])); 
    696         addMeta("Image height", new Integer(heights[i])); 
     675        core.sizeZ[i] = DataTools.bytesToInt(temp, 0, 4, littleEndian); 
     676        core.sizeX[i] = DataTools.bytesToInt(temp, 4, 4, littleEndian); 
     677        core.sizeY[i] = DataTools.bytesToInt(temp, 8, 4, littleEndian); 
     678 
     679        addMeta("Number of images", new Integer(core.sizeZ[i])); 
     680        addMeta("Image width", new Integer(core.sizeX[i])); 
     681        addMeta("Image height", new Integer(core.sizeY[i])); 
    697682        addMeta("Bits per Sample", 
    698683          new Integer(DataTools.bytesToInt(temp, 12, 4, littleEndian))); 
     
    973958 
    974959        if (nChannels > 4) nChannels = 3; 
    975         numChannels[i] = nChannels; 
     960        core.sizeC[i] = nChannels; 
    976961 
    977962        for (int j=0; j<nChannels; j++) { 
     
    10151000    } 
    10161001 
    1017     sizeX = widths; 
    1018     sizeY = heights; 
    1019     sizeZ = zs; 
    1020     sizeC = numChannels; 
    1021     sizeT = new int[numSeries]; 
    1022     pixelType = new int[numSeries]; 
    1023     currentOrder = new String[numSeries]; 
    1024     orderCertain = new boolean[numSeries]; 
    1025     Arrays.fill(orderCertain, true); 
     1002    core = new CoreMetadata(numSeries); 
     1003    Arrays.fill(core.orderCertain, true); 
    10261004 
    10271005    // sizeC is null here if the file we opened was a TIFF. 
    10281006    // However, the sizeC field will be adjusted anyway by 
    10291007    // a later call to BaseTiffReader.initMetadata. 
    1030     if (sizeC != null) { 
     1008    if (core.sizeC != null) { 
    10311009      try { 
    10321010        int oldSeries = getSeries(currentId); 
    1033         for (int i=0; i<sizeC.length; i++) { 
     1011        for (int i=0; i<core.sizeC.length; i++) { 
    10341012          setSeries(currentId, i); 
    10351013          if (!ignoreColorTable) { 
    1036             if (isRGB(currentId)) sizeC[i] = 3; 
    1037             else sizeC[i] = 1; 
     1014            if (isRGB(currentId)) core.sizeC[i] = 3; 
     1015            else core.sizeC[i] = 1; 
    10381016          } 
    10391017          else { 
    1040             sizeZ[i] /= sizeC[i]; 
     1018            core.sizeZ[i] /= core.sizeC[i]; 
    10411019          } 
    10421020        } 
     
    10541032 
    10551033    if (v != null) { 
    1056       validBits = new int[sizeC.length][]; 
     1034      validBits = new int[core.sizeC.length][]; 
    10571035 
    10581036      for (int i=0; i<validBits.length; i++) { 
    1059         validBits[i] = new int[sizeC[i] == 2 ? 3 : sizeC[i]]; 
     1037        validBits[i] = new int[core.sizeC[i] == 2 ? 3 : core.sizeC[i]]; 
    10601038        for (int j=0; j<validBits[i].length; j++) { 
    10611039          validBits[i][j] = v.intValue(); 
     
    10781056 
    10791057    for (int i=0; i<numSeries; i++) { 
    1080       orderCertain[i] = true; 
    1081  
    1082       if (sizeC[i] == 0) sizeC[i] = 1; 
    1083       sizeT[i] += 1; 
    1084       currentOrder[i] = sizeC[i] == 1 ? "XYZTC" : "XYCZT"; 
    1085       if (sizeZ[i] == 0) sizeZ[i] = 1; 
     1058      core.orderCertain[i] = true; 
     1059 
     1060      if (core.sizeC[i] == 0) core.sizeC[i] = 1; 
     1061      core.sizeT[i] += 1; 
     1062      core.currentOrder[i] = core.sizeC[i] == 1 ? "XYZTC" : "XYCZT"; 
     1063      if (core.sizeZ[i] == 0) core.sizeZ[i] = 1; 
    10861064 
    10871065      int tPixelType = ((Integer) getMeta("Bytes per pixel")).intValue(); 
    10881066      switch (tPixelType) { 
    10891067        case 1: 
    1090           pixelType[i] = FormatTools.UINT8; 
     1068          core.pixelType[i] = FormatTools.UINT8; 
    10911069          break; 
    10921070        case 2: 
    1093           pixelType[i] = FormatTools.UINT16; 
     1071          core.pixelType[i] = FormatTools.UINT16; 
    10941072          break; 
    10951073        case 3: 
    1096           pixelType[i] = FormatTools.UINT8; 
     1074          core.pixelType[i] = FormatTools.UINT8; 
    10971075          break; 
    10981076        case 4: 
    1099           pixelType[i] = FormatTools.INT32; 
     1077          core.pixelType[i] = FormatTools.INT32; 
    11001078          break; 
    11011079        case 6: 
    1102           pixelType[i] = FormatTools.INT16; 
     1080          core.pixelType[i] = FormatTools.INT16; 
    11031081          break; 
    11041082        case 8: 
    1105           pixelType[i] = FormatTools.DOUBLE; 
     1083          core.pixelType[i] = FormatTools.DOUBLE; 
    11061084          break; 
    11071085      } 
     
    11101088 
    11111089      store.setPixels( 
    1112         new Integer(widths[i]), 
    1113         new Integer(heights[i]), 
    1114         new Integer(zs[i]), 
    1115         new Integer(numChannels[i] == 0 ? 1 : numChannels[i]), // SizeC 
    1116         new Integer(sizeT[i]), // SizeT 
    1117         new Integer(pixelType[i]), // PixelType 
     1090        new Integer(core.sizeX[i]), 
     1091        new Integer(core.sizeY[i]), 
     1092        new Integer(core.sizeZ[i]), 
     1093        new Integer(core.sizeC[i] == 0 ? 1 : core.sizeC[i]), // SizeC 
     1094        new Integer(core.sizeT[i]), // SizeT 
     1095        new Integer(core.pixelType[i]), // PixelType 
    11181096        new Boolean(!littleEndian), // BigEndian 
    1119         "XYZTC", // DimensionOrder 
     1097        core.currentOrder[i], // DimensionOrder 
    11201098        ii, null); 
    11211099 
     
    11331111      store.setImage(null, timestamp, description, ii); 
    11341112 
    1135       for (int j=0; j<sizeC[0]; j++) { 
     1113      for (int j=0; j<core.sizeC[0]; j++) { 
    11361114        store.setLogicalChannel(j, null, null, null, null, null, null, ii); 
    11371115        // TODO : get channel min/max from metadata  
     
    11651143  } 
    11661144 
    1167   // -- Main method -- 
    1168  
    1169   public static void main(String[] args) throws FormatException, IOException { 
    1170     new LeicaReader().testRead(args); 
    1171   } 
    1172  
    11731145} 
  • trunk/loci/formats/in/MNGReader.java

    r2535 r2557  
    4545  protected int numImages = 0; 
    4646 
    47   /** Frame dimensions. */ 
    48   private int width, height; 
    49  
    5047  /** Offsets to each plane. */ 
    5148  private Vector offsets; 
     
    6158  // -- FormatReader API methods -- 
    6259 
    63   /** Checks if the given block is a valid header for an MNG file. */ 
     60  /* @see loci.formats.IFormatReader#isThisType(byte[]) */  
    6461  public boolean isThisType(byte[] block) { 
    6562    if (block.length < 8) return false; 
     
    6966  } 
    7067 
    71   /** Determines the number of images in the given MNG file. */ 
     68  /* @see loci.formats.IFormatReader#getImageCount(String) */  
    7269  public int getImageCount(String id) throws FormatException, IOException { 
    7370    if (!id.equals(currentId)) initFile(id); 
     
    7572  } 
    7673 
    77   /** Checks if the images in the file are RGB. */ 
     74  /* @see loci.formats.IFormatReader#isRGB(String) */  
    7875  public boolean isRGB(String id) throws FormatException, IOException { 
    7976    if (!id.equals(currentId)) initFile(id); 
    80     return getSizeC(id) > 1; 
    81   } 
    82  
    83   /** Return true if the data is in little-endian format. */ 
     77    return core.sizeC[0] > 1; 
     78  } 
     79 
     80  /* @see loci.formats.IFormatReader#isLittleEndian(String) */  
    8481  public boolean isLittleEndian(String id) throws FormatException, IOException { 
    8582    return false; 
    8683  } 
    8784 
    88   /** Returns whether or not the channels are interleaved. */ 
     85  /* @see loci.formats.IFormatReader#isInterleaved(String) */  
    8986  public boolean isInterleaved(String id, int subC) 
    9087    throws FormatException, IOException 
     
    9390  } 
    9491 
    95   /** 
    96    * Obtains the specified image from the 
    97    * given MNG file as a byte array. 
    98    */ 
     92  /* @see loci.formats.IFormatReader#openBytes(String, int) */  
    9993  public byte[] openBytes(String id, int no) 
    10094    throws FormatException, IOException 
    10195  { 
    102     byte[] b = ImageTools.getBytes(openImage(id, no), true, getSizeC(id)); 
    103     return b; 
    104   } 
    105  
    106   /** Obtains the specified image from the given MNG file. */ 
     96    return ImageTools.getBytes(openImage(id, no), true, core.sizeC[0]); 
     97  } 
     98 
     99  /* @see loci.formats.IFormatReader#openImage(String, int) */  
    107100  public BufferedImage openImage(String id, int no) 
    108101    throws FormatException, IOException 
     
    128121    b[7] = 0x0a; 
    129122 
    130     BufferedImage bi = ImageIO.read(new ByteArrayInputStream(b)); 
    131     return bi; 
     123    return ImageIO.read(new ByteArrayInputStream(b)); 
    132124  } 
    133125 
     
    138130  } 
    139131 
    140   /** Closes any open files. */ 
     132  /* @see loci.formats.IFormatReader#close() */  
    141133  public void close() throws FormatException, IOException { 
    142134    if (in != null) in.close(); 
     
    167159    status("Reading dimensions"); 
    168160 
    169     width = (int) DataTools.read4UnsignedBytes(in, false); 
    170     height = (int) DataTools.read4UnsignedBytes(in, false); 
     161    core.sizeX[0] = (int) DataTools.read4UnsignedBytes(in, false); 
     162    core.sizeY[0] = (int) DataTools.read4UnsignedBytes(in, false); 
    171163    long fps = DataTools.read4UnsignedBytes(in, false); 
    172164    long layerCounter = DataTools.read4UnsignedBytes(in, false); 
     
    221213    status("Populating metadata"); 
    222214 
    223     sizeX[0] = width; 
    224     sizeY[0] = height; 
    225     sizeZ[0] = 1; 
    226     sizeC[0] = openImage(id, 0).getRaster().getNumBands(); 
    227     sizeT[0] = numImages; 
    228     currentOrder[0] = "XYCZT"; 
    229     pixelType[0] = FormatTools.UINT8; 
     215    core.sizeZ[0] = 1; 
     216    core.sizeC[0] = openImage(id, 0).getRaster().getNumBands(); 
     217    core.sizeT[0] = numImages; 
     218    core.currentOrder[0] = "XYCZT"; 
     219    core.pixelType[0] = FormatTools.UINT8; 
    230220 
    231221    MetadataStore store = getMetadataStore(id); 
    232222 
    233     store.setPixels(new Integer(width), new Integer(height), new Integer(1), 
    234       new Integer(sizeC[0]), new Integer(numImages), new Integer(pixelType[0]), 
    235       Boolean.TRUE, currentOrder[0], null, null); 
    236     for (int i=0; i<sizeC[0]; i++) { 
     223    store.setPixels(new Integer(core.sizeX[0]), new Integer(core.sizeY[0]),  
     224      new Integer(core.sizeZ[0]), new Integer(core.sizeC[0]),  
     225      new Integer(core.sizeT[0]), new Integer(core.pixelType[0]), 
     226      Boolean.TRUE, core.currentOrder[0], null, null); 
     227    for (int i=0; i<core.sizeC[0]; i++) { 
    237228      store.setLogicalChannel(i, null, null, null, null, null, null, null); 
    238229    } 
    239230  } 
    240231 
    241   // -- Main method -- 
    242  
    243   public static void main(String[] args) throws FormatException, IOException { 
    244     new MNGReader().testRead(args); 
    245   } 
    246  
    247232} 
  • trunk/loci/formats/in/MRCReader.java

    r2535 r2557  
    6565  // -- IFormatReader API methods -- 
    6666 
    67   /** Checks if the given block is a valid header for an MRC file. */ 
     67  /* @