[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27158] trunk/blender/source/gameengine/ VideoTexture: VideoTexture: optional arguments to ImageBuff constructor.

Benoit Bolsee benoit.bolsee at online.be
Fri Feb 26 23:14:31 CET 2010


Revision: 27158
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27158
Author:   ben2610
Date:     2010-02-26 23:14:31 +0100 (Fri, 26 Feb 2010)

Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/gameengine/VideoTexture/ImageBuff.cpp
    trunk/blender/source/gameengine/VideoTexture/ImageBuff.h

Modified: trunk/blender/source/gameengine/VideoTexture/ImageBuff.cpp
===================================================================
--- trunk/blender/source/gameengine/VideoTexture/ImageBuff.cpp	2010-02-26 21:08:06 UTC (rev 27157)
+++ trunk/blender/source/gameengine/VideoTexture/ImageBuff.cpp	2010-02-26 22:14:31 UTC (rev 27158)
@@ -43,6 +43,41 @@
 // 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 @@
 	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 @@
 	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 */
 };

Modified: trunk/blender/source/gameengine/VideoTexture/ImageBuff.h
===================================================================
--- trunk/blender/source/gameengine/VideoTexture/ImageBuff.h	2010-02-26 21:08:06 UTC (rev 27157)
+++ trunk/blender/source/gameengine/VideoTexture/ImageBuff.h	2010-02-26 22:14:31 UTC (rev 27158)
@@ -44,6 +44,8 @@
 
 	/// 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);





More information about the Bf-blender-cvs mailing list