[Bf-committers] Final Revision
Austin Benesh
bfdeveloper at gmail.com
Wed Feb 23 02:24:31 CET 2005
Skipped content of type multipart/alternative-------------- next part --------------
Index: Image.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Image.c,v
retrieving revision 1.26
diff -u -w -b -r1.26 Image.c
--- Image.c 9 Feb 2005 15:53:34 -0000 1.26
+++ Image.c 23 Feb 2005 01:19:35 -0000
@@ -48,6 +48,7 @@
#include "Image.h"
+
/*****************************************************************************/
/* Python BPy_Image defaults: */
/*****************************************************************************/
@@ -211,10 +212,45 @@
"couldn't load image" ) );
img->image = img_ptr;
-
return ( PyObject * ) img;
}
+/* FUNCTION GET PIXELS NEEDED DESPERATELY*/
+static PyObject *Image_getPixelColor(BPy_Image * self, PyObject *args)
+{
+
+ PyObject *attr;
+ Image *image=self->image;
+ char* pixel;
+ int ptr;
+ int x=0;
+ int y=0;
+
+ if( !PyArg_ParseTuple( args, "ii", &x, &y ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected 2 integers" );
+
+ if( !image->ibuf||!image->ibuf->rect ) /* if no image data available */
+ load_image( image, IB_rect, "", 0 ); /* loading it */
+
+ if( !image->ibuf||!image->ibuf->rect ) /* didn't work */
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't load image data in Blender" );
+ if(x>image->ibuf->x||y>image->ibuf->y||image->ibuf->xorig>x||image->ibuf->yorig>y)
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError, "x or y is out of range");
+
+
+ ptr=(x + y* image->ibuf->x)*4;
+
+ pixel=(char*)image->ibuf->rect;
+ attr = Py_BuildValue( "[f,f,f,f]", ((float)pixel[ptr])/255,((float)pixel[ptr+1])/255,((float)pixel[ptr+2])/255,((float)pixel[ptr+3]/255) );
+
+ if( attr )
+ return attr;
+
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get pixel colors" );
+};// by Austin
/*****************************************************************************/
/* Function: Image_Init */
/*****************************************************************************/
@@ -252,12 +288,16 @@
static PyObject *Image_reload( BPy_Image * self ); /* by Campbell */
static PyObject *Image_glLoad( BPy_Image * self );
static PyObject *Image_glFree( BPy_Image * self );
-
+static PyObject *Image_getPixelColor(BPy_Image * self, PyObject *args); /* by Austin Benesh */
/*****************************************************************************/
/* Python BPy_Image methods table: */
/*****************************************************************************/
static PyMethodDef BPy_Image_methods[] = {
/* name, method, flags, doc */
+ // desperately needed...
+ {"getPixelColor", ( PyCFunction ) Image_getPixelColor, METH_VARARGS,
+ "(int) X,Y"},
+ //
{"getName", ( PyCFunction ) Image_getName, METH_NOARGS,
"() - Return Image object name"},
{"getFilename", ( PyCFunction ) Image_getFilename, METH_NOARGS,
@@ -425,6 +465,7 @@
static PyObject *Image_getDepth( BPy_Image * self )
{
+ int* p;
PyObject *attr;
Image *image = self->image;
@@ -437,6 +478,8 @@
attr = Py_BuildValue( "h", image->ibuf->depth );
+ p=&image->ibuf->depth;
+ printf("%*p");
if( attr )
return attr;
@@ -493,6 +536,7 @@
static PyObject *Image_glFree( BPy_Image * self )
{
Image *img = self->image;
+
free_realtime_image( img );
return EXPP_incr_ret( Py_None );
More information about the Bf-committers
mailing list