blender/source/gameengine/VideoTexture/SConscript
Benoit Bolsee 37b9c9fe4d 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.
2010-02-21 22:20:00 +00:00

32 lines
1.2 KiB
Python

#!/usr/bin/python
import sys
Import ('env')
sources = env.Glob('*.cpp')
incs = '. #source/gameengine/Ketsji #source/gameengine/Expressions'
incs += ' #source/gameengine/GameLogic #source/gameengine/SceneGraph #source/gameengine/Rasterizer'
incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer'
incs += ' #source/gameengine/BlenderRoutines'
incs += ' #source/blender/editors/include #source/blender/blenlib #source/blender/blenkernel'
incs += ' #source/blender/makesdna #source/blender/imbuf #source/blender/python #source/blender/python/generic'
incs += ' #source/blender/gpu #source/kernel/gen_system #intern/string #intern/moto/include'
incs += ' #intern/guardedalloc #extern/glew/include'
defs = []
if env['OURPLATFORM'] in ('win32-vc', 'win64-vc','win32-mingw'):
if env['BF_DEBUG']:
defs.append('_DEBUG')
if env['WITH_BF_PYTHON']:
incs += ' ' + env['BF_PYTHON_INC']
else:
defs.append('DISABLE_PYTHON')
if env['WITH_BF_FFMPEG']:
defs.append('WITH_FFMPEG')
incs += ' ' + env['BF_FFMPEG_INC'] + ' ' + env['BF_PTHREADS_INC']
env.BlenderLib ( 'bf_videotex', sources, Split(incs), defs, libtype=['core','player'], priority=[340,205], cxx_compileflags=env['BGE_CXXFLAGS'])