Blender Git Commit Log

Git Commits -> Revision 37b9c9f

Revision 37b9c9f by Benoit Bolsee (master)
February 21, 2010, 22:20 (GMT)
VideoTexture: improvements to image data access API.

- Use BGL buffer instead of string for image data.
- Add buffer interface to image source.
- Allow customization of pixel format.
- Add valid property to check if the image data is available.

The image property of all Image source objects will now
return a BGL 'buffer' object. Previously it was returning
a string, which was not working at all with Python 3.1.
The BGL buffer type allows sequence access to bytes and
is directly usable in BGL OpenGL wrapper functions.
The buffer is formated as a 1 dimensional array of bytes
with 4 bytes per pixel in RGBA order.

BGL buffers will also be accepted in the ImageBuff load()
and plot() functions.

It is possible to customize the pixel format by using
the VideoTexture.imageToArray(image, mode) function:
the first argument is a Image source object, the second
optional argument is a format string using the R, G, B,
A, 0 and 1 characters. For example "BGR" means that each
pixel will be 3 bytes, corresponding to the Blue, Green
and Red channel in that order. Use 0 for a fixed hex 00
value, 1 for hex FF. The default mode is "RGBA".

All Image source objects now support the buffer interface
which allows to create memoryview objects for direct access
to the image internal buffer without memory copy. The buffer
format is one dimensional array of bytes with 4 bytes per
pixel in RGBA order. The buffer is writable, which allows
custom modifications of the image data.

v = memoryview(source)

A bug in the Python 3.1 buffer API will cause a crash if
the memoryview object cannot be created. Therefore, you
must always check first that an image data is available
before creating a memoryview object. Use the new valid
attribute for that:

if source.valid:
v = memoryview(source)
...

Note: the BGL buffer object itself does not yet support
the buffer interface.

Note: the valid attribute makes sense only if you use
image source in conjunction with texture object like this:

# refresh texture but keep image data in memory
texture.refresh(False)
if texture.source.valid:
v = memoryview(texture.source)
# process image
...
# invalidate image for next texture refresh
texture.source.refresh()

Limitation: While memoryview objects exist, the image cannot be
resized. Resizing occurs with ImageViewport objects when the
viewport size is changed or with ImageFFmpeg when a new image
is reloaded for example. Any attempt to resize will cause a
runtime error. Delete the memoryview objects is you want to
resize an image source object.

Commit Details:

Full Hash: 37b9c9fe4dc6a4adea419ce6b20b28dd60e24794
SVN Revision: 27066
Parent Commit: 115fc34
Lines Changed: +366, -103

18 Modified Paths:

/projectfiles_vc9/gameengine/videotexture/TEX_Video.vcproj (+1, -1) (Diff)
/source/blender/python/generic/bgl.c (+37, -28) (Diff)
/source/blender/python/generic/bgl.h (+23, -14) (Diff)
/source/gameengine/VideoTexture/blendVideoTex.cpp (+4, -12) (Diff)
/source/gameengine/VideoTexture/CMakeLists.txt (+1, -0) (Diff)
/source/gameengine/VideoTexture/Exception.cpp (+2, -0) (Diff)
/source/gameengine/VideoTexture/Exception.h (+2, -0) (Diff)
/source/gameengine/VideoTexture/ImageBase.cpp (+166, -4) (Diff)
/source/gameengine/VideoTexture/ImageBase.h (+11, -4) (Diff)
/source/gameengine/VideoTexture/ImageBuff.cpp (+83, -19) (Diff)
/source/gameengine/VideoTexture/ImageMix.cpp (+2, -1) (Diff)
/source/gameengine/VideoTexture/ImageRender.cpp (+4, -2) (Diff)
/source/gameengine/VideoTexture/ImageViewport.cpp (+22, -4) (Diff)
/source/gameengine/VideoTexture/Makefile (+1, -0) (Diff)
/source/gameengine/VideoTexture/SConscript (+1, -1) (Diff)
/source/gameengine/VideoTexture/Texture.cpp (+1, -1) (Diff)
/source/gameengine/VideoTexture/VideoFFmpeg.cpp (+5, -9) (Diff)
/source/gameengine/VideoTexture/VideoFFmpeg.h (+0, -3) (Diff)
By: Miika HämäläinenLast update: Nov-07-2014 14:18MiikaHweb | 2003-2021