Changeset 3125 for trunk


Ignore:
Timestamp:
08/31/07 10:45:17 (13 years ago)
Author:
melissa
Message:

Added API methods for working with indexed color images, and implemented it in AVIReader. Note that ChannelMerger and ChannelSeparator can't handle indexed images (yet).

Location:
trunk/loci/formats
Files:
6 edited

Legend:

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

    r3015 r3125  
    279279    FormatTools.assertId(currentId, true, 2); 
    280280    return getSizeC() / getEffectiveSizeC(); 
     281  } 
     282 
     283  /* @see IFormatReader#isIndexed() */ 
     284  public boolean isIndexed() {  
     285    FormatTools.assertId(currentId, true, 2); 
     286    return reader.isIndexed(); 
     287  } 
     288 
     289  /* @see IFormatReader#get8BitLookupTable() */ 
     290  public byte[][] get8BitLookupTable() { 
     291    FormatTools.assertId(currentId, true, 2); 
     292    return reader.get8BitLookupTable(); 
     293  } 
     294 
     295  /* @see IFormatReader#get16BitLookupTable() */ 
     296  public short[][] get16BitLookupTable() { 
     297    FormatTools.assertId(currentId, true, 2); 
     298    return reader.get16BitLookupTable(); 
    281299  } 
    282300 
  • trunk/loci/formats/FormatReader.java

    r3115 r3125  
    247247  } 
    248248 
     249  /* @see IFormatReader#isIndexed() */ 
     250  public boolean isIndexed() {  
     251    return false; 
     252  } 
     253 
     254  /* @see IFormatReader#get8BitLookupTable() */ 
     255  public byte[][] get8BitLookupTable() { 
     256    return null; 
     257  } 
     258 
     259  /* @see IFormatReader#get16BitLookupTable() */ 
     260  public short[][] get16BitLookupTable() { 
     261    return null; 
     262  } 
     263 
    249264  /* @see IFormatReader#getChannelDimLengths() */ 
    250265  public int[] getChannelDimLengths() { 
  • trunk/loci/formats/IFormatReader.java

    r3108 r3125  
    8080  /** 
    8181   * Gets the effective size of the C dimension, guaranteeing that 
    82    * getEffectiveSizeC(id) * getSizeZ(id) * getSizeT(id) == getImageCount(id) 
    83    * regardless of the result of isRGB(id). 
     82   * getEffectiveSizeC() * getSizeZ() * getSizeT() == getImageCount() 
     83   * regardless of the result of isRGB(). 
    8484   */ 
    8585  int getEffectiveSizeC(); 
     
    8787  /** Gets the number of channels per RGB image (if not RGB, this returns 1). */ 
    8888  int getRGBChannelCount(); 
     89 
     90  /** Gets whether the images are indexed color. */ 
     91  boolean isIndexed(); 
     92 
     93  /** 
     94   * Gets the 8-bit color lookup table associated with the most recently opened  
     95   * image. 
     96   * If no images have been opened, or if isIndexed() returns false, then 
     97   * this returns null.  Also, if getPixelType() returns anything other than 
     98   * <code>INT8</code> or <code>UINT8</code>, this method will return null. 
     99   */ 
     100  byte[][] get8BitLookupTable(); 
     101 
     102  /** 
     103   * Gets the 8-bit color lookup table associated with the most recently opened  
     104   * image. 
     105   * If no images have been opened, or if isIndexed() returns false, then 
     106   * this returns null.  Also, if getPixelType() returns anything other than 
     107   * <code>INT8</code> or <code>UINT8</code>, this method will return null. 
     108   */ 
     109  short[][] get16BitLookupTable(); 
    89110 
    90111  /** 
  • trunk/loci/formats/ImageReader.java

    r3108 r3125  
    230230  } 
    231231 
     232  /* @see IFormatReader#isIndexed() */ 
     233  public boolean isIndexed() {  
     234    FormatTools.assertId(currentId, true, 2); 
     235    return getReader().isIndexed(); 
     236  } 
     237 
     238  /* @see IFormatReader#get8BitLookupTable() */ 
     239  public byte[][] get8BitLookupTable() { 
     240    FormatTools.assertId(currentId, true, 2); 
     241    return getReader().get8BitLookupTable(); 
     242  } 
     243 
     244  /* @see IFormatReader#get16BitLookupTable() */ 
     245  public short[][] get16BitLookupTable() { 
     246    FormatTools.assertId(currentId, true, 2); 
     247    return getReader().get16BitLookupTable(); 
     248  } 
     249 
    232250  /* @see IFormatReader#getChannelDimLengths() */ 
    233251  public int[] getChannelDimLengths() { 
  • trunk/loci/formats/ReaderWrapper.java

    r3015 r3125  
    118118  } 
    119119 
     120  public boolean isIndexed() {  
     121    return reader.isIndexed(); 
     122  } 
     123 
     124  public byte[][] get8BitLookupTable() { 
     125    return reader.get8BitLookupTable(); 
     126  } 
     127 
     128  public short[][] get16BitLookupTable() { 
     129    return reader.get16BitLookupTable(); 
     130  } 
     131 
    120132  public int[] getChannelDimLengths() { 
    121133    return reader.getChannelDimLengths(); 
  • trunk/loci/formats/in/AVIReader.java

    r3097 r3125  
    2525package loci.formats.in; 
    2626 
    27 import java.awt.image.BufferedImage; 
     27import java.awt.image.*; 
    2828import java.io.*; 
    2929import java.util.Vector; 
     
    9999  } 
    100100 
     101  /* @see loci.formats.IFormatReader#isIndexed() */ 
     102  public boolean isIndexed() { 
     103    FormatTools.assertId(currentId, true, 1); 
     104    return isRLE; 
     105  } 
     106 
     107  /* @see loci.formats.IFormatReader#get8BitLookupTable() */ 
     108  public byte[][] get8BitLookupTable() { 
     109    FormatTools.assertId(currentId, true, 1); 
     110    return new byte[][] {pr, pg, pb}; 
     111  } 
     112 
    101113  /* @see loci.formats.IFormatReader#openBytes(int) */ 
    102114  public byte[] openBytes(int no) throws FormatException, IOException { 
     
    109121    } 
    110122 
    111     byte[] buf = 
    112       new byte[core.sizeY[0] * effectiveWidth * bytes * core.sizeC[0]]; 
     123    int size = core.sizeY[0] * effectiveWidth * bytes; 
     124    if (!isIndexed()) size *= core.sizeC[0]; 
     125    byte[] buf = new byte[size]; 
    113126    return openBytes(no, buf); 
    114127  } 
     
    130143    } 
    131144 
    132     if (buf.length < core.sizeY[0]*effectiveWidth*bytes*core.sizeC[0]) { 
    133       throw new FormatException("Buffer too small."); 
    134     } 
     145    int size = effectiveWidth * bytes * core.sizeY[0]; 
     146    if (!isIndexed()) size *= core.sizeC[0]; 
     147 
     148    if (buf.length < size) throw new FormatException("Buffer too small."); 
    135149 
    136150    long fileOff = ((Long) offsets.get(no)).longValue(); 
     
    146160 
    147161      MSRLECodec codec = new MSRLECodec(); 
    148       b = codec.decompress(b, options); 
    149       lastImage = b; 
     162      buf = codec.decompress(b, options); 
     163      lastImage = buf; 
    150164      if (no == core.imageCount[0] - 1) lastImage = null; 
    151       byte[] colors = new byte[b.length * 3]; 
    152       for (int i=0; i<b.length; i++) { 
    153         int ndx = b[i]; 
    154         if (ndx < 0) ndx += 256; 
    155         colors[i*3] = pr[ndx]; 
    156         colors[i*3 + 1] = pg[ndx]; 
    157         colors[i*3 + 2] = pb[ndx]; 
    158       } 
    159       return colors; 
     165      return buf;  
    160166    } 
    161167 
     
    209215  public BufferedImage openImage(int no) throws FormatException, IOException { 
    210216    FormatTools.assertId(currentId, true, 1); 
    211     return ImageTools.makeImage(openBytes(no), 
    212       core.sizeX[0], core.sizeY[0], core.sizeC[0], !core.interleaved[0], 
     217    BufferedImage b = ImageTools.makeImage(openBytes(no), core.sizeX[0],  
     218      core.sizeY[0], isIndexed() ? 1 : core.sizeC[0], !core.interleaved[0], 
    213219      FormatTools.getBytesPerPixel(core.pixelType[0]), core.littleEndian[0]); 
     220    if (isIndexed()) { 
     221      byte[][] table = get8BitLookupTable(); 
     222      IndexedColorModel model =  
     223        new IndexedColorModel(8, table[0].length, table); 
     224      WritableRaster raster = Raster.createWritableRaster(b.getSampleModel(), 
     225        b.getData().getDataBuffer(), null); 
     226      b = new BufferedImage(model, raster, false, null);  
     227    } 
     228    return b; 
    214229  } 
    215230 
Note: See TracChangeset for help on using the changeset viewer.