Bug 51465 - Significant slowdown in PNG and TIFF processing with xmlgraphics 1.4
Summary: Significant slowdown in PNG and TIFF processing with xmlgraphics 1.4
Status: REOPENED
Alias: None
Product: XMLGraphicsCommons - Now in Jira
Classification: Unclassified
Component: image writer (show other bugs)
Version: 1.4
Hardware: PC All
: P2 regression with 2 votes (vote)
Target Milestone: --
Assignee: XML Graphics Project Mailing List
URL:
Keywords:
Depends on: 51149
Blocks:
  Show dependency tree
 
Reported: 2011-07-02 12:05 UTC by patches
Modified: 2012-08-15 21:48 UTC (History)
1 user (show)



Attachments
Profiler (27.64 KB, image/png)
2011-07-02 12:05 UTC, patches
Details
PNG image (46.05 KB, image/png)
2012-06-20 15:46 UTC, patches
Details
an example to test icc profiles (594.76 KB, application/x-gzip)
2012-07-08 23:15 UTC, Luis Bernardo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description patches 2011-07-02 12:05:23 UTC
Created attachment 27243 [details]
Profiler

Hello, 
Iā€™m using fop 1.0 (xmlgraphics 1.4) to generate PDF, I noticed that PDF generation with PNG or TIF image is 7 times longer. 
The problem doesn't appear in the version 1.3 of xmlgraphics.


The problem seems to come from color model associated with the image.
* if is_sRGB_stdStale = true then getRBG method is very fast
* if is_sRGB_stdStale = false then getRBG  is slow because the treatment is
delegated to ICC_ColorSpace.toRGB

The color model is correct, but it is modified by the class
org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderImageIO
by the following code : 
            if (providerIgnoresICC && cm instanceof ComponentColorModel) {
                // Apply ICC Profile to Image by creating a new image with a new color model.
                ICC_Profile iccProf = tryToExctractICCProfile(iiometa);
                if (iccProf != null) {
                    ColorModel cm2 = new ComponentColorModel(
                            new ICC_ColorSpace(iccProf), cm.hasAlpha(), cm
                                    .isAlphaPremultiplied(), cm
                                    .getTransparency(), cm.getTransferType());
                    WritableRaster wr = Raster.createWritableRaster(imageData
                            .getSampleModel(), null);
                    imageData.copyData(wr);
                    BufferedImage bi = new BufferedImage(cm2, wr, cm2
                            .isAlphaPremultiplied(), null);
                    imageData = bi;
                    cm = cm2;

I removed this code and it works fine now, but it's dirty. What's the impact ?

Until a fix, best regards.
Comment 1 Glenn Adams 2012-06-01 20:10:23 UTC
patch (from bug 51149) applied at:

http://svn.apache.org/viewvc?rev=1345323&view=rev
Comment 2 patches 2012-06-20 15:18:19 UTC
Hi, 

We applied your patch but it dont fix my issue.
What information do you need about the PNG Image ?

Regards,
Comment 3 Luis Bernardo 2012-06-20 15:32:06 UTC
this bug is linked to bug 51149 but the issue may be different... the slowdown addressed by the patch appeared due to a change in the jdk, not from a change in xmlgraphics (from 1.3 to 1.4).

please provide the image so that the issue can be investigated. does it happen with all images or just some?
Comment 4 patches 2012-06-20 15:46:48 UTC
Created attachment 28971 [details]
PNG image
Comment 5 patches 2012-06-20 15:52:30 UTC
I attached the concerned PNG image.

The image is used inside a PDF document generated by FOP.
This image used by FOP 0.95+XmlGraphics 1.3.1 had no performance issue during the PDF generation.
Changing JDK has no effect in my case.
Comment 6 Luis Bernardo 2012-07-08 23:15:09 UTC
Created attachment 29041 [details]
an example to test icc profiles

the slowdown that happens between xmlgraphics-1.3 and xmlgraphics-1.4 is due to the fact that the color profiles were being ignored in 1.3 while in 1.4 they are taken into account, as the PNG specification suggests. so even though 1.3 was faster, it was not correct. the impact of removing the check for color profile is that the output may be wrong, although in most cases that does not happen because the color pixel values in the PNG image already match what the embedded color profile expects.

attached is an example with two images that look the same when viewed in an application that does not apply color profiles (like Chrome), but that look different when viewed with an application that applies the color profile (like Safari). the example, when processed with FOP-0.95 (xmlgraphics-1.3) generates two images that look the same, while with FOP-1.0 (xmlgraphics-1.4) the images look different.

a workaround, as was suggested somewhere else, is to remove the color profile from the image (this can be done with imagemagick). obviously this only works in the cases where the color profile is not adding anything new to the image. another option is to use the new raw png image loader, which for now, still ignores the color profile (of course, this will not help in the cases where the color profile is important).
Comment 7 Luis Bernardo 2012-08-15 21:48:00 UTC
as a follow-up to previous comment 6, see bug 40676, with attachment 29132 [details] (a patch that adds support for color profiles)