[cairo] Observations from a newb

Carl Worth cworth at cworth.org
Thu Nov 8 10:55:53 PST 2007


On Thu, 8 Nov 2007 18:01:37 +0100 (CET), Dirk Schönberger wrote:
> Oh, then I seem to miss something. I am not quite up to date with the
> actual code, but I consulted the API documentation at cairographics.org.
> While I found a way to render _to_ ciro image surfaces, I have found no
> way to render a image surface or a RGBA buffer using cairo functionality
> I.e. something like
> 
> cairo_t *cr;
> cairo_matrix_t *ctx;
> cairo_image_t *img;
> cairo_render_image (cr, img, ctx);

It can be slightly tricky to find the "cairo way" of doing this
operation because cairo doesn't consider "drawing an image" to be a
distinct operation. Instead, *any* of the 5 drawing operations,
(paint, mask, stroke, fill, and show_text/glyphs), can just happen to
be using a source pattern that is based on an image.

So, the answer to your question above on how to render a transformed
surface might look like this:

	void
	draw_transformed_surface (cairo_t *cr,
				  cairo_matrix_t *matrix,
				  cairo_surface_t *surface)
	{
	    cairo_save (cr);

	    cairo_transform (cr, matrix);
	    cairo_set_source_surface (cr, surface, 0.0, 0.0);
	    cairo_paint (cr);

	    cairo_restore (cr);
	}

After setting up a source pattern based on the given surface, we use a
"paint" operation to paint the entire surface.

And notice that "draw an image" is not a primitive at all. You can use
the same set_source_surface to then fill or stroke an arbitrary path
with the contents of an image, or you can fill text with image
contents. (And where I'm saying "image" here, you can use any type of
surface or any other type of pattern as well---such as gradients).

We do recognize that people with familiarity of other systems expect
to find a "draw image" operation in cairo. That's why we publish the
answer to a frequently-asked question that addresses this issue:

	http://cairographics.org/FAQ/#paint_from_a_surface

If you have suggestions for other places where cairo's documentation
could be improved, they would be most appreciated.

> Creating the cairo_image_t (or more generically a device independent
> image, aka a RGBA buffer) would be left to other parties.

Yes, that's precisely the point I was making earlier.

Do have fun with cairo!

-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.cairographics.org/archives/cairo/attachments/20071108/b231d846/attachment.pgp 


More information about the cairo mailing list