[cairo]how to draw bitmap with cairo

Carl Worth cworth at cworth.org
Fri Sep 22 09:10:52 PDT 2006


On Fri, 22 Sep 2006 16:17:01 +0800, "stephen_liwf" wrote:
> Is this the correct method to show bitmap? Or there is better way to
> do it(manipulate pData directly...)?

The cairo_set_source_surface;cairo_paint idiom is the correct way to
display an image that has color information in it.

But that's not the expected way to use an A1 surface which consists
only of transparency information, and no color at all. For an A1
surface, it would be much more conventional to set an independent
source into cairo for the color and then use cairo_mask_surface to
paint that source color _through_ the A1 surface as a mask. That is,
something like:

	cairo_set_source_rgb (cr, red, green, blue); /* Desired color */
	cairo_mask_surface (cr, a1_surface, x, y);

The other concern you mentioned was speed. What is the surface type of
your destination surface (image?, xlib?, something else?). It may make
sense for you to prefer to use surfaces of the same type,
(cairo_surface_create_similar is useful for this), and to copy from an
image surface to the similar surface as early as possible.

Beyond that, the performance characteristics of the various surface
backends all vary widely. The next step in diagnosing speed problems
would be to know what the destination surface type is and to start
profiling representative code samples.

If you'd like to help us improve the speed for desired operations, one
of the best things you could do is to checkout the latest cairo source
code through git, and write a performance test case for cairo/perf
that exercises the code paths of interest for you, (see
cairo/perf/README for some explanation of how to do that).

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060922/0ef05b73/attachment.pgp


More information about the cairo mailing list