[Bf-committers] Revised Patches

Austin Benesh bfdeveloper at gmail.com
Wed Feb 23 02:13:06 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 00:41:42 -0000
@@ -48,6 +48,7 @@
 
 #include "Image.h"
 
+
 /*****************************************************************************/
 /* Python BPy_Image defaults:																								 */
 /*****************************************************************************/
@@ -211,10 +212,60 @@
 						"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
+PyObject *return_Max_xy(BPy_Image *self)
+{
+Image* image=self->image;
+PyObject* attr;
+
+	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" );
+
+	attr=Py_BuildValue("[i,i]",image->ibuf->x,image->ibuf->y);
+
+}	// by Austin
 /*****************************************************************************/
 /* Function:		Image_Init	 */
 /*****************************************************************************/
@@ -252,12 +303,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 +480,7 @@
 
 static PyObject *Image_getDepth( BPy_Image * self )
 {
+	int* p;
 	PyObject *attr;
 	Image *image = self->image;
 
@@ -437,6 +493,8 @@
 
 	attr = Py_BuildValue( "h", image->ibuf->depth );
 
+	p=&image->ibuf->depth;
+	printf("%*p");
 	if( attr )
 		return attr;
 
@@ -493,6 +551,7 @@
 static PyObject *Image_glFree( BPy_Image * self )
 {
 	Image *img = self->image;
+	
 
 	free_realtime_image( img );
 	return EXPP_incr_ret( Py_None );

-------------- next part --------------
Index: Image.py
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Image.py,v
retrieving revision 1.7
diff -u -w -b -r1.7 Image.py
--- Image.py	9 Feb 2005 05:19:24 -0000	1.7
+++ Image.py	22 Feb 2005 02:28:50 -0000
@@ -68,6 +68,7 @@
   @cvar yrep: Texture tiling: the number of repetitions in the y (vertical)
      axis.
   @cvar bindcode: Texture's bind code (readonly).
+  @cvar getPixelColor: The color [r,g,b,a] of a specified pixel (x,y).
   """
 
   def getName():
@@ -176,4 +177,12 @@
     Texture tiling: set the number of y repetitions for this Image.
     @type yrep: int
     @param yrep: The new value in [1, 16].
+    """
+  def getPixelColor(x,y)
+    """
+    Pixel Color: retrieves the color of a pixel.
+    @type x: int, y: int
+    @param x: The coordinate of the pixel along the x-axis.
+    @param y: The coordinate of the pixel along the y-axis.
+    @returns: list 4 floats (min 0 - max 1) [r,g,b,a]
     """



More information about the Bf-committers mailing list