Bug 690487 - Issues with transparency and GraphicsAlphaBits
Summary: Issues with transparency and GraphicsAlphaBits
Status: NOTIFIED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Images (show other bugs)
Version: master
Hardware: Macintosh MacOS X
: P2 normal
Assignee: Michael Vrhel
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-19 09:01 UTC by Marcos H. Woehrmann
Modified: 2011-10-02 02:35 UTC (History)
2 users (show)

See Also:
Customer: 536
Word Size: ---


Attachments
i4.pdf - decompressed sample file (1.31 KB, application/pdf)
2009-05-19 21:44 UTC, Alex Cherepanov
Details
simplified.pdf (4.58 KB, application/pdf)
2010-05-05 20:51 UTC, Michael Vrhel
Details
a possible fix to the build breakage in r11211 (2.29 KB, patch)
2010-05-10 04:10 UTC, Hin-Tak Leung
Details | Diff
A patch that should build.... (4.75 KB, patch)
2010-05-10 08:53 UTC, Michael Vrhel
Details | Diff
not_a_rectangle.png (2.21 KB, image/png)
2010-06-18 21:13 UTC, Henry Stiles
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marcos H. Woehrmann 2009-05-19 09:01:59 UTC
The customer reports errors with the combination of transparency and GraphicAlphaBits.  I've duplicated 
their problem with 8.64 and head (r9743).  Here is their original report:

We are facing some problems when using GS for interpreting the 'pdf' file. ( pdf file is attached. 
'BigBBoxTesting_1_Clipped.pdf').
 
We tried the png16m device ( to get RGB output) and pngalpha device ( to get RGB with transparency 
output). Also we tried different combinations for Graphics smoothing.
 
 
We used the following command lines to generate the output.
 
// Without Graphics smoothing. Without Transparency      // NoSmoothingNoAlpha.png
gswin32c -dSAFER -dBATCH -dNOPAUSE -r72 -sDEVICE=png16m -dGraphicsAlphaBits=1 -
sOutputFile="NoSmoothingNoAlpha.png" "BigBBoxTesting_1_Clipped.pdf"

// With Graphics smoothing. Without Transparency      // WithSmoothingNoAlpha.png
gswin32c -dSAFER -dBATCH -dNOPAUSE -r72 -sDEVICE=png16m -dGraphicsAlphaBits=4 -
sOutputFile="WithSmoothingNoAlpha.png" "BigBBoxTesting_1_Clipped.pdf"

// Without Graphics smoothing. With Transparency      // NoSmoothingWithAlpha.png
gswin32c -dSAFER -dBATCH -dNOPAUSE -r72 -sDEVICE=pngalpha -dGraphicsAlphaBits=1 -
sOutputFile="NoSmoothingWithAlpha.png" "BigBBoxTesting_1_Clipped.pdf"

// With Graphics smoothing. With Transparency       // WithSmoothingWithAlpha.png
gswin32c -dSAFER -dBATCH -dNOPAUSE -r72 -sDEVICE=pngalpha -dGraphicsAlphaBits=4 -
sOutputFile="WithSmoothingWithAlpha.png" "BigBBoxTesting_1_Clipped.pdf"

// Without Graphics smoothing. With Transparency. Resoultuin 300  // NoSmoothingWithAlpha_Big.png
gswin32c -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pngalpha -dGraphicsAlphaBits=1 -
sOutputFile="NoSmoothingWithAlpha_Big.png" "BigBBoxTesting_1_Clipped.pdf"
 
Following errors were observed.
1) Image "NoSmoothingNoAlpha.png" was OK.
2) Image "NoSmoothingWithAlpha.png" was OK.
3) Image "WithSmoothingNoAlpha.png" white color of the center region box converted to black.
4) Image "WithSmoothingwithAlpha.png" white color of the center rectangular area converted to black., 
also there was no transparency present in the center rectangular area.
5) In the last case "NoSmoothingWithAlpha_Big.png" we observed that by just changing resolution from 
72 dpi ( as in case of "NoSmoothingWithAlpha.png") to 300 dpi we lost the transparency in the image.
Comment 1 Marcos H. Woehrmann 2009-05-19 09:02:49 UTC
Created attachment 5023 [details]
BigBBoxTesting_1_Clipped.pdf
Comment 2 Ray Johnston 2009-05-19 09:45:21 UTC
Alex, please reassign this to Michael if it is another instance of smoothing
not working correctly with the pdf14 (transparency) compositor.
Comment 3 Alex Cherepanov 2009-05-19 21:44:14 UTC
Created attachment 5025 [details]
i4.pdf - decompressed sample file

