Changeset 3178


Ignore:
Timestamp:
09/19/07 12:03:42 (12 years ago)
Author:
melissa
Message:

Added utility methods and reader wrapper to expand indexed color images.

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

Legend:

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

    r3104 r3178  
    20272027  } 
    20282028 
     2029  // -- Indexed color conversion -- 
     2030 
     2031  /** Converts an indexed color BufferedImage to an RGB BufferedImage. */ 
     2032  public static BufferedImage indexedToRGB(BufferedImage img, boolean le) { 
     2033    byte[][] indices = getPixelBytes(img, le); 
     2034    if (indices.length > 1) return img; 
     2035    if (getPixelType(img) == FormatTools.UINT8) { 
     2036      IndexedColorModel model = (IndexedColorModel) img.getColorModel(); 
     2037      byte[][] b = new byte[3][indices[0].length]; 
     2038      for (int i=0; i<indices[0].length; i++) { 
     2039        b[0][i] = (byte) (model.getRed(indices[0][i] & 0xff) & 0xff); 
     2040        b[1][i] = (byte) (model.getGreen(indices[0][i] & 0xff) & 0xff); 
     2041        b[2][i] = (byte) (model.getBlue(indices[0][i] & 0xff) & 0xff); 
     2042      } 
     2043      return makeImage(b, img.getWidth(), img.getHeight()); 
     2044    } 
     2045    else if (getPixelType(img) == FormatTools.UINT16) { 
     2046      IndexedColorModel model = (IndexedColorModel) img.getColorModel(); 
     2047      short[][] s = new short[3][indices[0].length / 2]; 
     2048      for (int i=0; i<s[0].length; i++) { 
     2049        int ndx = DataTools.bytesToInt(indices[0], i*2, 2, le) & 0xffff; 
     2050        s[0][i] = (short) (model.getRed(ndx) & 0xffff); 
     2051        s[1][i] = (short) (model.getRed(ndx) & 0xffff); 
     2052        s[2][i] = (short) (model.getRed(ndx) & 0xffff); 
     2053      } 
     2054      return makeImage(s, img.getWidth(), img.getHeight()); 
     2055    } 
     2056    return null; 
     2057  } 
     2058 
     2059  /** Converts a LUT and an array of indices into an array of RGB tuples. */ 
     2060  public static byte[][] indexedToRGB(byte[][] lut, byte[] b) { 
     2061    byte[][] rtn = new byte[lut.length][b.length]; 
     2062 
     2063    for (int i=0; i<b.length; i++) { 
     2064      for (int j=0; j<lut.length; j++) { 
     2065        rtn[j][i] = lut[j][b[i]]; 
     2066      } 
     2067    } 
     2068    return rtn; 
     2069  } 
     2070 
     2071  /** Converts a LUT and an array of indices into an array of RGB tuples. */ 
     2072  public static short[][] indexedToRGB(short[][] lut, byte[] b, boolean le) { 
     2073    short[][] rtn = new short[lut.length][b.length / 2]; 
     2074    for (int i=0; i<b.length/2; i++) { 
     2075      for (int j=0; j<lut.length; j++) { 
     2076        rtn[j][i] = lut[j][DataTools.bytesToShort(b, i*2, 2, le)]; 
     2077      } 
     2078    } 
     2079    return rtn; 
     2080  } 
     2081 
    20292082} 
Note: See TracChangeset for help on using the changeset viewer.