[cairo] Pixman copies unused alpha bits to alpha channels

Carl Worth cworth at cworth.org
Tue Sep 4 17:26:01 PDT 2007


Cairo's CAIRO_FORMAT_RGB24 format is documented as:

	CAIRO_FORMAT_RGB24: each pixel is a 32-bit quantity, with
	the upper 8 bits unused.

But the implementation does not appear to be ignoring the upper 8
bits. I've just pushed out a new test that tries to draw 2x2 green
pixels as follows:

    /* Four green pixels with different "alpha" values, (but which
     * should be entirely ignored). */

    uint32_t colors[4] = {
        0xff00ff00, 0x8800ff00,
        0x4400ff00, 0x0000ff00
    };

    surface = cairo_image_surface_create_for_data ((unsigned char *) colors,
                                                   CAIRO_FORMAT_RGB24,
						   2, 2, 8);

    cairo_set_source_surface (cr, surface, 0, 0);
    cairo_paint (cr);

This code gives the desired four opaque pixels when the destination is
also RGB24 but actually gives a different result for each pixel when
the destination is ARGB32(!). It looks like it's simply copying the
values, so that the unused values end up getting interpreted as alpha
values.

And after tracing the code a bit...

Here's a simple patch to pixman that seems to fix the problem, (but
making this case go through the slow path). Does faster code exist in
pixman that's correct for this case? Or would someone care to quickly
bang some out?

-Carl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Don-t-copy-unused-bits-to-an-alpha-channel.patch
Type: application/octet-stream
Size: 0 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20070904/a0f59dc5/attachment.obj 


More information about the cairo mailing list