batik-codec/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGImageDecoder.java [1052:1221]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            properties.put("background_color", new Color(r, g, b));
        }
    }

    private void parse_cHRM_chunk(PNGChunk chunk) {
        // If an sRGB chunk exists, ignore cHRM chunks
        if (sRGBRenderingIntent != -1) {
            return;
        }

        chromaticity = new float[8];
        chromaticity[0] = chunk.getInt4(0)/100000.0F;
        chromaticity[1] = chunk.getInt4(4)/100000.0F;
        chromaticity[2] = chunk.getInt4(8)/100000.0F;
        chromaticity[3] = chunk.getInt4(12)/100000.0F;
        chromaticity[4] = chunk.getInt4(16)/100000.0F;
        chromaticity[5] = chunk.getInt4(20)/100000.0F;
        chromaticity[6] = chunk.getInt4(24)/100000.0F;
        chromaticity[7] = chunk.getInt4(28)/100000.0F;

        if (encodeParam != null) {
            encodeParam.setChromaticity(chromaticity);
        }
        if (emitProperties) {
            properties.put("white_point_x", chromaticity[0]);
            properties.put("white_point_y", chromaticity[1]);
            properties.put("red_x", chromaticity[2]);
            properties.put("red_y", chromaticity[3]);
            properties.put("green_x", chromaticity[4]);
            properties.put("green_y", chromaticity[5]);
            properties.put("blue_x", chromaticity[6]);
            properties.put("blue_y", chromaticity[7]);
        }
    }

    private void parse_gAMA_chunk(PNGChunk chunk) {
        // If an sRGB chunk exists, ignore gAMA chunks
        if (sRGBRenderingIntent != -1) {
            return;
        }

        fileGamma = chunk.getInt4(0)/100000.0F;

        float exp =
            performGammaCorrection ? displayExponent/userExponent : 1.0F;
        if (encodeParam != null) {
            encodeParam.setGamma(fileGamma*exp);
        }
        if (emitProperties) {
            properties.put("gamma", fileGamma * exp);
        }
    }

    private void parse_hIST_chunk(PNGChunk chunk) {
        if (redPalette == null) {
            String msg = PropertyUtil.getString("PNGImageDecoder18");
            throw new RuntimeException(msg);
        }

        int length = redPalette.length;
        int[] hist = new int[length];
        for (int i = 0; i < length; i++) {
            hist[i] = chunk.getInt2(2*i);
        }

        if (encodeParam != null) {
            encodeParam.setPaletteHistogram(hist);
        }
    }

    private void parse_iCCP_chunk(PNGChunk chunk) {
        String name = "";  // todo simplify this
        byte b;

        int textIndex = 0;
        while ((b = chunk.getByte(textIndex++)) != 0) {
            name += (char)b;
        }
    }

    private void parse_pHYs_chunk(PNGChunk chunk) {
        int xPixelsPerUnit = chunk.getInt4(0);
        int yPixelsPerUnit = chunk.getInt4(4);
        int unitSpecifier = chunk.getInt1(8);

        if (encodeParam != null) {
            encodeParam.setPhysicalDimension(xPixelsPerUnit,
                                             yPixelsPerUnit,
                                             unitSpecifier);
        }
        if (emitProperties) {
            properties.put("x_pixels_per_unit", xPixelsPerUnit);
            properties.put("y_pixels_per_unit", yPixelsPerUnit);
            properties.put("pixel_aspect_ratio",
                    (float) xPixelsPerUnit / yPixelsPerUnit);
            if (unitSpecifier == 1) {
                properties.put("pixel_units", "Meters");
            } else if (unitSpecifier != 0) {
                // Error -- unit specifier must be 0 or 1
                String msg = PropertyUtil.getString("PNGImageDecoder12");
                throw new RuntimeException(msg);
            }
        }
    }

    private void parse_sBIT_chunk(PNGChunk chunk) {
        if (colorType == PNG_COLOR_PALETTE) {
            significantBits = new int[3];
        } else {
            significantBits = new int[inputBands];
        }
        for (int i = 0; i < significantBits.length; i++) {
            int bits = chunk.getByte(i);
            int depth = (colorType == PNG_COLOR_PALETTE) ? 8 : bitDepth;
            if (bits <= 0 || bits > depth) {
                // Error -- significant bits must be between 0 and
                // image bit depth.
                String msg = PropertyUtil.getString("PNGImageDecoder13");
                throw new RuntimeException(msg);
            }
            significantBits[i] = bits;
        }

        if (encodeParam != null) {
            encodeParam.setSignificantBits(significantBits);
        }
        if (emitProperties) {
            properties.put("significant_bits", significantBits);
        }
    }

    private void parse_sRGB_chunk(PNGChunk chunk) {
        sRGBRenderingIntent = chunk.getByte(0);

        // The presence of an sRGB chunk implies particular
        // settings for gamma and chroma.
        fileGamma = 45455/100000.0F;

        chromaticity = new float[8];
        chromaticity[0] = 31270/10000.0F;
        chromaticity[1] = 32900/10000.0F;
        chromaticity[2] = 64000/10000.0F;
        chromaticity[3] = 33000/10000.0F;
        chromaticity[4] = 30000/10000.0F;
        chromaticity[5] = 60000/10000.0F;
        chromaticity[6] = 15000/10000.0F;
        chromaticity[7] =  6000/10000.0F;

        if (performGammaCorrection) {
            // File gamma is 1/2.2
            float gamma = fileGamma*(displayExponent/userExponent);
            if (encodeParam != null) {
                encodeParam.setGamma(gamma);
                encodeParam.setChromaticity(chromaticity);
            }
            if (emitProperties) {
                properties.put("gamma", gamma);
                properties.put("white_point_x", chromaticity[0]);
                properties.put("white_point_y", chromaticity[1]);
                properties.put("red_x", chromaticity[2]);
                properties.put("red_y", chromaticity[3]);
                properties.put("green_x", chromaticity[4]);
                properties.put("green_y", chromaticity[5]);
                properties.put("blue_x", chromaticity[6]);
                properties.put("blue_y", chromaticity[7]);
            }
        }
    }

    private void parse_tEXt_chunk(PNGChunk chunk) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



