Bug 697860 - PDF with white background rendered as image with black background
Summary: PDF with white background rendered as image with black background
Status: CONFIRMED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Transparency (show other bugs)
Version: master
Hardware: All All
: P4 minor
Assignee: Robin Watts
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-04 16:11 UTC by Kenneth Chan
Modified: 2023-05-11 11:11 UTC (History)
4 users (show)

See Also:
Customer:
Word Size: ---


Attachments
faulting pdf (12.44 KB, application/pdf)
2017-05-04 16:11 UTC, Kenneth Chan
Details
modified file (118.63 KB, application/pdf)
2017-05-05 00:42 UTC, Ken Sharp
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Chan 2017-05-04 16:11:11 UTC
Created attachment 13642 [details]
faulting pdf

Following command to render a white PDF into a black image:

gs -dNOPAUSE -dBATCH -dQUIET -dNOPAGEPROMPT -sDEVICE=png16m -dGraphicsAlphaBits=4 -r100 -dFirstPage=1 -dLastPage=1 -sOutputFile=output.png >/dev/null 2>&1 white_black.pdf
Comment 1 Ken Sharp 2017-05-05 00:42:51 UTC
Created attachment 13643 [details]
modified file

This is caused by using GraphicsAlphaBits=4 and the construction of the PDF file.

Note that the file does not contain any images, so this is not an 'images' problem. All the content is linework (vector shapes).

All the objects are drawn using a graphics state with a constant alpha (ca) of 0, ie totally transparent, makes no marks, which is the only reason that the page is white.

I've attached a version of the file where the constant alpha has been removed, you can see this is very similar to the result when GraphicsAlphaBits is 4.

In short, GraphicsALphaBits (which long predates the presence of PDF transparency) cannot be relied upon when rendering transparent PDF files, because it operates in a way incompatible with the blending of PDF transparency. I've assigned this to our transparency expert to see (as a low priority) if there's any way to address this, but I strongly suspect the answer is no.

So don't use GraphicsAlphaBits (or TextAlphaBits) with transparent PDF files. If you want anti-aliasing for some reason, use the *scaled devices.
Comment 2 Michael Vrhel 2018-12-20 20:33:41 UTC
This should actually work fine.   The gdevabuf device does a copy_alpha call when its alpha buffer is to be flushed which ends up in pdf14_copy_alpha.  

The file renders properly in the non-clist case.  Going through the clist, the file renders wrong.  

Transfering the bug to Ray to have a look.
Comment 3 Peter Cherepanov 2020-12-26 04:25:11 UTC
The bug is reproduced in the current master branch on GNU/Linux and Android platforms.
Comment 4 Ray Johnston 2020-12-27 22:39:02 UTC
Michael's comment is not correct as far a I can tell. I get the same output
(Black background with 6 white "dots" along the bottom lower left) from
clist and non-clist:

gswin64c -dGraphicsAlphaBits=4 -sDEVICE=ppmraw -o pagemode.ppm -Z: faulting.pdf

and

gswin64c -dMaxBitmap=2g  -dGraphicsAlphaBits=4 -sDEVICE=ppmraw -o clist.ppm -Z: faulting.pdf

(and both give the all white page without -dGraphicsAlphaBits=4)

I'd like Michael to look at what might be going on with non-clist mode, taking
into account Ken's comment that it may not be fixable. Then if there is still
a clist mode difference I'll look into it.