Bug 4687 - Getting pixel data
Summary: Getting pixel data
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: image backend (show other bugs)
Version: 1.0.2
Hardware: x86 (IA32) Linux (All)
: high enhancement
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-04 19:17 UTC by Steve Chaplin
Modified: 2006-06-13 19:45 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Steve Chaplin 2005-10-04 19:17:54 UTC
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.
Comment 1 kareem 2005-10-13 22:24:21 UTC
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
Comment 2 Steve Chaplin 2005-10-14 00:25:35 UTC
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?


Comment 3 Carl Worth 2006-01-18 10:08:52 UTC
[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.
Comment 4 Behdad Esfahbod 2006-06-13 19:45:36 UTC
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.