Re: RGB channels are set to zero if alpha is 0.

Bill Spitzak <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAL-8oAgLo6O6o1DGQ1W+hPr4cB7C2px4krdc0pa1KoMLOzA_Ug@mail.gmail.com>
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
<[email protected]> wrote:
>
> El domingo, 27 de agosto de 2017, Bram Stolk <[email protected]> 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
> [email protected]
> https://lists.cairographics.org/mailman/listinfo/cairo
-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.