[cairo] Stange alpha channel problem.

Paul Giblock drfaygo at gmail.com
Tue Jun 13 12:53:22 PDT 2006


First, I would like to thank the Cairo developers for providing such a
nice library. I have been using Cairo for several months with my
custom toolkit under X11. My problem is related to drawing RGBA images
(currently png) to my cairo surface.

The following code is what I use to draw an image, img, at (x,y)
clipped by the rectangle: (cx,cy) [cw, ch].

    cairo_save(m_context);
    cairo_rectangle(m_context, x, y, cw, ch);
    cairo_clip(m_context);
    cairo_new_path(m_context);
    cairo_set_source_surface(m_context, img, x-cx, y-cy);
    cairo_paint(m_context);
    cairo_restore(m_context);

This works, in that the image is displayed in the right place and is
properly clipped.  Unfortunately, the areas of the surface underneith
the transparent areas get darker each time I draw the image.  For
example: My surface I am rendering to may be 255,0,0 (red). Each time
I draw the image over the surface the visible red areas get darker.
These areas will only get as dark as (128,0,0).

Another example: My underlying surface is white, (255,255,255).  After
drawing the image a few hundred times the surface becomes (128, 128,
128), but not darker.  Finally, an underlying surface of (32, 64, 192)
becomes (32, 64, 128) after darkening. So, the error is that it
darkens any channel that is greater than 128  (0.5).

I am creating my image surface with
cairo_image_surface_create_from_png().  I am 100% sure that the
transparent portions of my image are completely transparent. That is,
they are 0% alpha - so there isn't any residual color being drawn.

I also tried this method to drawing clipped images. It behaves the
same as the above method:

    cairo_set_source_surface(m_context, img, x-cx, y-cy);
    cairo_rectangle(m_context, x, y, cw, ch);
    cairo_fill(m_context);

Any ideas? I have been stumped on this one for a few days.

Thanks,
Paul


More information about the cairo mailing list