[cairo] Creating an opaque fade-in effect with Cairo

Tristan Schmelcher tschmelcher at google.com
Thu Jan 20 13:54:15 PST 2011


I am developing a Cairo-based application and I'd like to fade-in an
opaque image on top of a background. i.e., I want the image to start
out as opaque black and gradually fade-in to its full brightness. But
I can't figure out how to efficiently paint my image surface to the
screen and attenuate the RGB channels at the same time. Ideally I'm
looking for an API that lets me paint my source surface (the image)
and takes a fractional brightness parameter in the range [0, 1] to
multiply with each of the R, G, and B channels. So far the best that I
have come up with is to first paint with CAIRO_OPERATOR_CLEAR and then
paint with CAIRO_OPERATOR_OVER and cairo_mask(), but that seems like a
lot of computational work. Is there a more efficient way to do this
with Cairo?

Tristan Schmelcher

More information about the cairo mailing list