batik-codec/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGRed.java [1063:1232]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            properties.put("background_color", new Color(r, g, b));
        }
    }

    private void parse_cHRM_chunk(PNGChunk chunk) {
        // If an sRGB chunk exists, ignore cHRM chunks
        if (sRGBRenderingIntent != -1) {
            return;
        }

        chromaticity = new float[8];
        chromaticity[0] = chunk.getInt4(0)/100000.0F;
        chromaticity[1] = chunk.getInt4(4)/100000.0F;
        chromaticity[2] = chunk.getInt4(8)/100000.0F;
        chromaticity[3] = chunk.getInt4(12)/100000.0F;
        chromaticity[4] = chunk.getInt4(16)/100000.0F;
        chromaticity[5] = chunk.getInt4(20)/100000.0F;
        chromaticity[6] = chunk.getInt4(24)/100000.0F;
        chromaticity[7] = chunk.getInt4(28)/100000.0F;

        if (encodeParam != null) {
            encodeParam.setChromaticity(chromaticity);
        }
        if (emitProperties) {
            properties.put("white_point_x", chromaticity[0]);
            properties.put("white_point_y", chromaticity[1]);
            properties.put("red_x", chromaticity[2]);
            properties.put("red_y", chromaticity[3]);
            properties.put("green_x", chromaticity[4]);
            properties.put("green_y", chromaticity[5]);
            properties.put("blue_x", chromaticity[6]);
            properties.put("blue_y", chromaticity[7]);
        }
    }

    private void parse_gAMA_chunk(PNGChunk chunk) {
        // If an sRGB chunk exists, ignore gAMA chunks
        if (sRGBRenderingIntent != -1) {
            return;
        }

        fileGamma = chunk.getInt4(0)/100000.0F;
        // System.out.println("Gamma: " + fileGamma);
        float exp =
            performGammaCorrection ? displayExponent/userExponent : 1.0F;
        if (encodeParam != null) {
            encodeParam.setGamma(fileGamma*exp);
        }
        if (emitProperties) {
            properties.put("gamma", fileGamma * exp);
        }
    }

    private void parse_hIST_chunk(PNGChunk chunk) {
        if (redPalette == null) {
            String msg = PropertyUtil.getString("PNGImageDecoder18");
            throw new RuntimeException(msg);
        }

        int length = redPalette.length;
        int[] hist = new int[length];
        for (int i = 0; i < length; i++) {
            hist[i] = chunk.getInt2(2*i);
        }

        if (encodeParam != null) {
            encodeParam.setPaletteHistogram(hist);
        }
    }

    private void parse_iCCP_chunk(PNGChunk chunk) {
        String name = "";
        byte b;

        int textIndex = 0;
        while ((b = chunk.getByte(textIndex++)) != 0) {
            name += (char)b;
        }
    }

    private void parse_pHYs_chunk(PNGChunk chunk) {
        int xPixelsPerUnit = chunk.getInt4(0);
        int yPixelsPerUnit = chunk.getInt4(4);
        int unitSpecifier = chunk.getInt1(8);

        if (encodeParam != null) {
            encodeParam.setPhysicalDimension(xPixelsPerUnit,
                                             yPixelsPerUnit,
                                             unitSpecifier);
        }
        if (emitProperties) {
            properties.put("x_pixels_per_unit", xPixelsPerUnit);
            properties.put("y_pixels_per_unit", yPixelsPerUnit);
            properties.put("pixel_aspect_ratio",
                    (float) xPixelsPerUnit / yPixelsPerUnit);
            if (unitSpecifier == 1) {
                properties.put("pixel_units", "Meters");
            } else if (unitSpecifier != 0) {
                // Error -- unit specifier must be 0 or 1
                String msg = PropertyUtil.getString("PNGImageDecoder12");
                throw new RuntimeException(msg);
            }
        }
    }

    private void parse_sBIT_chunk(PNGChunk chunk) {
        if (colorType == PNG_COLOR_PALETTE) {
            significantBits = new int[3];
        } else {
            significantBits = new int[inputBands];
        }
        for (int i = 0; i < significantBits.length; i++) {
            int bits = chunk.getByte(i);
            int depth = (colorType == PNG_COLOR_PALETTE) ? 8 : bitDepth;
            if (bits <= 0 || bits > depth) {
                // Error -- significant bits must be between 0 and
                // image bit depth.
                String msg = PropertyUtil.getString("PNGImageDecoder13");
                throw new RuntimeException(msg);
            }
            significantBits[i] = bits;
        }

        if (encodeParam != null) {
            encodeParam.setSignificantBits(significantBits);
        }
        if (emitProperties) {
            properties.put("significant_bits", significantBits);
        }
    }

    private void parse_sRGB_chunk(PNGChunk chunk) {
        sRGBRenderingIntent = chunk.getByte(0);

        // The presence of an sRGB chunk implies particular
        // settings for gamma and chroma.
        fileGamma = 45455/100000.0F;

        chromaticity = new float[8];
        chromaticity[0] = 31270/10000.0F;
        chromaticity[1] = 32900/10000.0F;
        chromaticity[2] = 64000/10000.0F;
        chromaticity[3] = 33000/10000.0F;
        chromaticity[4] = 30000/10000.0F;
        chromaticity[5] = 60000/10000.0F;
        chromaticity[6] = 15000/10000.0F;
        chromaticity[7] =  6000/10000.0F;

        if (performGammaCorrection) {
            // File gamma is 1/2.2
            float gamma = fileGamma*(displayExponent/userExponent);
            if (encodeParam != null) {
                encodeParam.setGamma(gamma);
                encodeParam.setChromaticity(chromaticity);
            }
            if (emitProperties) {
                properties.put("gamma", gamma);
                properties.put("white_point_x", chromaticity[0]);
                properties.put("white_point_y", chromaticity[1]);
                properties.put("red_x", chromaticity[2]);
                properties.put("red_y", chromaticity[3]);
                properties.put("green_x", chromaticity[4]);
                properties.put("green_y", chromaticity[5]);
                properties.put("blue_x", chromaticity[6]);
                properties.put("blue_y", chromaticity[7]);
            }
        }
    }

    private void parse_tEXt_chunk(PNGChunk chunk) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



