Bug 12185 - Poppler does not correctly handle knockout groups
Summary: Poppler does not correctly handle knockout groups
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: splash backend (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-27 13:39 UTC by Carl Worth
Modified: 2012-04-29 07:03 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
PDF file demonstrating bug (over-below-source) (3.48 KB, application/pdf)
2007-08-27 13:46 UTC, Carl Worth
Details
Buggy, poppler rendering of over-below-source (481 bytes, image/png)
2007-08-27 13:47 UTC, Carl Worth
Details
Desired rendering of over-below-source (434 bytes, image/png)
2007-08-27 13:51 UTC, Carl Worth
Details
Here a small appetiser (101.89 KB, image/png)
2012-04-19 06:06 UTC, Thomas Freitag
Details
Implementation of knockout groups in splash (5.30 KB, patch)
2012-04-26 01:13 UTC, Thomas Freitag
Details | Splinter Review
New implementation of knockout groups in splash (6.94 KB, patch)
2012-04-28 03:26 UTC, Thomas Freitag
Details | Splinter Review
Correct patch (8.05 KB, patch)
2012-04-28 03:36 UTC, Thomas Freitag
Details | Splinter Review

Description Carl Worth 2007-08-27 13:39:06 UTC
Current work within cairo uses knockout groups to render fine-grained
image-based fallbacks for cairo operations that are not directly
supported by PDF.

When rendering these cairo files with poppler, it's clear that the
knockout groups are not being handled correctly.

I'll attach some simple examples to show the problem.

-Carl
Comment 1 Carl Worth 2007-08-27 13:46:08 UTC
Created attachment 11295 [details]
PDF file demonstrating bug (over-below-source)

This file should show a vector, translucent green circle with an image
of a traslucent, red triangle above it, but in a knockout group so
that it completely obscures the circle.

Expressed in cairo terms, the circle is rendered with the OVER
operator, while the triangle is rendered with the SOURCE operator.

Currently, poppler is blending the triangle with the circle, rather
than obscuring the circle.

I've verified that acroread renders the file as desired.

I'll attach a couple of renderings to make things clear.

-Carl
Comment 2 Carl Worth 2007-08-27 13:47:17 UTC
Created attachment 11296 [details]
Buggy, poppler rendering of over-below-source
Comment 3 Carl Worth 2007-08-27 13:51:22 UTC
Created attachment 11297 [details]
Desired rendering of over-below-source

NOTE: This rendering contains translucence while the buggy rendering
has been flattened against a white background. This difference is
indicental. The bug I'm trying to demonstrate is the difference in the
region of the image where the triangle and the circle overlap.

Also, we should soon be pushing the necessary changes to cairo so that
generating these images is as simple as "make check". Stay tuned.

-Carl
Comment 4 Albert Astals Cid 2007-08-27 13:56:35 UTC
Moving to general, splash seems to have the same problem.
Comment 5 Carl Worth 2007-08-27 14:54:47 UTC
(In reply to comment #3)
> Also, we should soon be pushing the necessary changes to cairo so that
> generating these images is as simple as "make check". Stay tuned.

The support for fine-grained fallbacks in cairo PDF output has now
been pushed out to cairo's master branch. However, the tests that
exercise this bug have now been disabled in cairo's test suite. So to
exercise this bug with cairo's test suite requires editing
cairo/boilerplate/cairo-boilerplate-pdf.c and removing the desired
test names from the pdf_ignored_tests list.

The 7 affected tests are clip-operator, operator-clear,
operator-source, over-above-source, over-around-source,
over-below-source, and over-between-source.

-Carl
Comment 6 Jeff Muizelaar 2007-08-29 20:19:09 UTC
Adding support for this to the cairo backend will require some work. Supporting knockout groups requires tracking shape and opacity seperately. The cairo backend currently implements transparency groups using cairo_push/pop_group, but these do not help with tracking shape. However, support should be possible by tracking shape with an additional CAIRO_CONTENT_ALPHA surface.
Comment 7 Carl Worth 2007-09-20 13:41:11 UTC
(In reply to comment #6)
> Adding support for this to the cairo backend will require some work. Supporting
> knockout groups requires tracking shape and opacity seperately. The cairo
> backend currently implements transparency groups using cairo_push/pop_group,
> but these do not help with tracking shape. However, support should be possible
> by tracking shape with an additional CAIRO_CONTENT_ALPHA surface.

I did try an experiment to implement something very much like the
example in plate 17 of the PDF reference, (a 2x2 matrix showing the
effects of knockout and isolated grouups). And yes, it will be a bit
tricky to do that completely. I think it will require two passes over
the group in some cases, as you suggest.

But, for the limited use of knockout groups that cairo is currently
emitting, you should be able to get by with something much
simpler. For example, just drawing all objects within the group with
CAIRO_OPERATOR_SOURCE should do the trick.

It might indeed be very worthwhile to start with just that, and then
later flesh out more complete support for all the combinations of
knockout and isolated groups as required.

Let me know if you have any more questions about that.

-Carl


Comment 8 Jeff Muizelaar 2007-09-20 14:09:08 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > Adding support for this to the cairo backend will require some work. Supporting
> > knockout groups requires tracking shape and opacity seperately. The cairo
> > backend currently implements transparency groups using cairo_push/pop_group,
> > but these do not help with tracking shape. However, support should be possible
> > by tracking shape with an additional CAIRO_CONTENT_ALPHA surface.
> 
> I did try an experiment to implement something very much like the
> example in plate 17 of the PDF reference, (a 2x2 matrix showing the
> effects of knockout and isolated grouups). And yes, it will be a bit
> tricky to do that completely. I think it will require two passes over
> the group in some cases, as you suggest.
> 
> But, for the limited use of knockout groups that cairo is currently
> emitting, you should be able to get by with something much
> simpler. For example, just drawing all objects within the group with
> CAIRO_OPERATOR_SOURCE should do the trick.

This falls apart as soon as you have a group inside the knock-out group. Which is what the pdf generated by cairo has.

e.g.

cairo_set_source_arg(0.8, 0, 0, 0.5);
cairo_set_operator(SOURCE);
draw_square();

draw_circle_in_square();


has a very different result (circle inside square) than


cairo_set_source_arg(0.8, 0, 0, 0.5);
cairo_set_operator(SOURCE);
draw_square();

cairo_push_group();
draw_circle_in_square();
cairo_pop_group_to_source();
cairo_paint();

which paints a circle and clears the rest of the surface. (arguably not what you'd expect when using push/pop_group()).

I have a very hacked up poppler tree that tries to do proper shape and opacity tracking. The output is currently 'correct' except it looks bad (seams) because of the lack of EXTEND_PAD.

-Jeff
Comment 9 Jeff Muizelaar 2007-11-12 18:54:20 UTC
Should be fixed in git (for the cairo backend of course)
Comment 10 Albert Astals Cid 2009-09-16 15:51:46 UTC
Reopening for the Splash backend
Comment 11 Thomas Freitag 2012-04-19 06:01:43 UTC
(In reply to comment #10)
> Reopening for the Splash backend

I had a look at it: in the current splash implementation the knockout for transparency groups was missing. Because it's the same area as Bug 13487 I'll fix it together with it in 0.22.0 (if Albert accepts it)
Comment 12 Thomas Freitag 2012-04-19 06:06:43 UTC
Created attachment 60310 [details]
Here a small appetiser

Produced with my current code. Unnecessary to say, that of course also the over-below-source PDF works now in splash
Comment 13 Thomas Freitag 2012-04-26 01:13:23 UTC
Created attachment 60600 [details] [review]
Implementation of knockout groups in splash

Ok, let's continue with this one. This should implement knockout groups in splash
Comment 14 Albert Astals Cid 2012-04-26 10:14:12 UTC
It fixes the bug, but the letters in https://bugs.launchpad.net/ubuntu/+source/poppler/+bug/817626/+attachment/2238754/+files/512 pages SAMPLE.pdf get too much "punched" seems to me the old rendering is much closer (if not exact) to what Adode renders, any idea why?
Comment 15 Thomas Freitag 2012-04-28 03:26:48 UTC
Created attachment 60726 [details] [review]
New implementation of knockout groups in splash

In the way splash implements shape and antialiasing effects my first implementation also knockouts these effects. The new implementation is now much trickier and leave these effects untouched. Also the PDF file demonstrating this bug looks a little bit smarter with the new implementation, i.e. it looses now the white line between triangle.
Your sample of comment 17 still has some but now very small, nearly unvisible changes.
Comment 16 Thomas Freitag 2012-04-28 03:36:47 UTC
Created attachment 60728 [details] [review]
Correct patch

Sorry, I uploaded not the patch but an intermediate state, Here the one I really regtested.
BTW, in comment 15 I meant "white line between circle and triangle", and I want to point to the PDF of comment 14.
Comment 17 Albert Astals Cid 2012-04-29 07:03:58 UTC
Fixed fox Splash too


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.