[cairo] Color-Tinting a surface with alpha channel

Uli Schlachter psychon at znc.in
Sat Dec 26 08:09:22 UTC 2020


Hi,

Am 25.12.20 um 21:09 schrieb Simon Schneegans:
> But I am afraid your method does not yet accomplish my goal.
[...]
> But if you replace the checkerboard with a white
> background you receive this image:
[...]
> If you use e.g. Gimp to look at the color channels you see that there is
> a darkening in the red channel which shouldn't be there:
[...]

well... [/me investigates for a moment]... my copy_with_content()
function does not actually do what it is supposed to do. Copying the
original ARGB32 surface to an RGB24 surface behaves "as if" the ARGB32
surface is drawn on a black background. Put differently, this just
copies out the pre-multiplied pixel values, but we want/need the
unmultiplied pixel values. Something needs to divide the color
components by the alpha value for this approach to work.

A first idea would be to fill the color-components surface with white
and then drawing the ARGB32 to_tint-surface with OVER. That makes the
red gradient work (it ends up as all-white in the color-components
surface), but of course it breaks the black gradient, because that one
now also gets some white "mixed in" which is then tinted red.

Hm... division by the alpha value is needed. Looking through the list
over compositing operators, OVER, DEST_OVER, XOR, SATURATE, and the
blend modes contain division by the alpha value, but all of these
multiply with the alpha value first. Thus, that cannot do what we need here.

I think my approach cannot work correctly, sorry. :-(

Cheers,
Uli
-- 
This can be a, a little complicated. Listen, my advice is... ask
somebody else for advice, at least someone who's... got more experience
at...  giving advice.


More information about the cairo mailing list