[Bf-committers] bpy.Image memoryview problems

Campbell Barton ideasman42 at gmail.com
Mon May 3 04:27:19 CEST 2010


On Mon, May 3, 2010 at 1:08 AM, Dan Eicher <dan at trollwerks.org> wrote:
> On Sun, May 2, 2010 at 1:32 PM, Campbell Barton <ideasman42 at gmail.com>wrote:
>
>>
>> Hi, I didnt realize this was possible but you should be able to add
>> image access without any C changes using the as_pointer() function.
>> pt = bpy.data.images["Image"].as_pointer()
>>
>> >From here you should be able to use pure python with ctypes to access
>> the ibuf's rect.
>> this is one of the reasons I added as_pointer() but I didnt test it with
>> images.
>>
>> --
>> - Campbell
>>
>
> Seem to recall you saying you wanted a py_buffer method to replace
> Image.getpixel()/setpixel() which is what this patch attempts to do but I
> suppose one could use ctypes and a raw pointer to do the same thing...not
> very pythonic though.

yep, buffer access is good to have, but making it an official part of
the api like this is risky
- An Image has float and int buffers, so we cant assume one buffer per image
- An image has imbuf's for different frames of an image sequence.
- This code adds image specific buffer access in bpy_rna.c, which I
prefer keep generic where possible.
- adds members, increasing the size of every object/mesh/vertex
instance (not just images)
- brecht's recent work on image tiles means this could be tricky to
continue supporting in some cases??

So while ctypes + pointer is a bit messy, it means we can have some
code in bpy_types.py for instance which exposes imbuf's in a way which
is very easy to change. eg.
 buf = image.buffer_find(frame=10, type=float)

-- 
- Campbell


More information about the Bf-committers mailing list