Changeset 6309


Ignore:
Timestamp:
05/13/10 13:09:37 (10 years ago)
Author:
curtis
Message:

Fix bug with 8-bit indexed color when less than 3 channels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/gui/AWTImageTools.java

    r6230 r6309  
    3535import java.awt.MediaTracker; 
    3636import java.awt.RenderingHints; 
     37import java.awt.Transparency; 
    3738import java.awt.color.ColorSpace; 
    3839import java.awt.geom.AffineTransform; 
     
    755756        byte[][] table = r.get8BitLookupTable(); 
    756757        if (table != null && table.length > 0 && table[0] != null) { 
    757           model = new IndexColorModel(8, table[0].length, 
    758             table[0], table[1], table[2]); 
     758          int len = table[0].length; 
     759          byte[] dummy = table.length < 3 ? new byte[len] : null; 
     760          byte[] red = table.length >= 1 ? table[0] : dummy; 
     761          byte[] green = table.length >= 2 ? table[1] : dummy; 
     762          byte[] blue = table.length >= 3 ? table[2] : dummy; 
     763          model = new IndexColorModel(8, len, red, green, blue); 
    759764        } 
    760765      } 
     
    802807  public static byte[][] getBytes(BufferedImage image) { 
    803808    WritableRaster r = image.getRaster(); 
    804     if (canUseBankDataDirectly(image, 1, 
     809    if (canUseBankDataDirectly(image, 
    805810      DataBuffer.TYPE_BYTE, DataBufferByte.class)) 
    806811    { 
     
    821826  public static short[][] getShorts(BufferedImage image) { 
    822827    WritableRaster r = image.getRaster(); 
    823     if (canUseBankDataDirectly(image, 2, 
     828    if (canUseBankDataDirectly(image, 
    824829      DataBuffer.TYPE_USHORT, DataBufferUShort.class)) 
    825830    { 
     
    840845  public static int[][] getInts(BufferedImage image) { 
    841846    WritableRaster r = image.getRaster(); 
    842     if (canUseBankDataDirectly(image, 4, 
     847    if (canUseBankDataDirectly(image, 
    843848      DataBuffer.TYPE_INT, DataBufferInt.class)) 
    844849    { 
     
    855860  public static float[][] getFloats(BufferedImage image) { 
    856861    WritableRaster r = image.getRaster(); 
    857     if (canUseBankDataDirectly(image, 4, 
     862    if (canUseBankDataDirectly(image, 
    858863      DataBuffer.TYPE_FLOAT, DataBufferFloat.class)) 
    859864    { 
     
    870875  public static double[][] getDoubles(BufferedImage image) { 
    871876    WritableRaster r = image.getRaster(); 
    872     if (canUseBankDataDirectly(image, 8, 
     877    if (canUseBankDataDirectly(image, 
    873878      DataBuffer.TYPE_DOUBLE, DataBufferDouble.class)) 
    874879    { 
     
    887892   */ 
    888893  private static boolean canUseBankDataDirectly(BufferedImage image, 
    889     int bytesPerPixel, int transferType, Class dataBufferClass) 
     894    int transferType, Class<? extends DataBuffer> dataBufferClass) 
    890895  { 
    891896    WritableRaster r = image.getRaster(); 
     
    11021107    WritableRaster raster = cm.createCompatibleWritableRaster(width, height); 
    11031108    boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); 
    1104     Hashtable properties = new Hashtable(); 
     1109    Hashtable<String, Object> properties = new Hashtable<String, Object>(); 
    11051110    String[] keys = img.getPropertyNames(); 
    11061111    if (keys != null) { 
     
    11191124    byte[][] p = getBytes(img); 
    11201125    if (separated || p.length == 1) return p[0]; 
    1121     else { 
    1122       byte[] rtn = new byte[p.length * p[0].length]; 
    1123       for (int i=0; i<p.length; i++) { 
    1124         System.arraycopy(p[i], 0, rtn, i * p[0].length, p[i].length); 
    1125       } 
    1126       return rtn; 
    1127     } 
     1126 
     1127    byte[] rtn = new byte[p.length * p[0].length]; 
     1128    for (int i=0; i<p.length; i++) { 
     1129      System.arraycopy(p[i], 0, rtn, i * p[0].length, p[i].length); 
     1130    } 
     1131    return rtn; 
    11281132  } 
    11291133 
     
    13831387          if (shorts[i][j] < 0) shorts[i][j] += 32767; 
    13841388 
    1385           float diff = (float) max - (float) min; 
     1389          int diff = max - min; 
    13861390          float dist = (float) (shorts[i][j] - min) / diff; 
    13871391 
     
    16891693    ColorSpace cs = makeColorSpace(c); 
    16901694    return cs == null ? null : new ComponentColorModel(cs, 
    1691       c == 4, false, ColorModel.TRANSLUCENT, dataType); 
     1695      c == 4, false, Transparency.TRANSLUCENT, dataType); 
    16921696  } 
    16931697 
Note: See TracChangeset for help on using the changeset viewer.