Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2010-02-22 01:20:00 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2010-02-22 01:20:00 +0300
commit37b9c9fe4dc6a4adea419ce6b20b28dd60e24794 (patch)
treeec184b994766f3e5b3c7c757d37898a5cda9432b /source/gameengine/VideoTexture/VideoFFmpeg.cpp
parent115fc34dd382c76cf74c062db5741bcbb52fe988 (diff)
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.
Diffstat (limited to 'source/gameengine/VideoTexture/VideoFFmpeg.cpp')
-rw-r--r--source/gameengine/VideoTexture/VideoFFmpeg.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.cpp b/source/gameengine/VideoTexture/VideoFFmpeg.cpp
index 4c87b1764d6..c33cb9a671d 100644
--- a/source/gameengine/VideoTexture/VideoFFmpeg.cpp
+++ b/source/gameengine/VideoTexture/VideoFFmpeg.cpp
@@ -723,14 +723,8 @@ void VideoFFmpeg::setFrameRate (float rate)
// image calculation
-void VideoFFmpeg::calcImage (unsigned int texId, double ts)
-{
- loadFrame(ts);
-}
-
-
// load frame from video
-void VideoFFmpeg::loadFrame (double ts)
+void VideoFFmpeg::calcImage (unsigned int texId, double ts)
{
if (m_status == SourcePlaying)
{
@@ -1162,6 +1156,7 @@ static PyGetSetDef videoGetSets[] =
{(char*)"repeat", (getter)Video_getRepeat, (setter)Video_setRepeat, (char*)"repeat count, -1 for infinite repeat", NULL},
{(char*)"framerate", (getter)Video_getFrameRate, (setter)Video_setFrameRate, (char*)"frame rate", NULL},
// attributes from ImageBase class
+ {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
{(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
{(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
{(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbour)", NULL},
@@ -1193,7 +1188,7 @@ PyTypeObject VideoFFmpegType =
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ &imageBufferProcs, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"FFmpeg video source", /* tp_doc */
0, /* tp_traverse */
@@ -1282,6 +1277,7 @@ static PyGetSetDef imageGetSets[] =
{ // methods from VideoBase class
{(char*)"status", (getter)Video_getStatus, NULL, (char*)"video status", NULL},
// attributes from ImageBase class
+ {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
{(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
{(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
{(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbour)", NULL},
@@ -1311,7 +1307,7 @@ PyTypeObject ImageFFmpegType =
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ &imageBufferProcs, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"FFmpeg image source", /* tp_doc */
0, /* tp_traverse */