Bug 38938 - cairo-1.10.2 renders RGB PNGs without blue channel (yellow colouring)
Summary: cairo-1.10.2 renders RGB PNGs without blue channel (yellow colouring)
Status: RESOLVED NOTOURBUG
Alias: None
Product: cairo
Classification: Unclassified
Component: png functions (show other bugs)
Version: 1.10.2
Hardware: Other All
: medium normal
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-03 18:36 UTC by Stuart Longland
Modified: 2011-07-07 14:53 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Test diagram from 'dia' (1.32 KB, application/octet-stream)
2011-07-03 18:36 UTC, Stuart Longland
Details
RGB PNG generated by dia directly (13.31 KB, image/png)
2011-07-03 18:39 UTC, Stuart Longland
Details
RGB PNG generated by dia using Cairo (10.27 KB, image/png)
2011-07-03 18:41 UTC, Stuart Longland
Details
RGBA PNG generated by dia using Cairo (11.90 KB, image/png)
2011-07-03 18:42 UTC, Stuart Longland
Details
Workaround different byte layout (514 bytes, patch)
2011-07-04 01:35 UTC, Andrea Canciani
Details | Splinter Review

Description Stuart Longland 2011-07-03 18:36:52 UTC
Created attachment 48722 [details]
Test diagram from 'dia'

Hi all...

Been chasing a few libpng-1.5 related issues, namely after porting dia across to libpng-1.5, I noticed it had a distinct yellow colouring to the exported image.

Affected machine is running Gentoo Linux i686.

Thinking this was a bug with dia, I dug a little further.  dia provides three options for exporting to PNG:

- Cairo PNG
- Cairo PNG (with alpha)
- PNG (anti-aliased)

The latter two work fine, as does the PNG export in Inkscape (which uses Cairo to generate RGBA PNGs as far as I know).  The former one lacks the blue channel.  I still wasn't sure if this was a result of my porting or not, so I left it at that point.

Then I noticed graphviz on my other system (running the AMD64 variant of Gentoo), also using libpng-1.5, started misbehaving with respect to PNG image generation with the same symptoms.

Lo and behold, I try the same thing on this i686 system, and the images once again come out yellow in colour.  Two different programs, two different systems, same bug.

Going back to dia, I have created a test diagram which I have tried to export as PNG using all three methods.  I shall attach the diagram now, and the results in a moment.  You will notice that the RGB PNG generated by dia itself (without Cairo), and the RGBA PNG generated by Cairo are fine, but the RGB PNG generated by Cairo lacks the blue channel.

I haven't yet gone digging to find out why, nor have I seen other bug reports that would indicate what is going on.

Regards,
Stuart Longland
Comment 1 Stuart Longland 2011-07-03 18:39:11 UTC
Created attachment 48723 [details]
RGB PNG generated by dia directly

/tmp/test-png.png: PNG image data, 238 x 139, 8-bit/color RGB, non-interlaced

Generated by selecting "PNG (anti-aliased)" within dia.
Comment 2 Stuart Longland 2011-07-03 18:41:02 UTC
Created attachment 48724 [details]
RGB PNG generated by dia using Cairo

/tmp/test-cairo-rgb.png: PNG image data, 238 x 139, 8-bit/color RGB, non-interlaced

Generated by selecting "Cairo PNG" in dia.
Comment 3 Stuart Longland 2011-07-03 18:42:18 UTC
Created attachment 48725 [details]
RGBA PNG generated by dia using Cairo

/tmp/test-cairo-rgba.png: PNG image data, 238 x 139, 8-bit/color RGBA, non-interlaced

Generated by selecting "Cairo PNG (with alpha)" within dia.
Comment 4 Andrea Canciani 2011-07-04 01:35:37 UTC
Created attachment 48735 [details] [review]
Workaround different byte layout

It looks like the byte layout libpng15 expects is different from that used in previous library versions.
This might be actually caused by something we forgot to initialize, but it certainly looks suspect.

The attached patch seems to work around the issue, but it breaks png generation on libpng1{2,4}.
Comment 5 Stuart Longland 2011-07-04 06:10:52 UTC
Yep, that fixes it.  It'd be worth finding out what changed, or what's not being done properly.

As a short-term solution, it could probably be #ifdef'd to handle older libpng, as ugly as that solution is.

Thanks for the assistance.
Comment 6 Andrea Canciani 2011-07-07 07:08:37 UTC
(In reply to comment #5)
> Yep, that fixes it.  It'd be worth finding out what changed, or what's not
> being done properly.
> 
> As a short-term solution, it could probably be #ifdef'd to handle older libpng,
> as ugly as that solution is.
> 
> Thanks for the assistance.

The bugfix for the issue you're seeing seems to be available in recent (unstable) libpng versions.
In the ChangeLog:
Version 1.5.3beta03 [April 16, 2011]
[...]
Fixed bug with stripping the filler or alpha channel when writing, that
was introduced in libpng-1.5.2beta01 (bug report by Andrew Church).

The relevant commit is:
http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng/libpng;a=commitdiff;h=cb1aee250698490a4117797c398f93c5a089f95f;hp=8d4ce1fed58e96970ba4c30f39ea4a7712abaeaa

Please reopen if you manage to reproduce the problem even with the just-released libpng 1.5.4:
http://sourceforge.net/projects/libpng/files/libpng15/1.5.4/

(I managed to reproduce the bug with 1.5.2, but 1.5.4 seems to be ok)
Comment 7 Stuart Longland 2011-07-07 14:53:42 UTC
Okay, that is interesting…

I shall give the newer libpng a try (running 1.5.2 at present) after rebuilding cairo without attachment 48735 [details] [review].

The reason why I presumed Cairo was to blame is that whenever it was used to render PNGs in Dia, it had this effect.  Whenever dia used libpng directly, it worked fine, as can be seen by attachments 48723 and 48724.

Both Dia and Cairo use the same libpng.  Why does it magically JustWork in Dia, but not Cairo?


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.