Bug 692265 - Colors distorted when breaking up a PDF into images
Summary: Colors distorted when breaking up a PDF into images
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Color (show other bugs)
Version: 9.02
Hardware: All All
: P4 normal
Assignee: Michael Vrhel
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-08 18:36 UTC by bhapca
Modified: 2011-06-11 23:34 UTC (History)
2 users (show)

See Also:
Customer:
Word Size: ---


Attachments
the PDF that fails (15.88 MB, application/pdf)
2011-06-08 18:36 UTC, bhapca
Details
Simplified sample file. (175.26 KB, application/pdf)
2011-06-09 00:09 UTC, Alex Cherepanov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bhapca 2011-06-08 18:36:41 UTC
Created attachment 7578 [details]
the PDF that fails

When using ghostscript to break up the attached PDF into PNG images, corresponding to each page, the colors on the cover page get distorted.

This seems to be a regression bug, as it works fine in version 8.71, but fails in 9.02.

I'm using the following switches when invoking gs:

$cmd = GS_BINARY_PATH." -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -dTextAlphaBits=4  -dGraphicsAlphaBits=4 -dUseCropBox -sOutputFile=$folderBase/full/image-%d.png -r100  $folderBase/pub.pdf";

Tested on both MacOS and CentOS, with the same result.
Comment 1 Alex Cherepanov 2011-06-09 00:09:07 UTC
Created attachment 7581 [details]
Simplified sample file.

Changing the color space in 12 0 obj to /DeviceRGB or /DeviceGray has dramatic effect on Ghostscript but no visible effects on AR9 or Evince.
Comment 2 Michael Vrhel 2011-06-09 04:26:36 UTC
Alex,

What do you mean "changing" the color space in 12 0 obj?  I went in and did the change from DeviceCMYK to DeviceGray and DeviceRGB in the PDF file and AR no longer opens the file.  I also ran your simplified file as it stands and it looks fine to me.  Could you clarify what the simplified file is showing? 

If you change the color space 12 0 I would expect to see some changes as it changes the transparency group color space.
Comment 4 Michael Vrhel 2011-06-09 04:50:50 UTC
With the simplified file bug692265_simple.pdf  the file will render properly to a CMYK based device (e.g. tiff32nc) but not to an RGB based device (e.g. tiff24nc) this is regardless of the antialiasing parameters nor the multipage output settings the user reported on the command line.  The simplified file consists of an image and a softmask with a path fill.  The source of the problem is that there appears to be some color space confusion with respect to the transparency groups.
Comment 5 Michael Vrhel 2011-06-09 05:54:07 UTC
So this is a strange one.  I have found that the color conversion that is done on a transparency buffer to go from CMYK to RGB is giving the wrong result.  The input data coming in seems to be fine.  The output is the weird colors that we see in the simple file.  I am a bit surprised to see this as we should have files in the regression tests for this case.  Need to see when exactly this broke.
Comment 7 James Cloos 2011-06-09 19:38:52 UTC
Using gentoo’s mildly patched version of gs 9.02 and the x11alpha device, I get the wrong colours with:

:; gs -dBATCH -sDefaultCMYKProfile=default_cmyk.icc ic.pdf

but get the correct colours with:

:; gs -dBATCH -sDefaultCMYKProfile=ps_cmyk.icc ic.pdf

With my compile of ghostpdl git and pspcl6, -sDefaultCMYKProfile doesn't seem to change anything, but soft linking ./default_cmyk.icc to the other profile files does.  With that in place, 

I tried a few other, real CMYK profiles; those had the same type of issues with that pdf as gs’s default_cmyk does.  Only ps_cmyk rendered that pdf properly.

Even weirder, specifying a different rgb profile also fixed the rendering, such as:

:; gs -dBATCH -sDefaultRGBProfile=/usr/share/color/icc/Display_Profiles/AdobeRGB1998.icc ic.pdf
:; gs -dBATCH -sDefaultRGBProfile=/usr/share/color/icc/sRGB/sRGB_type2.icc ic.pdf

(Adjust paths as needed.  And notice that the second one is an sRGB profile.)

This also works fine:

:; gs -dBATCH -sDefaultRGBProfile=ps_rgb.icc ic.pdf

It seems that the bug only happens with the combination of a measured cmyk profile (including your default_cmyk.icc) and your default_rgb.icc.

Maybe that will help narrow it down?

mupdf (also git master) had no problem with it.
Comment 8 James Cloos 2011-06-09 19:42:34 UTC
I seem to have lost a bit of text while editing....

please s/with that in place,/with that in place, pspcl6 gives the same results as the system gs does with -sDefaultCMYKProfile./
Comment 9 Michael Vrhel 2011-06-09 21:04:36 UTC
Ah.  Good catch on the profile differences.  This points me to the issue which is that the profile used during the softmask rendering is remaining around during the transparency group pop.  I will dig into this.