Re: How to flatten several data surfaces with transparency
Steve Moreau <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAD9K4eD0sbf9hfWgzpGFPP6YC0+J1KyohhSPUo1FshWqePZdeg@mail.gmail.com> |
Thank you guys, I will try and let you know when it works. Regards, Steve 2012/11/5 Bill Spitzak <[email protected]> > 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); > } > } > > -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo