Re: How to flatten several data surfaces with transparency

Bill Spitzak <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[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
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.