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(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, /* 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);