[cairo] Get pixeldata from image

Steve Chaplin stevech1097 at yahoo.com.au
Tue Nov 21 18:30:19 PST 2006


On Mon, 2006-11-20 at 23:06 -0500, Behdad Esfahbod wrote:
> On Mon, 2006-11-20 at 22:00 -0500, Steve Chaplin wrote:
> > 
> > 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. 
> 
> Isn't it more Pythonesque to make create_for_data() understand an array?
> Or does the create_for_array() create a copy of the data while
> create_for_data doesn't? Ick.
> 

create_for_data() and create_for_array() both use the original data.

ImageSurface.create_for_data(data, format, width, height, stride)
takes 'data' which is a Python object which implements a writable buffer
interface.

ImageSurface.create_for_array(array)
does not need the format, width, height, stride arguments since it can
get them from the array. It reads the array data directly.

However, Numerical Python arrays also implement the buffer interface so
  create_for_data(array, format, width, height, stride)
will also work most of the time.

So create_for_array() looks like its just a convenience function for
create_for_data(). But it does do more error checking - it checks the
array data is unsigned bytes, and checks the array is contiguous.

Steve





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


More information about the cairo mailing list