forked from bartvdbraak/blender
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.
This commit is contained in:
parent
a7b73a49a4
commit
71f7e50451
@ -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 */
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user