Page Menu
Home
Search
Configure Global Search
Log In
Files
F1816
getpixels.diff
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Austin Benesh (abtrumpet)
Nov 13 2013, 1:00 PM
Size
3 KB
Subscribers
None
getpixels.diff
View Options
Index: Image.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Image.c,v
retrieving revision 1.27
diff -u -w -b -r1.27 Image.c
--- Image.c 19 Mar 2005 21:08:11 -0000 1.27
+++ Image.c 29 Apr 2005 22:58:40 -0000
@@ -211,6 +211,61 @@
return ( PyObject * ) img;
}
+static PyObject *Image_getPixelColors(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
+
+static PyObject *Image_getMax_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);
+ if (attr) return attr;
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError, "could not determine max x or y");
+
+}; // by Austin
+
/*****************************************************************************/
/* Function: Image_Init */
/*****************************************************************************/
@@ -248,12 +303,18 @@
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_getPixelColors(BPy_Image * self, PyObject * args); /* by Austin */
+static PyObject *Image_getMax_xy(BPy_Image * self); /* by Austin */
/*****************************************************************************/
/* Python BPy_Image methods table: */
/*****************************************************************************/
static PyMethodDef BPy_Image_methods[] = {
/* name, method, flags, doc */
+ {"getPixelColors", ( PyCFunction ) Image_getPixelColors, METH_VARARGS,
+ "(float, float) - Get pixel colors of specified pixel"},
+ {"getMaxXY", ( PyCFunction ) Image_getPixelColors, METH_VARARGS,
+ "() - Get maximum x & y coordinates of current image"},
{"getName", ( PyCFunction ) Image_getName, METH_NOARGS,
"() - Return Image object name"},
{"getFilename", ( PyCFunction ) Image_getFilename, METH_NOARGS,
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d4/92/e98a0c5b09f4317ec9f3bb49503b
Event Timeline
Log In to Comment