cairo provides cairo_image_surface_create_for_data() which is useful for reading pixel data into a cairo surface. There does not seem to be a corresponding function for getting the pixel data out of an existing cairo surface. I think a new function char* data = cairo_image_surface_get_data() would be useful to enable reading pixel data into and out of cairo. PS I previously mailed the list at http://lists.freedesktop.org/archives/cairo/2005-September/005364.html and am opening the bug report so the problem is logged.
I faced the same problem and used the following code to paint the existing image surface into newly created image_data_for_pixel. But the behaviour of this is not defined since we dont know the alpha value when we create a image surface. cairo_set_source_surface (m_pcrData, m_paSurfaceImage, 0, 0); cairo_paint (m_pcrData); Tell me If I am wrong, or u have some new technique. Regards Kareem kareemullah.m@in.bosch.com
It does not solve the problem. How can you import pixel-data into cairo from an external source, and export pixel-data from cairo to an external application or library? With png you can do: cairo_image_surface_create_from_png() cairo_surface_write_to_png() How can you do the equivalent using pixel-data instead of png? What is required is something like: "cairo_image_surface_create_from_pixel_data()" "cairo_surface_write_to_pixel_data()" The first function is implemented by cairo_image_surface_create_for_data(). The second function is not implemented. You don't actually need to write the pixel data, you just need to know where it is so you can read it. We just need to be able to read image_surface->data which could be provided by a function unsigned char *data = cairo_image_surface_get_data() libpixman provides the equivalent function pixman_image_get_data() why can't cairo_image_surface do the same?
[Copying the mailing list simultaneously] We clearly need this. And I'd like to shove something in before we release cairo 1.2.0 (it turns out some improvements to the test suite would really like to be able to do this after cairo_image_surface_create_from_png). There is something missing though from the proposed interface. In order to really be able to use the image data, one will need the following information in addition to a pointer to the data: format, width, height, stride Two of these are available already in: cairo_public int cairo_image_surface_get_width (cairo_surface_t *surface); and: cairo_public int cairo_image_surface_get_height (cairo_surface_t *surface); Do we want to add the remaining three functions in a piece-wise fashion: cairo_public cairo_format_t cairo_image_surface_get_format (cairo_surface_t *surface); cairo_public unsigned char * cairo_image_surface_get_data (cairo_surface_t *surface); cairo_public int cairo_image_surface_get_stride (cairo_surface_t *surface); 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. Get your votes in quick if you care.
Fixed for a while.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.