Page MenuHome

pixelpatch.diff

pixelpatch.diff

Index: Image.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Image.c,v
retrieving revision 1.28
diff -u -w -b -r1.28 Image.c
--- Image.c 30 Apr 2005 19:30:35 -0000 1.28
+++ Image.c 30 Apr 2005 23:19:12 -0000
@@ -84,6 +84,7 @@
"(filename) - return image from file filename as Image Object, \
returns None if not found.\n";
+
/*****************************************************************************/
/* Python method structure definition for Blender.Image module: */
/*****************************************************************************/
@@ -210,6 +211,90 @@
return ( PyObject * ) img;
}
+static PyObject *Image_Save( BPy_Image * self )
+{
+ if(!self->image->ibuf||!self->image->ibuf->rect)
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError, "no image data available");
+
+ if(!IMB_saveiff(self->image->ibuf, self->image->name, self->image->ibuf->flags))
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError, "errors saving image");
+
+
+ Py_INCREF( Py_None );
+ return Py_None;
+};
+
+static PyObject *Image_setPixel(BPy_Image *self, PyObject *args)
+{
+ int x, y, index, r2, g2, b2, a2;
+ float r, g, b, a;
+ Image *image = self->image;
+ int pixel_size = 4;
+ char *pixel;
+
+ if( !PyArg_ParseTuple( args, "ii(ffff)", &x, &y, &r, &g, &b, &a ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected 2 integers and a list of 4 floats" );
+
+ 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 - 1 )
+ || y > ( image->ibuf->y - 1 )
+ || x < image->ibuf->xorig || y < image->ibuf->yorig )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "x or y is out of range" );
+
+ if((r>1.0||r<0.0)
+ ||(g>1.0||g<0.0)
+ ||(b>1.0||b<0.0)
+ ||(a>1.0||a<0.0))
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError, "r, g, b, or a is out of range");
+
+
+ index = (x + y * image->ibuf->x) * pixel_size;
+ pixel = (char*)image->ibuf->rect;
+
+ r2 = (int)(r*255);
+ g2 = (int)(g*255);
+ b2 = (int)(b*255);
+ a2 = (int)(a*255);
+
+ pixel[index] = r2;
+ pixel[index+1] = g2;
+ pixel[index+2] = b2;
+ pixel[index+3] = a2;
+
+ self->image->ibuf->rect = (unsigned int*)pixel;
+
+
+ Py_INCREF( Py_None );
+ return Py_None;
+}
+
+static PyObject *Image_getMinXY(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->xorig,image->ibuf->yorig);
+ if (attr) return attr;
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError, "could not determine min x or y");
+}
+
+
/**
@@ -330,7 +415,10 @@
static PyObject *Image_glLoad( BPy_Image * self );
static PyObject *Image_glFree( BPy_Image * self );
static PyObject *Image_getPixel( BPy_Image * self, PyObject * args );
+static PyObject *Image_setPixel( BPy_Image * self, PyObject * args );
static PyObject *Image_getMaxXY( BPy_Image * self );
+static PyObject *Image_getMinXY( BPy_Image * self );
+static PyObject *Image_Save( BPy_Image * self );
/*****************************************************************************/
/* Python BPy_Image methods table: */
@@ -339,8 +427,12 @@
/* name, method, flags, doc */
{"getPixel", ( PyCFunction ) Image_getPixel, METH_VARARGS,
"(float, float) - Get colors of specified pixel as [r,g,b,a]"},
- {"getMaxXY", ( PyCFunction ) Image_getMaxXY, METH_VARARGS,
+ {"setPixel", ( PyCFunction ) Image_setPixel, METH_VARARGS,
+ "(int, int, [f,f,f,f]) - Set colors of specified pixel"},
+ {"getMaxXY", ( PyCFunction ) Image_getMaxXY, METH_NOARGS,
"() - Get maximum x & y coordinates of current image as [x, y]"},
+ {"getMinXY", ( PyCFunction ) Image_getMinXY, METH_NOARGS,
+ "() - Get minimum x & y coordinates of current image as [x, y]"},
{"getName", ( PyCFunction ) Image_getName, METH_NOARGS,
"() - Return Image object name"},
{"getFilename", ( PyCFunction ) Image_getFilename, METH_NOARGS,
@@ -371,6 +463,8 @@
"(int) - Change Image object x repetition value"},
{"setYRep", ( PyCFunction ) Image_setYRep, METH_VARARGS,
"(int) - Change Image object y repetition value"},
+ {"Save", ( PyCFunction ) Image_Save, METH_NOARGS,
+ "() - Saves current image buffers to image"},
{NULL, NULL, 0, NULL}
};

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
06/47/6d8f6885bd4612ce488e53bc6db0

Event Timeline