After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 783528 - PDF export ignores layer masks
PDF export ignores layer masks
Status: RESOLVED OBSOLETE
Product: GIMP
Classification: Other
Component: Plugins
2.8.22
Other All
: Normal normal
: 2.8
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2017-06-07 19:44 UTC by Simon Müller
Modified: 2018-05-24 17:54 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Simon Müller 2017-06-07 19:44:09 UTC
Whenever I try to export an image with layer masks to pdf, the export plugin completely ignores any layer masks - no matter whether the checkbox "apply layer masks before saving" is active or not. In the resulting pdf the layers are stacked as expected but they have no transparent parts, so only the top layer is visible. When I apply the layer masks by hand before exporting, everything works as expected.

Expected behavior: Layer masks on image layers should cause transparency in the corresponding layers of the pdf.
Comment 1 Jehan 2017-06-14 23:37:15 UTC
I confirm this issue. This should not be too hard to fix. Adding a newcomers keyword.
Comment 2 Jehan 2017-06-16 14:52:52 UTC
On GIMP master, there were a few issues. First an inversion on the "Apply layer masks" option. When unchecked, the mask would be applied, and when checked, it would be ignored.

Fixed with:

commit 0bd94f172ae960c0229d925e08e489ec07cd8fa0
Author: Jehan <jehan@girinstud.io>
Date:   Thu Jun 15 20:53:55 2017 +0200

    plug-ins: properly "Apply layer masks before saving" when checked.
    
    The `if` test was inverted. When the option is checked, we don't want to
    add the GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS capability so that
    gimp_export_image() applies the mask.
    This is a first step to fix bug 783528, but it's not finished. Right
    now, when the option is unchecked, the mask is simply ignored. We want
    to export a PDF mask instead.

 plug-ins/common/file-pdf-save.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

------------------------------------

The second issue was that cairo_mask_surface() uses the alpha channel of the surface it is handled but we were copying 'Y u8/u16/…' data. So we needed to change the data type (i.e. the babl format) before copying.

Now this is fixed, and tested in Scribus: when checked, the mask is applied into the bitmap (any data under the mask is forever modified); when unchecked, this creates a mask over the object (see for instance: https://blog.idrsolutions.com/2011/07/understanding-the-pdf-file-format-%E2%80%93-3-type-of-image-mask/) which can be removed for instance in Scribus and does not edit the pixels.

commit 85c0373489a0bafd16774350c4023b493c39e727
Author: Jehan <jehan@girinstud.io>
Date:   Fri Jun 16 16:21:06 2017 +0200

    libgimpcolor: support CAIRO_FORMAT_A8 in gimp_cairo_surface_get_format()

 libgimpcolor/gimpcairo.c | 1 +
 1 file changed, 1 insertion(+)

commit dd6dab113e5da0cb1af7a588ada3b09d226f2f1f
Author: Jehan <jehan@girinstud.io>
Date:   Fri Jun 16 16:23:38 2017 +0200

    Bug 783528 - PDF export ignores layer masks.
    
    Cairo doc is pretty clear about cairo_mask_surface():
    > A drawing operator that paints the current source using the alpha
    > channel of @surface as a mask
    Therefore when creating a mask surface, it must be in one of
    CAIRO_FORMAT_* with an alpha channel and the mask data must be copied
    into this alpha channel. I chose CAIRO_FORMAT_A8 (a format with alpha
    only) which I map to "Y u8" babl format in GEGL so that
    gegl_buffer_copy() copies the contents of Y into A.

 plug-ins/common/file-pdf-save.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
Comment 3 Jehan 2017-06-16 15:04:21 UTC
Note: I wanted to cherry-pick my commits into gimp-2-8 but I realized that the implementation is different since it was not using GEGL in 2.8 (only the first of the 3 commits were cherry-picked). Now I'm pretty sure the fix is similar (mask data must go in the alpha channel of the surface), but I don't want to spend too much time on this since I prefer to focus on getting 2.10 out.

So I will reopen since the bug is still there on 2.8.
If someone wants to fix 2.8, now that you know the likely issue, feel free.
Comment 4 GNOME Infrastructure Team 2018-05-24 17:54:39 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gimp/issues/1110.