[cairo] How to flatten several data surfaces with transparency

Steve Moreau moreau.steve at free.fr
Mon Nov 5 22:06:53 PST 2012


Thank you guys,

I will try and let you know when it works.
Regards,

Steve


2012/11/5 Bill Spitzak <spitzak at gmail.com>

> Cairo wants pre-multiplied data for the OVER composite. This likely means
> that the green value should depend on y just like the alpha value does. Ie
> set the green to (y < 50 ? 0 : 50 * (y - 50)/height)
>
> Also I recommend filling in the buffer as 32-bit words, rather than bytes.
> This is faster and will make the it work on a big-endian machine.
>
> unsigned char* buf = (unsigned char*)malloc(4*width*height);
>   cairo_surface_t* dataSurface = cairo_image_surface_create_**for_data
> (buf, CAIRO_FORMAT_ARGB32, width, height, rowLen);
>   for (y=0; y<height; y++)
>   {
>     for (x=0; x<width; x++)
>     {
>       //setColor(&buf[y*rowLen+x*4], 0x00FF00, y*255.0/3/height);
>       buf[y*rowLen+x*4+0] = 0;
>       buf[y*rowLen+x*4+1] = 50;
>       buf[y*rowLen+x*4+2] = 0;
>       buf[y*rowLen+x*4+3] = (y < 50 ? 0 : (y-50)*255.0/height);
>     }
>   }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20121106/48cd2bdb/attachment.html>


More information about the cairo mailing list