in src/main/java/org/apache/xmlgraphics/image/codec/png/PNGRed.java [1262:1336]
private void parse_tRNS_chunk(PNGChunk chunk) {
if (colorType == PNG_COLOR_PALETTE) {
int entries = chunk.getLength();
if (entries > paletteEntries) {
// Error -- mustn't have more alpha than RGB palette entries
String msg = PropertyUtil.getString("PNGImageDecoder14");
throw new RuntimeException(msg);
}
// Load beginning of palette from the chunk
alphaPalette = new byte[paletteEntries];
for (int i = 0; i < entries; i++) {
alphaPalette[i] = chunk.getByte(i);
}
// Fill rest of palette with 255
for (int i = entries; i < paletteEntries; i++) {
alphaPalette[i] = (byte)255;
}
if (!suppressAlpha) {
if (expandPalette) {
postProcess = POST_PALETTE_TO_RGBA;
outputBands = 4;
} else {
outputHasAlphaPalette = true;
}
}
} else if (colorType == PNG_COLOR_GRAY) {
grayTransparentAlpha = chunk.getInt2(0);
if (!suppressAlpha) {
if (bitDepth < 8) {
output8BitGray = true;
maxOpacity = 255;
postProcess = POST_GRAY_LUT_ADD_TRANS;
} else {
postProcess = POST_ADD_GRAY_TRANS;
}
if (expandGrayAlpha) {
outputBands = 4;
postProcess |= POST_EXP_MASK;
} else {
outputBands = 2;
}
if (encodeParam != null) {
((PNGEncodeParam.Gray)encodeParam).setTransparentGray(grayTransparentAlpha);
}
}
} else if (colorType == PNG_COLOR_RGB) {
redTransparentAlpha = chunk.getInt2(0);
greenTransparentAlpha = chunk.getInt2(2);
blueTransparentAlpha = chunk.getInt2(4);
if (!suppressAlpha) {
outputBands = 4;
postProcess = POST_ADD_RGB_TRANS;
if (encodeParam != null) {
int[] rgbTrans = new int[3];
rgbTrans[0] = redTransparentAlpha;
rgbTrans[1] = greenTransparentAlpha;
rgbTrans[2] = blueTransparentAlpha;
((PNGEncodeParam.RGB)encodeParam).setTransparentRGB(rgbTrans);
}
}
} else if (colorType == PNG_COLOR_GRAY_ALPHA
|| colorType == PNG_COLOR_RGB_ALPHA) {
// Error -- GA or RGBA image can't have a tRNS chunk.
String msg = PropertyUtil.getString("PNGImageDecoder15");
throw new RuntimeException(msg);
}
}