If an IndexColorModel is created with some transparent black entries (i.e. 0x0)
but no transparent pixel is specified, then the getDataElements does not
return that pixel value when given a transparent black rgb value.
-- Begin TransparentLookupTest.java --
import java.awt.image.IndexColorModel;
import java.awt.image.DataBuffer;
public class TransparentLookupTest {
public static void main(String argv[]) {
// Create a 6x6x6 color cube
int[] cmap = new int[256];
int i=0;
for (int r=0; r < 256; r += 51) {
for (int g=0; g < 256; g += 51) {
for (int b=0; b < 256; b += 51) {
cmap[i++] = (r<<16)|(g<<8)|b;
}
}
}
testFindTP(new IndexColorModel(8, 256, cmap, 0, true, -1,
DataBuffer.TYPE_BYTE));
}
public static void testFindTP(IndexColorModel icm) {
byte pix[] = (byte[]) icm.getDataElements(0, null);
int rgb = icm.getRGB(pix[0] & 0xff);
if (rgb != 0) {
throw new RuntimeException("Transparent black (0x00) resolves to ("+
Integer.toHexString(rgb)+")");
}
}
}