[Bf-committers] bpy.Image memoryview problems

Campbell Barton ideasman42 at gmail.com
Sat May 8 08:53:03 CEST 2010


On Wed, May 5, 2010 at 9:35 AM, Theo de Ridder <theo.de.ridder at planet.nl> wrote:
>
> On 5 mei 2010, at 07:53, Campbell wrote:
>
>> indeed it seems there is no way to get a PyCapsule into ctypes.
>> Since this was the purpose, as_pointer() could return an 'int' which
>> ctypes can convert into a pointer.
>>
>> as for security, there are probably easier ways to exploit blender
>> then getting a pointer to an image and somehow replacing parts of it
>> with machine code???.
>>
>> struct.as_pointer() could be rewritten in ctypes alone by getting the
>> PyObject pointer the the pointer to the ID from that (which always has
>> the same offset), in fact even without any api access, a developer
>> with ctypes can write into any part of blenders memory they like.
>
> agreed, in fact I don't like the as_pointer and ctypes approach at all, but
> do prefer a clean py_buffer interface to certain types of contiguous
> memory data like images and keybuffers; for security it is then good
> enough to have write access to such buffers without being able to change their
> sizes; it seems there is some reluctance towards py_buffers, but
> my reason for wanting them is that I found a few years
> ago enormous benefits in performance and codesize by wrapping
> such buffers in numpy (and now I am also looking at openCV
> for realtime camera input tracking); my personal opinion is still that
> the relevance of numpy is underestimated in the Blender community
> for highlevel and fast transformations of huge n-dimensional matrices of colors
> and vertices without looping (with getters and setters) at Python level;
> but I am not in a hurry with this, numpy2.0 (for python3.x) will not be there
> before the 2e half of this year.
>
> ~Theo

At the moment I'm looking at this from a API maintenance perspective
where I really want to avoid large chunks of C/API code creeping into
blender for each array we wrap.

Basically images are just a big array of floats/chars (lets ignore
Brecht added image tilling+mipmaps for a second)
so I gather ctypes is capable of getting the offset from a pointer and
exposing an array?

If not, we'll need to use some other solution, at the moment I don't
really have time to investigate the best way, so Ill defer this for a
few months (after Durian).

Re: numpy
Once we get a python 3.x port we can look at bundling it with
Blender's python by default.


More information about the Bf-committers mailing list