Hello,

The com.sun.imageio.plugins.png.PNGImageReader was updated during one
of the jdk1.6 releases (I think the change happened in jdk1.6_14).

One of the changes that I noticed caused some performance impact when
generating PS with a PNG image in FOP is this one in the
getImageTypes() method:

        case PNG_COLOR_RGB:
            if (bitDepth == 8) {
                // some standard types of buffered images
                // which can be used as destination
                l.add(ImageTypeSpecifier.createFromBufferedImageType(
                          BufferedImage.TYPE_3BYTE_BGR));

                l.add(ImageTypeSpecifier.createFromBufferedImageType(
                          BufferedImage.TYPE_INT_RGB));

                l.add(ImageTypeSpecifier.createFromBufferedImageType(
                          BufferedImage.TYPE_INT_BGR));

            }
            // Component R, G, B
            rgb = ColorSpace.getInstance(ColorSpace.CS_sRGB);

The if (bitDepth ==8) {} code is new. There is similar new code for
PNG_COLOR_RGB_ALPHA.

This new code is executed for some PNG images and the result is seen
in the 
org.apache.xmlgraphics.ps.ImageEncodingHelper.determineEncodedColorModel()
method:

                    int[] offsets = piSampleModel.getBandOffsets();
                    for (int i = 0; i < offsets.length; i++) {
                        if (offsets[i] != i ) {
                            //Don't encode directly as samples are not
next to each other
                            //i.e. offsets are not 012 (RGB) or 0123 (CMYK)
                            return;
                        }
                    }

The offsets come as [2, 1, 0] instead of [0, 1, 2] so the above code
returns. As result, the encode() method in the same class:

    public void encode(OutputStream out) throws IOException {
        if (!isConverted()) {
            if (optimizedWriteTo(out)) {
                return;
            }
        }
        writeRGBTo(out);
    }

follows the writeRGBTo() path instead of the previous
optimizedWriteTo() path. The end result is a 40% performance impact
for the PNG file I have been testing with when going from jdk1.6_13 to
a more recent one, like jdk1.6_30.

Any ideas on how to recover the previous performance (i.e., use the
optimizedWriteTo() path)?

Luis

Reply via email to