private void parse_bKGD_chunk()

in src/main/java/org/apache/xmlgraphics/image/codec/png/PNGImageDecoder.java [954:1009]


    private void parse_bKGD_chunk(PNGChunk chunk) {
        switch (colorType) {
        case PNG_COLOR_PALETTE:
            int bkgdIndex = chunk.getByte(0) & 0xff;

            bkgdRed = redPalette[bkgdIndex] & 0xff;
            bkgdGreen = greenPalette[bkgdIndex] & 0xff;
            bkgdBlue = bluePalette[bkgdIndex] & 0xff;

            if (encodeParam != null) {
                ((PNGEncodeParam.Palette)encodeParam).setBackgroundPaletteIndex(bkgdIndex);
            }
            break;
        case PNG_COLOR_GRAY: case PNG_COLOR_GRAY_ALPHA:
            int bkgdGray = chunk.getInt2(0);
            bkgdRed = bkgdGreen = bkgdBlue = bkgdGray;

            if (encodeParam != null) {
                ((PNGEncodeParam.Gray)encodeParam).setBackgroundGray(bkgdGray);
            }
            break;
        case PNG_COLOR_RGB: case PNG_COLOR_RGB_ALPHA:
            bkgdRed = chunk.getInt2(0);
            bkgdGreen = chunk.getInt2(2);
            bkgdBlue = chunk.getInt2(4);

            int[] bkgdRGB = new int[3];
            bkgdRGB[0] = bkgdRed;
            bkgdRGB[1] = bkgdGreen;
            bkgdRGB[2] = bkgdBlue;
            if (encodeParam != null) {
                ((PNGEncodeParam.RGB)encodeParam).setBackgroundRGB(bkgdRGB);
            }
            break;
        }

        int r = 0;
        int g = 0;
        int b = 0;
        if (bitDepth < 8) {
            r = expandBits[bitDepth][bkgdRed];
            g = expandBits[bitDepth][bkgdGreen];
            b = expandBits[bitDepth][bkgdBlue];
        } else if (bitDepth == 8) {
            r = bkgdRed;
            g = bkgdGreen;
            b = bkgdBlue;
        } else if (bitDepth == 16) {
            r = bkgdRed >> 8;
            g = bkgdGreen >> 8;
            b = bkgdBlue >> 8;
        }
        if (emitProperties) {
            properties.put("background_color", new Color(r, g, b));
        }
    }