This problem seems to be a bad interaction between pngalpha device and
pattern rendering. Occasionally, I've got unexpected results even with
-dGraphicsAlphaBits=1

The new sample file is a decompressed and modified version of the
original file. If the rectangle is filled (see the file) the bug disappears.
Comment 4 Alex Cherepanov 2009-05-19 22:05:55 UTC
This PS program generates filled boxes with the following
command line: gswin32c -dGraphicsAlphaBits=4 pat.ps
So, the bug is in the interaction between smoothing and pattern rendering.

%!
<< /PatternType 1 % Tiling pattern
   /PaintType 1 % Colored
   /TilingType 1
   /BBox [0 0 60 60]
   /XStep 60
   /YStep 60
   /box { 0 0 12 12 rectstroke } bind
   /PaintProc
     { begin
       0.3 setgray
       15 15 translate box
       30 30 translate box
       0.7 setgray
       -30 0 translate box
       30 -30 translate box
       end
    } bind
>> matrix makepattern setpattern 
120 120 184 120 4 copy
rectfill
0 setgray rectstroke
showpage

Comment 5 Alex Cherepanov 2009-05-21 11:28:33 UTC
Valgrind reports just 1 relevant error for
valgrind gs -dGraphicsAlphaBits=4 -sDEVICE=bmp16m -o /dev/null pat.ps

This software comes with NO WARRANTY: see the file PUBLIC for details.
Conditional jump or move depends on uninitialised value(s)
    at 0x8A7241: gx_default_copy_alpha (gdevdbit.c:281)
    by 0x8A5C28: abuf_flush_block (gdevabuf.c:218)
    by 0x8A5C7A: abuf_flush (gdevabuf.c:235)
    by 0x8A5CEB: mem_abuf_close (gdevabuf.c:246)
    by 0x842C99: alpha_buffer_release (gspaint.c:236)
    by 0x84348A: gs_stroke (gspaint.c:456)
    by 0x41A382: gs_rectstroke (gsdps1.c:298)
    by 0x41BB19: zrectstroke (zdps1.c:333)
    by 0x4BD42F: call_operator (interp.c:111)
    by 0x4BFD7F: interp (interp.c:1162)
    by 0x4BDAE3: gs_call_interp (interp.c:496)
    by 0x4BD91C: gs_interpret (interp.c:454)

It should be relatively easy to trace this back to the origin of the error.
Comment 6 Masaki Ushizaka 2009-08-13 02:14:54 UTC
Tried comment #4 ps code with r9980 on Mac OS X.  Reproduced filled rectangle with command line: 
'bin/gs -dGraphicsAlphaBits=4 -sDEVICE=x11 pat.ps'
Comment 7 Michael Vrhel 2009-10-27 13:35:54 UTC
Looked a bit at this.  It appears that there is a problem having 
gx_default_copy_alpha for the copy_alpha operation with the pattern 
accumulator.
Comment 8 Thomas Oehrling 2010-05-05 08:53:26 UTC
I can reproduce this bug with Ubuntu 9.10 and ghostscript 8.70. The update destroy my production redering system and I had to downgrade to ubuntu 8.04 with ghostscript version 8.63 to get the system back to a production state.
For me this Bug is realy important because all dependencys with imagemagick and pdf/eps transparency are broken too. This also effects a lot of other programs that using imagemagick.

For me a usefull pdf conversion is no longer given. Funny is that the Bug seems to effect not all types of pdf. I have a conversion from a eps to a PDF and than to a transparent PNG. In our environment I can reproduce that some of the PDF converted correct if the desitnation size is different. The basefiles are all standardised in our system thats why I am not thinking its a problem of different types of EPS or PDF files.

I'll hope this helps. If you need some more informations I will provide all I can find.
Comment 9 Michael Vrhel 2010-05-05 20:51:39 UTC
Created attachment 6258 [details]
simplified.pdf

