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);
        }
    }
A convenience method to create an instance of
<code>ComponentColorModel</code> suitable for use with the
given <code>SampleModel</code>.  The <code>SampleModel</code>
should have a data type of <code>DataBuffer.TYPE_BYTE</code>,
<code>TYPE_USHORT</code>, or <code>TYPE_INT</code> and between
1 and 4 bands.  Depending on the number of bands of the
<code>SampleModel</code>, either a gray, gray+alpha, rgb, or
rgb+alpha <code>ColorModel</code> is returned.
plugins/svg-plugin/batik-codec-fix/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageDecoder.java