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

Benjamin Berg <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Hi,

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
 https://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t

Regards,
Benjamin

> 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
> incorrect.
> 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.set_line_width(0.01)
> 
> cr.rectangle(0, 0, 0.5, 1)
> cr.set_source_rgba(1, 1, 1, 0/255.0)
> cr.fill()
> 
> cr.set_source_rgba(1,1,1, 1/255.0)
> cr.rectangle(0.5,0,1,1)
> cr.fill()
> 
> surface.write_to_png(filename + '.png')
> cr.show_page()
> surface.finish()
> 
> 
> 
-- 
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.