diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2010-02-27 01:14:31 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2010-02-27 01:14:31 +0300 |
commit | 71f7e50451090a2a17bae3c1b47057c87d78a84a (patch) | |
tree | 1b1094e883226c8a1c7e00dcd2efbfe207357e16 /source/gameengine/VideoTexture | |
parent | a7b73a49a45739aba26601ba9f8261d467e7bd5e (diff) |
VideoTexture: optional arguments to ImageBuff constructor.
ImageBuff([width,height[,color[,scale]]])
width, height: size of buffer in pixel.
default: buffer not allocated.
color: initial value of RGB channels. Alpha channel is 255.
Possible values: 0(black=default) -> 255 (white)
scale: True or False to enable or disable fast scaling
default: False
This constructors eliminates the need to use the load function
when you just want to initialize the image buffer to black or white.
Diffstat (limited to 'source/gameengine/VideoTexture')
-rw-r--r-- | source/gameengine/VideoTexture/ImageBuff.cpp | 65 | ||||
-rw-r--r-- | source/gameengine/VideoTexture/ImageBuff.h | 2 |
2 files changed, 66 insertions, 1 deletions
diff --git a/source/gameengine/VideoTexture/ImageBuff.cpp b/source/gameengine/VideoTexture/ImageBuff.cpp index e1002bb2370..3e9e7af6c07 100644 --- a/source/gameengine/VideoTexture/ImageBuff.cpp +++ b/source/gameengine/VideoTexture/ImageBuff.cpp @@ -43,6 +43,41 @@ FilterRGB24 defFilter; // forward declaration; extern PyTypeObject ImageBuffType; +static int ImageBuff_init (PyObject * pySelf, PyObject * args, PyObject * kwds) +{ + short width = -1; + short height = -1; + unsigned char color = 0; + PyObject *py_scale = Py_False; + ImageBuff *image; + + PyImage * self = reinterpret_cast<PyImage*>(pySelf); + // create source object + if (self->m_image != NULL) + delete self->m_image; + image = new ImageBuff(); + self->m_image = image; + + if (PyArg_ParseTuple(args, "hh|bO!:ImageBuff", &width, &height, &color, &PyBool_Type, &py_scale)) + { + // initialize image buffer + image->setScale(py_scale == Py_True); + image->clear(width, height, color); + } + else + { + // check if at least one argument was passed + if (width != -1 || height != -1) + // yes and they didn't match => it's an error + return -1; + // empty argument list is okay + PyErr_Clear(); + } + // initialization succeded + return 0; + +} + ImageBuff::~ImageBuff (void) { if (m_imbuf) @@ -74,6 +109,34 @@ void ImageBuff::load (unsigned char * img, short width, short height) m_avail = true; } +void ImageBuff::clear (short width, short height, unsigned char color) +{ + unsigned char *p; + int size; + + // loading a new buffer implies to reset the imbuf if any, because the size may change + if (m_imbuf) + { + IMB_freeImBuf(m_imbuf); + m_imbuf = NULL; + } + // initialize image buffer + init(width, height); + // the width/height may be different due to scaling + size = (m_size[0] * m_size[1]); + // initialize memory with color for all channels + memset(m_image, color, size*4); + // and change the alpha channel + p = &((unsigned char*)m_image)[3]; + for (size; size>0; size--) + { + *p = 0xFF; + p += 4; + } + // image is available + m_avail = true; +} + // img must point to a array of RGBA data of size width*height void ImageBuff::plot (unsigned char * img, short width, short height, short x, short y, short mode) { @@ -348,7 +411,7 @@ PyTypeObject ImageBuffType = 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)Image_init<ImageBuff>, /* tp_init */ + (initproc)ImageBuff_init, /* tp_init */ 0, /* tp_alloc */ Image_allocNew, /* tp_new */ }; diff --git a/source/gameengine/VideoTexture/ImageBuff.h b/source/gameengine/VideoTexture/ImageBuff.h index e18edc44288..271647361e8 100644 --- a/source/gameengine/VideoTexture/ImageBuff.h +++ b/source/gameengine/VideoTexture/ImageBuff.h @@ -44,6 +44,8 @@ public: /// load image from buffer void load (unsigned char * img, short width, short height); + /// clear image with color set on RGB channels and 0xFF on alpha channel + void clear (short width, short height, unsigned char color); /// plot image from extern RGBA buffer to image at position x,y using one of IMB_BlendMode void plot (unsigned char * img, short width, short height, short x, short y, short mode); |