A reduced example file that also has the issue.  Basically a pattern fill of a small rectangle.  The pattern itself consists of only a green stroke of a rectangle.
Comment 10 Hin-Tak Leung 2010-05-05 21:49:59 UTC
(In reply to comment #8)
> I can reproduce this bug with Ubuntu 9.10 and ghostscript 8.70. The update
> destroy my production redering system and I had to downgrade to ubuntu 8.04
> with ghostscript version 8.63 to get the system back to a production state.

I don't know if you want to go to that amount of trouble, but since you know it is between 8.63 and 8.70 (and it used to work in 8.63), you could try git bisect'ing to give a precise revision which breaks. (after git-svn clone'ing the ghostscript repository).
Comment 11 Thomas Oehrling 2010-05-05 22:45:55 UTC
For sure the 8.63 release version dount have this problem and since the 8.64 release it is broken. I tryed also some versions between 8.64 and 8.70 they all have the same bug. This is what I figured out today and get the server back to production. If I have a bit more time I'll take a deeper look to the git.
Comment 12 Hin-Tak Leung 2010-05-05 22:49:13 UTC
(In reply to comment #11)
> For sure the 8.63 release version dount have this problem and since the 8.64
> release it is broken....

That's useful - at least some of us can have a go at a smaller set of changes.
Comment 13 Michael Vrhel 2010-05-06 01:53:19 UTC
I have made a bit of progress on this.  It appears that the pattern_accum_get_bits_rectangle function is returning regions that were not drawn in, this is sort of mentioned in the comment (line 548 in gxpcmap.c).  What is happening in the non-transparency device case, is that chunks of uninitialized memory regions are getting passed along to the gx_default_copy_alpha function. On windows debug, these appear as 0xcdcdcd (205 205 205) gray for an rgb device.  Other systems or devices the regions may be black.  I can't imagine how this ever worked in the past as mentioned by the posts above.
Comment 14 Hin-Tak Leung 2010-05-06 05:58:55 UTC
(In reply to comment #12)
> (In reply to comment #11)
> > For sure the 8.63 release version dount have this problem and since the 8.64
> > release it is broken....

Sorry I think this is mis-information - I git bisect'ed and can't find the revision. Then I tried 8.15 
(http://koji.fedoraproject.org/koji/buildinfo?buildID=2800) and the problem was there with attachement 6258. Since you said you have downgraded to 8.63 - can you give this a try again?

I really think this is as Michael commented in comment 13, it has never worked. 
This is probably the same problem as bug 690865 and bug 691181 . (and possibly other rendering bugs with the x11alpha device).
Comment 15 Michael Vrhel 2010-05-07 16:51:17 UTC
I should have a fix for this shortly but I need to do a bit of testing.  It appears that simply initializing the pattern bit buffer to white, fixes the issue since we are then not accessing uninitialized data during the pattern get_bits operation when we are in the gx_default_copy_alpha operation.  One thing I have observed is that using alphabits when the output device is CMYK based for this file results in wrong colors.  I want to take a quick look at that issue too.  It appears to me that gx_default_copy_alpha has problems with respect to this.
Comment 16 Michael Vrhel 2010-05-09 23:11:16 UTC
Fixed with rev 11211.
Comment 17 Hin-Tak Leung 2010-05-10 04:10:00 UTC
Created attachment 6271 [details]
a possible fix to the build breakage in r11211

r11211 breaks builds, and was reverted in r11212. The problem is that alpha_buffer_bits() was added to gsutils.c which mkromfs depends on; so building mkromfs fails with unsatistied dependencies. Here is a possible fix - adding alpha_buffer_bits() to gsalpha.{h,c} instead of gsutils.{h,c}.

I don't think this is the correct answer - the correct answer probably involves some re-factoring, but in any case, adding alpha_buffer_bits() to some other files than gsutils.{h,c} and gsalpha.{h,c}.
Comment 18 Michael Vrhel 2010-05-10 08:53:19 UTC
Created attachment 6272 [details]
A patch that should build....

A patch that should build and work properly.
Comment 19 Hin-Tak Leung 2010-05-10 12:59:13 UTC
r11213 builds alright on linux.
Comment 20 Hin-Tak Leung 2010-05-10 13:04:18 UTC
Tried the original pdf file and also the the pat.ps in comment 4. works like a charm.
Comment 21 Henry Stiles 2010-06-18 21:13:44 UTC
Created attachment 6385 [details]
not_a_rectangle.png

There are still problems here, the attached png was rendered with:

./gs -dGraphicAlphaBits=4 -sDEVICE=pngalpha -sOutputFile=foo.png test2.pdf

and part of the rectangle is missing.  test2.pdf is the file name for Michael's simplified.pdf file attached to this bug.
Comment 22 Michael Vrhel 2010-06-21 17:41:45 UTC
Reopening to figure out png problem.
Comment 23 Michael Vrhel 2011-04-02 06:15:48 UTC
Not sure when this was fixed, but it appears to work fine for me now with rev 12345