Changeset 3204


Ignore:
Timestamp:
10/01/07 11:49:55 (12 years ago)
Author:
melissa
Message:

Removed obsolete 'valid bits' logic; minor cleanup/bugfixes.

Location:
trunk/loci/formats
Files:
14 edited

Legend:

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

    r3197 r3204  
    110110  public BufferedImage openImage(int no) throws FormatException, IOException { 
    111111    FormatTools.assertId(getCurrentFile(), true, 2); 
    112     if (no < 0 || no >= getImageCount()) { 
    113       throw new FormatException("Invalid image number: " + no); 
    114     } 
     112    FormatTools.checkPlaneNumber(this, no); 
    115113 
    116114    if (isIndexed()) return reader.openImage(no); 
     
    137135  public byte[] openBytes(int no) throws FormatException, IOException { 
    138136    FormatTools.assertId(getCurrentFile(), true, 2); 
    139     if (no < 0 || no >= getImageCount()) { 
    140       throw new FormatException("Invalid image number: " + no); 
    141     } 
     137    FormatTools.checkPlaneNumber(this, no); 
    142138 
    143139    if (reader.isRGB() && !reader.isIndexed()) { 
     
    169165  } 
    170166 
     167  /* @see IFormatReader#close() */ 
    171168  public void close() throws IOException { 
    172169    super.close(); 
  • trunk/loci/formats/ImageTools.java

    r3197 r3204  
    6666    boolean interleaved, int bps, boolean little) 
    6767  { 
    68     return makeImage(data, w, h, c, interleaved, bps, little, null); 
    69   } 
    70  
    71   /** 
    72    * Creates an image from the given data, performing type conversions as 
    73    * necessary. 
    74    * If the interleaved flag is set, the channels are assumed to be 
    75    * interleaved; otherwise they are assumed to be sequential. 
    76    * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, 
    77    * while "RRR...GGG...BBB..." is sequential. 
    78    * 
    79    * The 'bits' argument specifies the number of significant bits per 
    80    * color component; if it is null, then all of the bits are used. 
    81    */ 
    82   public static BufferedImage makeImage(byte[] data, int w, int h, int c, 
    83     boolean interleaved, int bps, boolean little, int[] bits) 
    84   { 
    8568    Object pixels = DataTools.makeDataArray(data, bps % 3 == 0 ? bps / 3 : bps, 
    8669      false, little); 
    8770 
    8871    if (pixels instanceof byte[]) { 
    89       return makeImage((byte[]) pixels, w, h, c, interleaved, bits); 
     72      return makeImage((byte[]) pixels, w, h, c, interleaved); 
    9073    } 
    9174    else if (pixels instanceof short[]) { 
    92       return makeImage((short[]) pixels, w, h, c, interleaved, bits); 
     75      return makeImage((short[]) pixels, w, h, c, interleaved); 
    9376    } 
    9477    else if (pixels instanceof int[]) { 
    95       return makeImage((int[]) pixels, w, h, c, interleaved, bits); 
     78      return makeImage((int[]) pixels, w, h, c, interleaved); 
    9679    } 
    9780    else if (pixels instanceof float[]) { 
    98       return makeImage((float[]) pixels, w, h, c, interleaved, bits); 
     81      return makeImage((float[]) pixels, w, h, c, interleaved); 
    9982    } 
    10083    else if (pixels instanceof double[]) { 
    101       return makeImage((double[]) pixels, w, h, c, interleaved, bits); 
     84      return makeImage((double[]) pixels, w, h, c, interleaved); 
    10285    } 
    10386    return null; 
     
    11497    int w, int h, int c, boolean interleaved) 
    11598  { 
    116     return makeImage(data, w, h, c, interleaved, null); 
    117   } 
    118  
    119   /** 
    120    * Creates an image from the given unsigned byte data. 
    121    * If the interleaved flag is set, the channels are assumed to be 
    122    * interleaved; otherwise they are assumed to be sequential. 
    123    * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, 
    124    * while "RRR...GGG...BBB..." is sequential. 
    125    * 
    126    * The 'bits' argument specifies the number of significant bits per 
    127    * color component; if it is null, then all of the bits are used. 
    128    */ 
    129   public static BufferedImage makeImage(byte[] data, 
    130     int w, int h, int c, boolean interleaved, int[] bits) 
    131   { 
    132     if (c == 1) return makeImage(data, w, h, bits); 
     99    if (c == 1) return makeImage(data, w, h); 
    133100    int dataType = DataBuffer.TYPE_BYTE; 
    134101    if (c == 2) { 
     
    145112    } 
    146113    DataBuffer buffer = new DataBufferByte(data, c * w * h); 
    147     return constructImage(c, dataType, w, h, interleaved, buffer, bits); 
     114    return constructImage(c, dataType, w, h, interleaved, buffer); 
    148115  } 
    149116 
     
    158125    int w, int h, int c, boolean interleaved) 
    159126  { 
    160     return makeImage(data, w, h, c, interleaved, null); 
    161   } 
    162  
    163   /** 
    164    * Creates an image from the given unsigned short data. 
    165    * If the interleaved flag is set, the channels are assumed to be 
    166    * interleaved; otherwise they are assumed to be sequential. 
    167    * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, 
    168    * while "RRR...GGG...BBB..." is sequential. 
    169    * 
    170    * The 'bits' argument specifies the number of significant bits per 
    171    * color component; if it is null, then all of the bits are used. 
    172    */ 
    173   public static BufferedImage makeImage(short[] data, 
    174     int w, int h, int c, boolean interleaved, int[] bits) 
    175   { 
    176     if (c == 1) return makeImage(data, w, h, bits); 
     127    if (c == 1) return makeImage(data, w, h); 
    177128    int dataType = DataBuffer.TYPE_USHORT; 
    178129    if (c == 2) { 
     
    189140    } 
    190141    DataBuffer buffer = new DataBufferUShort(data, c * w * h); 
    191     return constructImage(c, dataType, w, h, interleaved, buffer, bits); 
     142    return constructImage(c, dataType, w, h, interleaved, buffer); 
    192143  } 
    193144 
     
    202153    int w, int h, int c, boolean interleaved) 
    203154  { 
    204     return makeImage(data, w, h, c, interleaved, null); 
    205   } 
    206  
    207   /** 
    208    * Creates an image from the given signed int data. 
    209    * If the interleaved flag is set, the channels are assumed to be 
    210    * interleaved; otherwise they are assumed to be sequential. 
    211    * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, 
    212    * while "RRR...GGG...BBB..." is sequential. 
    213    * 
    214    * The 'bits' argument specifies the number of significant bits per 
    215    * color component; if it is null, then all of the bits are used. 
    216    */ 
    217   public static BufferedImage makeImage(int[] data, 
    218     int w, int h, int c, boolean interleaved, int[] bits) 
    219   { 
    220     if (c == 1) return makeImage(data, w, h, bits); 
     155    if (c == 1) return makeImage(data, w, h); 
    221156    int dataType = DataBuffer.TYPE_INT; 
    222157    if (c == 2) { 
     
    233168    } 
    234169    DataBuffer buffer = new DataBufferInt(data, c * w * h); 
    235     return constructImage(c, dataType, w, h, interleaved, buffer, bits); 
     170    return constructImage(c, dataType, w, h, interleaved, buffer); 
    236171  } 
    237172 
     
    246181    int w, int h, int c, boolean interleaved) 
    247182  { 
    248     return makeImage(data, w, h, c, interleaved, null); 
    249   } 
    250  
    251   /** 
    252    * Creates an image from the given float data. 
    253    * If the interleaved flag is set, the channels are assumed to be 
    254    * interleaved; otherwise they are assumed to be sequential. 
    255    * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, 
    256    * while "RRR...GGG...BBB..." is sequential. 
    257    * 
    258    * The 'bits' argument specifies the number of significant bits per 
    259    * color component; if it is null, then all of the bits are used. 
    260    */ 
    261   public static BufferedImage makeImage(float[] data, 
    262     int w, int h, int c, boolean interleaved, int[] bits) 
    263   { 
    264     if (c == 1) return makeImage(data, w, h, bits); 
     183    if (c == 1) return makeImage(data, w, h); 
    265184    int dataType = DataBuffer.TYPE_FLOAT; 
    266185    if (c == 2) { 
     
    277196    } 
    278197    DataBuffer buffer = new DataBufferFloat(data, c * w * h); 
    279     return constructImage(c, dataType, w, h, interleaved, buffer, bits); 
     198    return constructImage(c, dataType, w, h, interleaved, buffer); 
    280199  } 
    281200 
     
    290209    int w, int h, int c, boolean interleaved) 
    291210  { 
    292     return makeImage(data, w, h, c, interleaved, null); 
    293   } 
    294  
    295   /** 
    296    * Creates an image from the given double data. 
    297    * If the interleaved flag is set, the channels are assumed to be 
    298    * interleaved; otherwise they are assumed to be sequential. 
    299    * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, 
    300    * while "RRR...GGG...BBB..." is sequential. 
    301    * 
    302    * The 'bits' argument specifies the number of significant bits per 
    303    * color component; if it is null, then all of the bits are used. 
    304    */ 
    305   public static BufferedImage makeImage(double[] data, 
    306     int w, int h, int c, boolean interleaved, int[] bits) 
    307   { 
    308  
    309     if (c == 1) return makeImage(data, w, h, bits); 
     211    if (c == 1) return makeImage(data, w, h); 
    310212    int dataType = DataBuffer.TYPE_DOUBLE; 
    311213    if (c == 2) { 
     
    322224    } 
    323225    DataBuffer buffer = new DataBufferDouble(data, c * w * h); 
    324     return constructImage(c, dataType, w, h, interleaved, buffer, bits); 
     226    return constructImage(c, dataType, w, h, interleaved, buffer); 
    325227  } 
    326228 
     
    336238    int bps, boolean little) 
    337239  { 
    338     return makeImage(data, w, h, bps, little, null); 
    339   } 
    340  
    341   /** 
    342    * Creates an image from the given data, performing type conversions as 
    343    * necessary. 
    344    * If the interleaved flag is set, the channels are assumed to be 
    345    * interleaved; otherwise they are assumed to be sequential. 
    346    * For example, for RGB data, the pattern "RGBRGBRGB..." is interleaved, 
    347    * while "RRR...GGG...BBB..." is sequential. 
    348    * 
    349    * The 'bits' argument specifies the number of significant bits per 
    350    * color component; if it is null, then all of the bits are used. 
    351    */ 
    352   public static BufferedImage makeImage(byte[][] data, int w, int h, 
    353     int bps, boolean little, int[] bits) 
    354   { 
    355     if (bps == 1) return makeImage(data, w, h, bits); 
     240    if (bps == 1) return makeImage(data, w, h); 
    356241    else if (bps == 2) { 
    357242      short[][] shorts = new short[data.length][data[0].length / bps]; 
     
    361246        } 
    362247      } 
    363       return makeImage(shorts, w, h, bits); 
     248      return makeImage(shorts, w, h); 
    364249    } 
    365250    else if (bps == 4) { 
     
    371256        } 
    372257      } 
    373       return makeImage(floats, w, h, bits); 
     258      return makeImage(floats, w, h); 
    374259    } 
    375260    else { 
     
    381266        } 
    382267      } 
    383       return makeImage(doubles, w, h, bits); 
     268      return makeImage(doubles, w, h); 
    384269    } 
    385270  } 
     
    391276   */ 
    392277  public static BufferedImage makeImage(byte[][] data, int w, int h) { 
    393     return makeImage(data, w, h, null); 
    394   } 
    395  
    396   /** 
    397    * Creates an image from the given unsigned byte data. 
    398    * It is assumed that each channel corresponds to one element of the array. 
    399    * For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B. 
    400    * 
    401    * The 'bits' argument specifies the number of significant bits per 
    402    * color component; if it is null, then all of the bits are used. 
    403    */ 
    404   public static BufferedImage makeImage(byte[][] data, int w, int h, int[] bits) 
    405   { 
    406278    int dataType = DataBuffer.TYPE_BYTE; 
    407     ColorModel colorModel = makeColorModel(data.length, dataType, bits); 
     279    ColorModel colorModel = makeColorModel(data.length, dataType); 
    408280    if (colorModel == null) return null; 
    409281    SampleModel model = new BandedSampleModel(dataType, w, h, data.length); 
     
    419291   */ 
    420292  public static BufferedImage makeImage(short[][] data, int w, int h) { 
    421     return makeImage(data, w, h, null); 
    422   } 
    423  
    424   /** 
    425    * Creates an image from the given unsigned short data. 
    426    * It is assumed that each channel corresponds to one element of the array. 
    427    * For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B. 
    428    * 
    429    * The 'bits' argument specifies the number of significant bits per 
    430    * color component; if it is null, then all of the bits are used. 
    431    */ 
    432   public static BufferedImage makeImage(short[][] data, int w, int h, 
    433     int[] bits) 
    434   { 
    435293    int dataType = DataBuffer.TYPE_USHORT; 
    436     ColorModel colorModel = makeColorModel(data.length, dataType, bits); 
     294    ColorModel colorModel = makeColorModel(data.length, dataType); 
    437295    if (colorModel == null) return null; 
    438296    SampleModel model = new BandedSampleModel(dataType, w, h, data.length); 
     
    448306   */ 
    449307  public static BufferedImage makeImage(int[][] data, int w, int h) { 
    450     return makeImage(data, w, h, null); 
    451   } 
    452  
    453   /** 
    454    * Creates an image from the given signed int data. 
    455    * It is assumed that each channel corresponds to one element of the array. 
    456    * For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B. 
    457    * 
    458    * The 'bits' argument specifies the number of significant bits per 
    459    * color component; if it is null, then all of the bits are used. 
    460    */ 
    461   public static BufferedImage makeImage(int[][] data, int w, int h, int[] bits) 
    462   { 
    463308    int dataType = DataBuffer.TYPE_INT; 
    464     ColorModel colorModel = makeColorModel(data.length, dataType, bits); 
     309    ColorModel colorModel = makeColorModel(data.length, dataType); 
    465310    if (colorModel == null) return null; 
    466311    SampleModel model = new BandedSampleModel(dataType, w, h, data.length); 
     
    476321   */ 
    477322  public static BufferedImage makeImage(float[][] data, int w, int h) { 
    478     return makeImage(data, w, h, null); 
    479   } 
    480  
    481   /** 
    482    * Creates an image from the given single-precision floating point data. 
    483    * It is assumed that each channel corresponds to one element of the array. 
    484    * For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B. 
    485    * 
    486    * The 'bits' argument specifies the number of significant bits per 
    487    * color component; if it is null, then all of the bits are used. 
    488    */ 
    489   public static BufferedImage makeImage(float[][] data, int w, int h, 
    490     int[] bits) 
    491   { 
    492323    int dataType = DataBuffer.TYPE_FLOAT; 
    493     ColorModel colorModel = makeColorModel(data.length, dataType, bits); 
     324    ColorModel colorModel = makeColorModel(data.length, dataType); 
    494325    if (colorModel == null) return null; 
    495326    SampleModel model = new BandedSampleModel(dataType, w, h, data.length); 
     
    505336   */ 
    506337  public static BufferedImage makeImage(double[][] data, int w, int h) { 
    507     return makeImage(data, w, h, null); 
    508   } 
    509  
    510   /** 
    511    * Creates an image from the given double-precision floating point data. 
    512    * It is assumed that each channel corresponds to one element of the array. 
    513    * For example, for RGB data, data[0] is R, data[1] is G, and data[2] is B. 
    514    * 
    515    * The 'bits' argument specifies the number of significant bits per 
    516    * color component; if it is null, then all of the bits are used. 
    517    */ 
    518   public static BufferedImage makeImage(double[][] data, int w, int h, 
    519     int[] bits) 
    520   { 
    521338    int dataType = DataBuffer.TYPE_DOUBLE; 
    522     ColorModel colorModel = makeColorModel(data.length, dataType, bits); 
     339    ColorModel colorModel = makeColorModel(data.length, dataType); 
    523340    if (colorModel == null) return null; 
    524341    SampleModel model = new BandedSampleModel(dataType, w, h, data.length); 
     
    530347  /** Creates an image from the given single-channel unsigned byte data. */ 
    531348  public static BufferedImage makeImage(byte[] data, int w, int h) { 
    532     return makeImage(data, w, h, null); 
    533   } 
    534  
    535   /** 
    536    * Creates an image from the given single-channel unsigned byte data. 
    537    * The 'bits' argument specifies the number of significant bits per 
    538    * color component; if it is null, then all of the bits are used. 
    539    */ 
    540   public static BufferedImage makeImage(byte[] data, int w, int h, int[] bits) { 
    541     return makeImage(new byte[][] {data}, w, h, bits); 
     349    return makeImage(new byte[][] {data}, w, h); 
    542350  } 
    543351 
    544352  /** Creates an image from the given single-channel unsigned short data. */ 
    545353  public static BufferedImage makeImage(short[] data, int w, int h) { 
    546     return makeImage(data, w, h, null); 
    547   } 
    548  
    549   /** 
    550    * Creates an image from the given single-channel unsigned short data. 
    551    * The 'bits' argument specifies the number of significant bits per 
    552    * color component; if it is null, then all of the bits are used. 
    553    */ 
    554   public static BufferedImage makeImage(short[] data, int w, int h, int[] bits) 
    555   { 
    556     return makeImage(new short[][] {data}, w, h, bits); 
     354    return makeImage(new short[][] {data}, w, h); 
    557355  } 
    558356 
    559357  /** Creates an image from the given single-channel signed int data. */ 
    560358  public static BufferedImage makeImage(int[] data, int w, int h) { 
    561     return makeImage(data, w, h, null); 
    562   } 
    563  
    564   /** 
    565    * Creates an image from the given single-channel signed int data. 
    566    * The 'bits' argument specifies the number of significant bits per 
    567    * color component; if it is null, then all of the bits are used. 
    568    */ 
    569   public static BufferedImage makeImage(int[] data, int w, int h, int[] bits) { 
    570     return makeImage(new int[][] {data}, w, h, bits); 
     359    return makeImage(new int[][] {data}, w, h); 
    571360  } 
    572361 
    573362  /** Creates an image from the given single-channel float data. */ 
    574363  public static BufferedImage makeImage(float[] data, int w, int h) { 
    575     return makeImage(data, w, h, null); 
    576   } 
    577  
    578   /** 
    579    * Creates an image from the given single-channel double data. 
    580    * The 'bits' argument specifies the number of significant bits per 
    581    * color component; if it is null, then all of the bits are used. 
    582    */ 
    583   public static BufferedImage makeImage(float[] data, int w, int h, int[] bits) 
    584   { 
    585     return makeImage(new float[][] {data}, w, h, bits); 
     364    return makeImage(new float[][] {data}, w, h); 
    586365  } 
    587366 
    588367  /** Creates an image from the given single-channel double data. */ 
    589368  public static BufferedImage makeImage(double[] data, int w, int h) { 
    590     return makeImage(data, w, h, null); 
    591   } 
    592  
    593   /** 
    594    * Creates an image from the given single-channel double data. 
    595    * The 'bits' argument specifies the number of significant bits per 
    596    * color component; if it is null, then all of the bits are used. 
    597    */ 
    598   public static BufferedImage makeImage(double[] data, int w, int h, int[] bits) 
    599   { 
    600     return makeImage(new double[][] {data}, w, h, bits); 
     369    return makeImage(new double[][] {data}, w, h); 
    601370  } 
    602371 
     
    631400    } 
    632401 
    633     return constructImage(c, tt, w, h, true, buffer, null); 
     402    return constructImage(c, tt, w, h, true, buffer); 
    634403  } 
    635404 
    636405  /** Create an image with the given DataBuffer. */ 
    637406  private static BufferedImage constructImage(int c, int type, int w, 
    638     int h, boolean interleaved, DataBuffer buffer, int[] bits) 
    639   { 
    640     ColorModel colorModel = makeColorModel(c, type, bits); 
     407    int h, boolean interleaved, DataBuffer buffer) 
     408  { 
     409    ColorModel colorModel = makeColorModel(c, type); 
    641410    if (colorModel == null) return null; 
    642411    int pixelStride = interleaved ? c : 1; 
     
    689458    // convert to image with DataBufferByte and BandedSampleModel 
    690459    int w = image.getWidth(), h = image.getHeight(), c = r.getNumBands(); 
    691     ColorModel colorModel = makeColorModel(c, dataType, null); 
     460    ColorModel colorModel = makeColorModel(c, dataType); 
    692461    if (colorModel == null) return null; 
    693462    SampleModel model = new BandedSampleModel(dataType, w, h, c); 
     
    896665    WritableRaster r = image.getRaster(); 
    897666    int w = image.getWidth(), h = image.getHeight(), c = r.getNumBands(); 
    898     ColorModel colorModel = makeColorModel(c, type, null); 
     667    ColorModel colorModel = makeColorModel(c, type); 
    899668    if (colorModel == null) return null; 
    900669 
     
    1153922    if (c == 2) c = 3; // blank B channel 
    1154923 
    1155     int[] validBits = images[0].getColorModel().getComponentSize(); 
    1156     if (validBits.length < images.length) { 
    1157       int vb = validBits[0]; 
    1158       validBits = new int[c]; 
    1159       for (int i=0; i<validBits.length; i++) validBits[i] = vb; 
    1160     } 
    1161  
    1162924    // compile results into a single array 
    1163925    int w = images[0].getWidth(), h = images[0].getHeight(); 
     
    1170932      } 
    1171933      while (ndx < pix.length) pix[ndx++] = new byte[w * h]; // blank channel 
    1172       return makeImage(pix, w, h, validBits); 
     934      return makeImage(pix, w, h); 
    1173935    } 
    1174936    if (type == DataBuffer.TYPE_USHORT) { 
     
    1180942      } 
    1181943      while (ndx < pix.length) pix[ndx++] = new short[w * h]; // blank channel 
    1182       return makeImage(pix, w, h, validBits); 
     944      return makeImage(pix, w, h); 
    1183945    } 
    1184946    if (type == DataBuffer.TYPE_INT) { 
     
    1190952      } 
    1191953      while (ndx < pix.length) pix[ndx++] = new int[w * h]; // blank channel 
    1192       return makeImage(pix, w, h, validBits); 
     954      return makeImage(pix, w, h); 
    1193955    } 
    1194956    if (type == DataBuffer.TYPE_FLOAT) { 
     
    1200962      } 
    1201963      while (ndx < pix.length) pix[ndx++] = new float[w * h]; // blank channel 
    1202       return makeImage(pix, w, h, validBits); 
     964      return makeImage(pix, w, h); 
    1203965    } 
    1204966    if (type == DataBuffer.TYPE_DOUBLE) { 
     
    1210972      } 
    1211973      while (ndx < pix.length) pix[ndx++] = new double[w * h]; // blank channel 
    1212       return makeImage(pix, w, h, validBits); 
     974      return makeImage(pix, w, h); 
    1213975    } 
    1214976 
     
    19931755 
    19941756  /** Gets a color space for the given number of color components. */ 
    1995   public static ColorModel makeColorModel(int c, int dataType, int[] bits) { 
     1757  public static ColorModel makeColorModel(int c, int dataType) { 
    19961758    int type; 
    19971759    switch (c) { 
     
    20111773        return null; 
    20121774    } 
    2013     if (bits != null) { 
    2014       return new ComponentColorModel(ColorSpace.getInstance(type), bits, 
    2015         c == 4, false, ColorModel.TRANSLUCENT, dataType); 
    2016     } 
    20171775    return new ComponentColorModel(ColorSpace.getInstance(type), c == 4, 
    20181776      false, ColorModel.TRANSLUCENT, dataType); 
  • trunk/loci/formats/TiffTools.java

    r3174 r3204  
    307307    // The following loosely resembles the logic of getIFD()... 
    308308    in.seek(offset); 
    309     int numEntries = in.readShort(); 
    310     if (numEntries < 0) numEntries += 65536; 
     309    int numEntries = in.readShort() & 0xffff; 
    311310 
    312311    for (int i = 0; i < numEntries; i++) { 
     
    315314        (BYTES_PER_ENTRY * i)); 
    316315 
    317       int entryTag = in.readShort(); 
    318       if (entryTag < 0) entryTag += 65536; 
     316      int entryTag = in.readShort() & 0xffff; 
    319317 
    320318      // Skip this tag unless it matches the one we want 
     
    322320 
    323321      // Parse the entry's "Type" 
    324       int entryType = in.readShort(); 
    325       if (entryType < 0) entryType += 65536; 
     322      int entryType = in.readShort() & 0xffff; 
    326323 
    327324      // Parse the entry's "ValueCount" 
     
    382379      debug("getIFDs: seeking IFD #" + ifdNum + " at " + offset); 
    383380    } 
    384     in.seek((int) offset); 
    385     int numEntries = in.readShort(); 
    386     if (numEntries < 0) numEntries += 65536; 
     381    in.seek(offset); 
     382    int numEntries = in.readShort() & 0xffff; 
    387383    if (DEBUG) debug("getIFDs: " + numEntries + " directory entries to read"); 
    388384    if (numEntries == 0 || numEntries == 1) return ifd; 
    389385 
    390386    for (int i=0; i<numEntries; i++) { 
    391       in.seek((int) (offset + 2 + 12 * i)); 
    392       int tag = in.readShort(); 
    393       if (tag < 0) tag += 65536; 
    394       int type = in.readShort(); 
    395       if (type < 0) type += 65536; 
     387      in.seek(offset + 2 + 12 * i); 
     388      int tag = in.readShort() & 0xffff; 
     389      int type = in.readShort() & 0xffff; 
    396390      int count = in.readInt(); 
    397391 
     
    407401        if (count > 4) { 
    408402          long pointer = in.readInt(); 
    409           in.seek((int) pointer); 
    410         } 
    411         if (count == 1) value = new Short((byte) in.read()); 
     403          in.seek(pointer); 
     404        } 
     405        if (count == 1) value = new Short(in.readByte()); 
    412406        else { 
    413407          short[] bytes = new short[count]; 
    414408          for (int j=0; j<count; j++) { 
    415             bytes[j] = (byte) in.read(); 
     409            bytes[j] = in.readByte(); 
    416410            if (bytes[j] < 0) bytes[j] += 255; 
    417411          } 
     
    425419        if (count > 4) { 
    426420          long pointer = in.readInt(); 
    427           in.seek((int) pointer); 
     421          in.seek(pointer); 
    428422        } 
    429423        in.read(ascii); 
     
    457451        if (count > 2) { 
    458452          long pointer = in.readInt(); 
    459           in.seek((int) pointer); 
     453          in.seek(pointer); 
    460454        } 
    461455        if (count == 1) value = new Integer(in.readShort()); 
     
    463457          int[] shorts = new int[count]; 
    464458          for (int j=0; j<count; j++) { 
    465             shorts[j] = in.readShort(); 
    466             if (shorts[j] < 0) shorts[j] += 65536; 
     459            shorts[j] = in.readShort() & 0xffff; 
    467460          } 
    468461          value = shorts; 
     
    473466        if (count > 1) { 
    474467          long pointer = in.readInt(); 
    475           in.seek((int) pointer); 
     468          in.seek(pointer); 
    476469        } 
    477470        if (count == 1) value = new Long(in.readInt()); 
     
    488481        // the second the denominator 
    489482        long pointer = in.readInt(); 
    490         in.seek((int) pointer); 
     483        in.seek(pointer); 
    491484        if (count == 1) value = new TiffRational(in.readInt(), in.readInt()); 
    492485        else { 
     
    504497        if (count > 4) { 
    505498          long pointer = in.readInt(); 
    506           in.seek((int) pointer); 
    507         } 
    508         if (count == 1) value = new Byte((byte) in.read()); 
     499          in.seek(pointer); 
     500        } 
     501        if (count == 1) value = new Byte(in.readByte()); 
    509502        else { 
    510503          byte[] sbytes = new byte[count]; 
     
    517510        if (count > 2) { 
    518511          long pointer = in.readInt(); 
    519           in.seek((int) pointer); 
     512          in.seek(pointer); 
    520513        } 
    521514        if (count == 1) value = new Short(in.readShort()); 
     
    530523        if (count > 1) { 
    531524          long pointer = in.readInt(); 
    532           in.seek((int) pointer); 
     525          in.seek(pointer); 
    533526        } 
    534527        if (count == 1) value = new Integer(in.readInt()); 
     
    543536        if (count > 1) { 
    544537          long pointer = in.readInt(); 
    545           in.seek((int) pointer); 
     538          in.seek(pointer); 
    546539        } 
    547540        if (count == 1) value = new Float(in.readFloat()); 
     
    555548        // Double precision (8-byte) IEEE format 
    556549        long pointer = in.readInt(); 
    557         in.seek((int) pointer); 
     550        in.seek(pointer); 
    558551        if (count == 1) value = new Double(in.readDouble()); 
    559552        else { 
     
    567560      if (value != null) ifd.put(new Integer(tag), value); 
    568561    } 
    569     in.seek((int) (offset + 2 + 12 * numEntries)); 
     562    in.seek(offset + 2 + 12 * numEntries); 
    570563 
    571564    return ifd; 
     
    850843    long[] maxes = getIFDLongArray(ifd, MAX_SAMPLE_VALUE, false); 
    851844    long maxValue = maxes == null ? 0 : maxes[0]; 
    852  
    853     if (ifd.get(new Integer(VALID_BITS)) == null && bitsPerSample[0] > 0) { 
    854       int[] validBits = bitsPerSample; 
    855       putIFDValue(ifd, VALID_BITS, validBits); 
    856     } 
    857845 
    858846    if (isTiled) { 
     
    13731361    int photoInterp = getPhotometricInterpretation(ifd); 
    13741362 
    1375     int[] validBits = getIFDIntArray(ifd, VALID_BITS, false); 
    1376  
    13771363    if (bitsPerSample[0] == 16 || bitsPerSample[0] == 12) { 
    13781364      // First wrap the byte arrays and then use the features of the 
     
    14111397        } 
    14121398        return ImageTools.makeImage(floatData, 
    1413           (int) imageWidth, (int) imageLength, validBits); 
     1399          (int) imageWidth, (int) imageLength); 
    14141400      } 
    14151401      else { 
     
    14291415 
    14301416        return ImageTools.makeImage(shortData, 
    1431           (int) imageWidth, (int) imageLength, validBits); 
     1417          (int) imageWidth, (int) imageLength); 
    14321418      } 
    14331419    } 
    14341420    if (samplesPerPixel == 1) { 
    14351421      return ImageTools.makeImage(samples[0], (int) imageWidth, 
    1436         (int) imageLength, 1, false, validBits); 
     1422        (int) imageLength, 1, false); 
    14371423    } 
    14381424 
     
    14431429      samples = s; 
    14441430    } 
    1445     return ImageTools.makeImage(samples, (int) imageWidth, (int) imageLength, 
    1446       validBits); 
     1431    return ImageTools.makeImage(samples, (int) imageWidth, (int) imageLength); 
    14471432  } 
    14481433 
  • trunk/loci/formats/in/EPSReader.java

    r3197 r3204  
    123123 
    124124      for (int i=0; i<buf.length; i++) { 
    125         chars[0] = (char) ras.read(); 
    126         while (chars[0] == '\n') chars[0] = (char) ras.read(); 
    127         chars[1] = (char) ras.read(); 
    128         while (chars[1] == '\n') chars[1] = (char) ras.read(); 
     125        chars[0] = ras.readChar(); 
     126        while (chars[0] == '\n') chars[0] = ras.readChar(); 
     127        chars[1] = ras.readChar(); 
     128        while (chars[1] == '\n') chars[1] = ras.readChar(); 
    129129        String s = new String(chars); 
    130130        buf[i] = (byte) Integer.parseInt(s, 16); 
  • trunk/loci/formats/in/FluoviewReader.java

    r3197 r3204  
    118118    } 
    119119    FormatTools.assertId(currentId, true, 1); 
    120     if (no < 0 || no >= core.imageCount[0]) { 
    121       throw new FormatException("Invalid image number: " + no); 
    122     } 
    123     if (buf.length < core.sizeX[0] * 
    124       FormatTools.getBytesPerPixel(core.pixelType[0])) 
    125     { 
    126       throw new FormatException("Buffer too small."); 
    127     } 
     120    FormatTools.checkPlaneNumber(this, no); 
     121    FormatTools.checkBufferSize(this, buf.length); 
    128122 
    129123    byte[] b = new byte[core.sizeX[0] * 
     
    188182 
    189183    put("Header Flag", ras.readShort()); 
    190     put("Image Type", (char) ras.read()); 
     184    put("Image Type", ras.readChar()); 
    191185 
    192186    put("Image name", ras.readString(257)); 
  • trunk/loci/formats/in/GIFReader.java

    r3197 r3204  
    187187      int r, g, b; 
    188188      while (i < gctSize) { 
    189         r = ((int) c[j++]) & 0xff; 
    190         g = ((int) c[j++]) & 0xff; 
    191         b = ((int) c[j++]) & 0xff; 
     189        r = c[j++] & 0xff; 
     190        g = c[j++] & 0xff; 
     191        b = c[j++] & 0xff; 
    192192        gct[i++] = 0xff000000 | (r << 16) | (g << 8) | b; 
    193193      } 
     
    226226            int j = 0; 
    227227            while (i < lctSize) { 
    228               int r = ((int) c[j++]) & 0xff; 
    229               int g = ((int) c[j++]) & 0xff; 
    230               int b = ((int) c[j++]) & 0xff; 
     228              int r = c[j++] & 0xff; 
     229              int g = c[j++] & 0xff; 
     230              int b = c[j++] & 0xff; 
    231231              lct[i++] = 0xff000000 | (r << 16) + (g << 8) | b; 
    232232            } 
  • trunk/loci/formats/in/ImageIOReader.java

    r3197 r3204  
    7979  public BufferedImage openImage(int no) throws FormatException, IOException { 
    8080    FormatTools.assertId(currentId, true, 1); 
    81     if (no < 0 || no >= getImageCount()) { 
    82       throw new FormatException("Invalid image number: " + no); 
    83     } 
     81    FormatTools.checkPlaneNumber(this, no); 
    8482 
    8583    RandomAccessStream ras = new RandomAccessStream(currentId); 
  • trunk/loci/formats/in/LIMReader.java

    r3198 r3204  
    6161    FormatTools.checkBufferSize(this, buf.length); 
    6262 
    63     // TODO : add support for compressed files 
    64  
    6563    in.seek(0x94b); 
    6664    in.read(buf); 
     65 
     66    // swap red and blue channels 
     67    if (core.rgb[0]) { 
     68      for (int i=0; i<buf.length/3; i++) { 
     69        byte tmp = buf[i*3]; 
     70        buf[i*3] = buf[i*3 + 2]; 
     71        buf[i*3 + 2] = tmp; 
     72      } 
     73    } 
     74 
    6775    return buf; 
    6876  } 
     
    120128    core.falseColor[0] = false; 
    121129    core.interleaved[0] = true; 
     130 
     131    MetadataStore store = getMetadataStore(); 
     132    FormatTools.populatePixels(store, this); 
     133    store.setImage(currentId, null, null, null); 
     134    for (int i=0; i<core.sizeC[0]; i++) { 
     135      store.setLogicalChannel(i, null, null, null, null, null, null, null, 
     136        null, null, null, null, null, null, null, null, null, null, null, 
     137        null, null, null, null, null, null); 
     138    } 
     139 
    122140  } 
    123141 
  • trunk/loci/formats/in/LegacyPictReader.java

    r3197 r3204  
    6767  public BufferedImage openImage(int no) throws FormatException, IOException { 
    6868    FormatTools.assertId(currentId, true, 1); 
    69     if (no < 0 || no >= getImageCount()) { 
    70       throw new FormatException("Invalid image number: " + no); 
    71     } 
     69    FormatTools.checkPlaneNumber(this, no); 
    7270 
    7371    // read in PICT data 
  • trunk/loci/formats/in/LegacyQTReader.java

    r3197 r3204  
    8686  public BufferedImage openImage(int no) throws FormatException, IOException { 
    8787    FormatTools.assertId(currentId, true, 1); 
    88     if (no < 0 || no >= getImageCount()) { 
    89       throw new FormatException("Invalid image number: " + no); 
    90     } 
     88    FormatTools.checkPlaneNumber(this, no); 
     89 
    9190    // paint frame into image 
    9291    try { 
  • trunk/loci/formats/in/MNGReader.java

    r3197 r3204  
    7575  public BufferedImage openImage(int no) throws FormatException, IOException { 
    7676    FormatTools.assertId(currentId, true, 1); 
    77     if (no < 0 || no >= getImageCount()) { 
    78       throw new FormatException("Invalid image number: " + no); 
    79     } 
     77    FormatTools.checkPlaneNumber(this, no); 
    8078 
    8179    long offset = ((Long) offsets.get(no)).longValue(); 
  • trunk/loci/formats/in/ND2Reader.java

    r3197 r3204  
    226226 
    227227    FormatTools.assertId(currentId, true, 1); 
    228     if (no < 0 || no >= getImageCount()) { 
    229       throw new FormatException("Invalid image number: " + no); 
    230     } 
     228    FormatTools.checkPlaneNumber(this, no); 
    231229 
    232230    in.seek(offsets[no]); 
  • trunk/loci/formats/in/OMEXMLReader.java

    r3197 r3204  
    151151    } 
    152152    buf = pixels; 
    153     return buf;  
     153    return buf; 
    154154  } 
    155155 
  • trunk/loci/formats/in/ZeissZVIReader.java

    r3197 r3204  
    9494  /** Vector containing T indices. */ 
    9595  private Vector tIndices; 
    96  
    97   /** Valid bits per pixel */ 
    98   private int[] validBits; 
    9996 
    10097  private Hashtable offsets; 
     
    317314        } 
    318315      } 
    319  
    320       String s = (String) getMeta("Acquisition Bit Depth"); 
    321       if (s != null && s.trim().length() > 0) { 
    322         validBits = new int[core.sizeC[0]]; 
    323         if (core.sizeC[0] == 2) validBits = new int[3]; 
    324         for (int i=0; i<core.sizeC[0]; i++) { 
    325           validBits[i] = Integer.parseInt(s.trim()); 
    326         } 
    327       } 
    328       else validBits = null; 
    329316 
    330317      if (cIndex != -1) { 
Note: See TracChangeset for help on using the changeset viewer.