[cairo] RGB channels are set to zero if alpha is 0.

Bill Spitzak spitzak at gmail.com
Mon Aug 28 17:31:30 UTC 2017


src/cairo-png.c has an unpremultiply_data function that is explicitly
setting the output to zero if the alpha is zero, to avoid
divide-by-zero. (It outputs a garbage value of (c/a)%256 if the alpha
is non-zero but less than any of the color channels). Note that some
work I have seen with trying to support unpremultiplied it is far more
common to output ((!c || c>a) ? c : c/a).

IMHO it is probably better for Cairo to write and read the channels
unchanged. Despite the spec, the majority of png files actually are
premultipled, since the majority of software just writes their
channels unchanged to the png library, and almost all compositing
graphics (including Cairo) more naturally works with premultiplied
data. Nuke at one time tried to guess whether it was premultipled, but
this had to be abandoned as the guess would screw up people using
emission color like you and it quickly became clear that almost all
images are premultiplied.

Removing this conversion from Cairo would probably be a good idea. It
would make Cairo match other software, it would remove surprises for
uses such as you, it would be faster, and write+read of png data would
be lossless. Use the fact that it is the "toy" api if you want an
excuse for ignoring the png spec.


On Sun, Aug 27, 2017 at 11:55 AM, Guillermo Rodriguez
<guillerodriguez.dev at gmail.com> wrote:
>
> El domingo, 27 de agosto de 2017, Bram Stolk <b.stolk at gmail.com> escribió:
>>
>> I must say that PNG then makes for a very poor choice of writing to by
>> Cairo.
>
>
> Note that PNG support in Cairo is explicitly described as a "toy API",
> intended to be used for testing and quick demos, but not much more.
>
> Guillermo
>
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> https://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list