[cairo] How to export image_surface pixel data?

Owen Taylor otaylor at redhat.com
Tue Jan 17 15:38:24 PST 2006

On Tue, 2006-01-17 at 15:20 -0800, Carl Worth wrote:

> Or would it be better to have one call to get them all (in
> an order to match cairo_image_surface_create_for_data)?
> 	cairo_public void
> 	cairo_image_surface_get_data (cairo_surface_t	 *surface,
> 				      unsigned char	**data,
> 				      cairo_format_t	 *format,
> 				      int		 *width,
> 				      int		 *height,
> 				      int		 *stride);
> The idea being that getting the data without the other information is
> either not useful or at best error-prone, and having to call five
> functions for a single operation is just painful.

Multiple return values are distinctly language binding unfriendly.
In the best case, you might be able to do

 (data,format,width,height,stride) = surface.get_data()

But even then you have to know the order. (C has the ordering problem
too, actually..)

And many languages don't allow multiple return values.

In GdkPixbuf we went with the separate accessors, and while it's a 
lot of typing in C, it works in the end.

>From the GdkPixbuf experience I'd caution thinking ahead of time about
what the above means for modifying data behind cairo's back. Are
the cairo_surface_mark_dirty() and cairo_surface_flush() sufficient?

Can you avoid copying the entire contents in:

 Create image surface
 Draw to it
 Draw to PS surface metafile

? For GdkPixbuf I've regretted not having a lock_data(), unlock_data()
instead, though that particular Rubicon may already have been crossed
with the current ability to create an image surface from user data.


More information about the cairo mailing list