[cairo] pycairo and PIL
James Evans
milamber at clark-evans.com
Thu Sep 22 06:49:29 PDT 2005
Actually, that wasn't supposed to be in the patch. If you look, the #if 0
(line 431) is still in effect. This is a relic of my first attempt. Both
hunk #4 and #5 shouldn't have been included.
I agree that if you want to enable this function, a PyBufferObject should
be passed in rather than a char *,int pair.
I backed off using image_surface_create_for_data and modified
image_surface_new so that I didn't have 2 types of surfaces, one I could
get the data from (created with image_surface_create_for_data) and one I
couldn't (created with image_surface_new). I didn't have need to pass in
an existing buffer to use as the surface, although come to think of it I
have a personal project that could use that funcationalty....
Are you thinking that the caller of image_surface_create_for_data should
use it like this:
import cairo
import Image
python_image = Image.open("background.png")
(Width,Height) = python_image.size
image_buffer = python_image.tostring()
cairo_image = cairo.ImageSurface.create_for_data(image_buffer,
cairo.FORMAT_ARGB32, Width, Height)
It does seem like that would be useful. I don't think I'll have time to
look at this until this weekend. Would you like me to take a shot at it?
Thanks,
james
> I've looked through one half of the patch - the
> cairo.ImageSurface.create_for_data() part.
>
> The problem is that we need to make sure the 'data' passed to
> cairo_image_surface_create_for_data() is not deallocated before we have
> finished using the cairo surface.
> I do not think that calling PyBuffer_FromReadWriteMemory() and
> referencing 'buffer' ensures the underlying 'data' is not deallocated.
>
> I think the original error was to use
> if (!PyArg_ParseTuple(args, "w#iii|i:Surface.create_for_data",
> which gives us the internal buffer data, but not the python object.
> A better method is to read a Python object, call
> PyObject_AsWriteBuffer, and reference the python object so the internal
> data is not deallocated.
>
> I've updated cvs use this new method and updated the test script, which
> seems to be working OK.
>
> Steve
>
> Send instant messages to your online friends http://au.messenger.yahoo.com
>
More information about the cairo
mailing list