[cairo] [Fwd: CAIRO_OPERATOR_SOURCE issue]

Clemens Eisserer linuxhippy at gmail.com
Sat May 8 03:14:40 PDT 2010


Hi,

Looks like CAIRO_FORMAT_ARGB32 is premultiplied, so the resulting
color already contains the alpha-value multiplied in.

- Clemens

2010/5/8 Carl Banks <pythondev1 at aerojockey.com>:
> Hello list.  Here's a little code to demonstrate an issue I'm having.
>
>
> #include <stdio.h>
> #include <cairo.h>
>
> int main(void) {
>    cairo_t *cr;
>    cairo_surface_t *surface;
>    unsigned char *data;
>
>    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,1,1);
>    cr = cairo_create(surface);
>    cairo_set_operator(cr,CAIRO_OPERATOR_SOURCE);
>    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.2);
>    cairo_paint(cr);
>    cairo_destroy(cr);
>
>    data = cairo_image_surface_get_data(surface);
>
>    printf("Cairo version: %s\n",cairo_version_string());
>    printf("Color: (%d,%d,%d,%d)\n",data[1],data[2],data[3],data[0]);
> }
>
>
> I get the following output:
>
> Cairo version: 1.8.10
> Color: (51,51,51,51)
>
>
> But I expect this output:
>
> Cairo version: 1.8.10
> Color: (255,255,255,51)
>
>
> What's wrong: Cairo, my usage, or my understanding of
> CAIRO_OPERATOR_SOURCE?  If it's the latter, how can I initialize a
> surface to something like (255,255,255,51)?
>
> It's not helpful to work around it by manipulating data directly,
> because my real use case involves more complex rendering.
>
> Thanks.
>
>
> Carl Banks
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list