Page MenuHome

Image.c.v1.diff

Image.c.v1.diff

Index: Image.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Image.c,v
retrieving revision 1.29
diff -u -w -b -r1.29 Image.c
--- Image.c 22 May 2005 18:43:29 -0000 1.29
+++ Image.c 16 Jun 2005 20:39:39 -0000
@@ -273,6 +273,187 @@
}
+static PyObject *Image_getPixelI( BPy_Image * self, PyObject * args )
+{
+
+ PyObject *attr;
+ Image *image = self->image;
+ char *pixel; /* image data */
+ int index; /* offset into image data */
+ int x = 0;
+ int y = 0;
+ int pixel_size = 4; /* each pixel is 4 x 8-bits packed in unsigned int */
+
+ 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( image->ibuf->type == 1 ) /* bitplane image */
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "unsupported bitplane image format" );
+
+ 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" );
+
+ /*
+ assumption: from looking at source, skipx is often not set,
+ so we calc ourselves
+ */
+
+ index = ( x + y * image->ibuf->x ) * pixel_size;
+
+ pixel = ( char * ) image->ibuf->rect;
+ attr = Py_BuildValue( "[i,i,i,i]",
+ pixel[index] ,
+ pixel[index + 1] ,
+ pixel[index + 2] ,
+ pixel[index + 3] );
+
+ if( attr ) /* normal return */
+ return attr;
+
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't get pixel colors" );
+}
+
+static PyObject *Image_setPixelF( BPy_Image * self, PyObject * args )
+{
+
+ PyObject *attr;
+ Image *image = self->image;
+ char *pixel; /* image data */
+ int index; /* offset into image data */
+ int x = 0;
+ int y = 0;
+ int a = 0;
+ int pixel_size = 4; /* each pixel is 4 x 8-bits packed in unsigned int */
+ float p[4];
+
+ if( !PyArg_ParseTuple( args, "ii(ffff)", &x, &y, &p[0], &p[1], &p[2], &p[3] ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected 2 integers and an array 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( image->ibuf->type == 1 ) /* bitplane image */
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "unsupported bitplane image format" );
+
+ 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" );
+
+ for ( a = 0; a < 4; a++ )
+ {
+ if( p[a] > 1.0
+ || p[a] < 0.0 )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "r, g, b, or a is out of range" );
+ }
+
+
+ /*
+ assumption: from looking at source, skipx is often not set,
+ so we calc ourselves
+ */
+
+ index = ( x + y * image->ibuf->x ) * pixel_size;
+
+ pixel = ( char* ) image->ibuf->rect;
+
+ pixel[ index ] = ( int ) ( p[0] * 255.0 );
+ pixel[ index+1 ] = ( int ) ( p[1] * 255.0 );
+ pixel[ index+2 ] = ( int ) ( p[2] * 255.0 );
+ pixel[ index+3 ] = ( int ) ( p[3] * 255.0 );
+
+ ( char* ) image->ibuf->rect = pixel;
+
+
+ Py_INCREF( Py_None );
+ return Py_None;
+
+}
+
+static PyObject *Image_setPixelI( BPy_Image * self, PyObject * args )
+{
+
+ PyObject *attr;
+ Image *image = self->image;
+ char *pixel; /* image data */
+ int index; /* offset into image data */
+ int x = 0;
+ int y = 0;
+ int a = 0;
+ int pixel_size = 4; /* each pixel is 4 x 8-bits packed in unsigned int */
+ int p[4];
+
+ if( !PyArg_ParseTuple( args, "ii(iiii)", &x, &y, &p[0], &p[1], &p[2], &p[3]) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected 2 integers and an list of 4 ints" );
+
+ 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( image->ibuf->type == 1 ) /* bitplane image */
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "unsupported bitplane image format" );
+
+ 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" );
+
+ for ( a = 0; a < 4; a++ )
+ {
+ if( p[a] > 255
+ || p[a] < 0 )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "r, g, b, or a is out of range" );
+ }
+
+ /*
+ assumption: from looking at source, skipx is often not set,
+ so we calc ourselves
+ */
+
+ index = ( x + y * image->ibuf->x ) * pixel_size;
+
+ pixel = ( char* ) image->ibuf->rect;
+
+ pixel[ index ] = p[0];
+ pixel[ index+1 ] = p[1];
+ pixel[ index+2 ] = p[2];
+ pixel[ index+3 ] = p[3];
+
+ ( char* ) image->ibuf->rect = pixel;
+
+
+ Py_INCREF( Py_None );
+ return Py_None;
+
+}
static PyObject *Image_getMaxXY( BPy_Image * self )
{
Image *image = self->image;
@@ -293,6 +474,37 @@
}
+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" );
+
+}
+
+static PyObject *Image_save( BPy_Image * self )
+{
+ Py_INCREF( Py_None );
+
+ if(!IMB_saveiff(self->image->ibuf,self->image->name,self->image->ibuf->flags))
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "could not save image" );
+
+ return Py_None; // normal return, image saved
+}
+
/*****************************************************************************/
/* Function: Image_Init */
/*****************************************************************************/
@@ -331,7 +543,13 @@
static PyObject *Image_glLoad( BPy_Image * self );
static PyObject *Image_glFree( BPy_Image * self );
static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args );
+static PyObject *Image_getPixelI( BPy_Image * self, PyObject * args );
+static PyObject *Image_setPixelF( BPy_Image * self, PyObject * args );
+static PyObject *Image_setPixelI( 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,9 +557,17 @@
static PyMethodDef BPy_Image_methods[] = {
/* name, method, flags, doc */
{"getPixelF", ( PyCFunction ) Image_getPixelF, METH_VARARGS,
- "(float, float) - Get colors of specified pixel as [r,g,b,a]"},
- {"getMaxXY", ( PyCFunction ) Image_getMaxXY, METH_VARARGS,
+ "(int, int) - Get colors of specified pixel as [r,g,b,a]"},
+ {"getPixelI", ( PyCFunction ) Image_getPixelI, METH_VARARGS,
+ "(int, int) - Get colors of specified pixel as [r,g,b,a]"},
+ {"setPixelF", ( PyCFunction ) Image_setPixelF, METH_VARARGS,
+ "(int, int, [f r,f g,f b,f a]) - Set colors of specified pixel"},
+ {"setPixelI", ( PyCFunction ) Image_setPixelI, METH_VARARGS,
+ "(int, int, [i r, i g, i b, i a]) - 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 minimun 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,
@@ -372,6 +598,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,
+ "() - Writes the current buffer to the image"},
{NULL, NULL, 0, NULL}
};

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
25/34/b61103ca7ff9b94667964e9d6e77

Event Timeline