[Bf-committers] bpy.Image memoryview problems

Campbell Barton ideasman42 at gmail.com
Sun May 2 22:32:43 CEST 2010


On Sun, May 2, 2010 at 9:39 PM, Dan Eicher <dan at trollwerks.org> wrote:
> Been working on a py_buffer method for pixel access (
> http://www.pasteall.org/12868/diff) and can't seem to figure out where it
> goes wrong.
>
> It appears to work...
>
>>>> import bpy
>>>> img = memoryview(bpy.data.images['Lenna.png'])
>>>> img.format
> 'B'
>
>>>> img.itemsize
> 1
>
>>>> img.shape
> (512, 512, 3)
>
>>>> img.ndim
> 3
>
>>>> img.strides
> (1536, 3, 1)
>
> but when trying to access pixels...
>
>>>> img[0][0][0]
> Traceback (most recent call last):
>  File "<console>", line 1, in <module>
> IndexError: invalid indexing of 0-dim memory
>
> This whole thing is driving me batty since there's very little info on the
> py_buffer method on the web.

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


More information about the Bf-committers mailing list