[cairo] Get pixeldata from image

Steve Chaplin stevech1097 at yahoo.com.au
Mon Nov 20 19:00:59 PST 2006

On Mon, 2006-11-20 at 07:57 -0800, Carl Worth wrote:
> On Mon, 20 Nov 2006 20:08:59 +0800, Steve Chaplin wrote:
> > cairo.ImageSurface.get_data_as_rgba() takes a cairo.FORMAT_ARGB32
> > surface and returns the data as rgba. It does not return the original
> > data because the original data is not in rgba format.
> Yuck!
> Can we eliminate that function please?
OK, its gone.
[ Copying to James since he was the original user for the function, and
may be able to explain things further; and to Owen since I remember he
objected when the function was originally added. ]

> > The current release of pycairo does not have a
> > cairo.ImageSurface.get_data() function. In CVS there is a
> > cairo.ImageSurface.get_data() which I added today. So if you want to
> > install using CVS you can test the new function.
> So now there's a nice, non-copying get_data and a copying
> get_data_as_rgb. Those names are much too similar for one to copy and
> one to not. At the very least, the copying one should have a different
> name.
> But even then, the bindings shouldn't have functions that cairo itself
> does not. If there's functionality missing, we should get it into
> cairo itself so that all bindings can have it.

There were historical reasons for creating the
ImageSurface.get_data_as_rgba(). The problem was - how can I read
pycairo image data into the Python Image Library (PIL)?
There were two problems/bugs/lack-of-features which prevented this:
1) cairo (at the time) did not provide a public get_data() function.
2) PIL could not read ARGB32.
So the problem was, IMHO, a cairo bug and a PIL bug.
The new pycairo function did two things at once (get data and convert
data) and worked round the two bugs. But confused things and created its
own problems as you know!

Now that cairo and pycairo provide a get_data() function, the cairo side
of the image data problem has been solved - cairo is now able to export
its image data to any other library/module/program. I don't know what
the current status of PIL is.

In general, pycairo users may request new functionality be added so that
pycairo can interact with other Python libraries/modules. Some requests
(like a get_data function) may be generic and can be pushed up into
cairo. But other functionality may be Python-specific and not suitable
for inclusion in cairo.

There is one other problem function I can think of.
    surface = cairo.ImageSurface.create_for_array (array)
where 'array' is a Numerical Python array

I don't think adding an array interface to cairo would be that useful.
But for Python users 'create_for_array' may be useful.

There is a pygtk precedent - they have gtk.gdk.pixbuf_new_from_array()
which has managed to survive without (or in spite of) Owen asking for
its removal.


Send instant messages to your online friends http://au.messenger.yahoo.com 

More information about the cairo mailing list