[cairo] RGB channels are set to zero if alpha is 0.
benjamin at sipsolutions.net
Sun Aug 27 10:41:10 UTC 2017
On Sat, 2017-08-26 at 17:55 -0700, Bram Stolk wrote:
> Cairo is treating colours with alpha=zero incorrectly.
> If alpha is zero, the red green and blue channels are zeroed by cairo, even
> if they contain non zero r/g/b values.
Please remember that pixman stores the data premultiplied. Because of
this it should be the expected behaviour that the 1,1,1,0 colour from
the left half of the image becomes 0,0,0,0 (even if you did set the
operator to CAIRO_OPERATOR_SOURCE so that the paint is not a no-op).
See also the documentation on CAIRO_FORMAT_ARGB32 in
> To demonstrate this bug, I wrote this python-cairo program that
> creates an
> image with two colours.
> The left half of the image is set to 1,1,1,0.
> The right half of the image is set to 1,1,1,1
> When cairo writes out the PNG, the left half of the image is
> The pixels are 0,0,0,0 instead of 1,1,1,0.
> The test program:
> #! /usr/bin/env python
> import cairo
> from math import pi, sqrt
> width = 120
> height = 120
> filename = "out"
> surface = cairo.SVGSurface(filename + '.svg', width, height)
> cr = cairo.Context(surface)
> cr.scale(width, height)
> cr.rectangle(0, 0, 0.5, 1)
> cr.set_source_rgba(1, 1, 1, 0/255.0)
> cr.set_source_rgba(1,1,1, 1/255.0)
> surface.write_to_png(filename + '.png')
More information about the cairo