Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-03-12 14:13:57 +0300
committerCampbell Barton <ideasman42@gmail.com>2008-03-12 14:13:57 +0300
commitaf93553640edda4e08cad4d5f8c621e389ff792a (patch)
tree576d9e5a79f69c4977a37969626755602e29869d /source/blender/python/api2_2x
parent51c58f3ca2dd86ed0382997f46f36a8686b427a7 (diff)
Moved recent addition of get/setPixelF to get/setPixelHDR and kept get/setPixelF limited to 0.0-1.0 range, to prevent existing scripts breaking.
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r--source/blender/python/api2_2x/Image.c125
-rw-r--r--source/blender/python/api2_2x/doc/Image.py33
2 files changed, 153 insertions, 5 deletions
diff --git a/source/blender/python/api2_2x/Image.c b/source/blender/python/api2_2x/Image.c
index a182563170d..c8217eba2b2 100644
--- a/source/blender/python/api2_2x/Image.c
+++ b/source/blender/python/api2_2x/Image.c
@@ -111,8 +111,10 @@ static PyObject *Image_updateDisplay( BPy_Image * self );
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_getPixelHDR( 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_setPixelHDR( 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 );
@@ -129,10 +131,14 @@ static PyMethodDef BPy_Image_methods[] = {
/* name, method, flags, doc */
{"getPixelF", ( PyCFunction ) Image_getPixelF, METH_VARARGS,
"(int, int) - Get pixel color as floats returns [r,g,b,a]"},
+ {"getPixelHDR", ( PyCFunction ) Image_getPixelHDR, METH_VARARGS,
+ "(int, int) - Get pixel color as floats returns [r,g,b,a]"},
{"getPixelI", ( PyCFunction ) Image_getPixelI, METH_VARARGS,
"(int, int) - Get pixel color as ints 0-255 returns [r,g,b,a]"},
{"setPixelF", ( PyCFunction ) Image_setPixelF, METH_VARARGS,
"(int, int, [f r,f g,f b,f a]) - Set pixel color using floats"},
+ {"setPixelHDR", ( PyCFunction ) Image_setPixelHDR, METH_VARARGS,
+ "(int, int, [f r,f g,f b,f a]) - Set pixel color using floats"},
{"setPixelI", ( PyCFunction ) Image_setPixelI, METH_VARARGS,
"(int, int, [i r, i g, i b, i a]) - Set pixel color using ints 0-255"},
{"getMaxXY", ( PyCFunction ) Image_getMaxXY, METH_NOARGS,
@@ -384,12 +390,12 @@ static PyObject *M_Image_Load( PyObject * self, PyObject * value )
/**
- * getPixelF( x, y )
+ * getPixelHDR( x, y )
* returns float list of pixel colors in rgba order.
* returned values are floats , in the full range of the float image source.
*/
-static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args )
+static PyObject *Image_getPixelHDR( BPy_Image * self, PyObject * args )
{
PyObject *attr;
@@ -505,9 +511,66 @@ static PyObject *Image_getPixelI( BPy_Image * self, PyObject * args )
}
+/**
+ * getPixelF( x, y )
+ * returns float list of pixel colors in rgba order.
+ * returned values are floats normalized to 0.0 - 1.0.
+ * blender images are all 4x8 bit at the moment apr-2005
+ */
+
+static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args )
+{
+
+ PyObject *attr;
+ ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL);
+ 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 */
+ int i;
+
+ if( !PyArg_ParseTuple( args, "ii", &x, &y ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected 2 integers" );
+
+ if( !ibuf || !ibuf->rect ) /* loading didn't work */
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't load image data in Blender" );
+
+ if( ibuf->type == 1 ) /* bitplane image */
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "unsupported bitplane image format" );
+
+ if( x > ( ibuf->x - 1 )
+ || y > ( ibuf->y - 1 )
+ || x < ibuf->xorig || y < 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
+ */
+
+ attr = PyList_New(4);
+
+ if (!attr)
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't allocate memory for color list" );
+
+ index = ( x + y * ibuf->x ) * pixel_size;
+
+ pixel = ( char * ) ibuf->rect;
+ for (i=0; i<4; i++) {
+ PyList_SetItem( attr, i, PyFloat_FromDouble( ( ( double ) pixel[index+i] ) / 255.0 ));
+ }
+ return attr;
+}
+
/* set pixel as floats */
-static PyObject *Image_setPixelF( BPy_Image * self, PyObject * args )
+static PyObject *Image_setPixelHDR( BPy_Image * self, PyObject * args )
{
ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL);
float *pixel; /* image data */
@@ -606,6 +669,62 @@ static PyObject *Image_setPixelI( BPy_Image * self, PyObject * args )
Py_RETURN_NONE;
}
+/* set pixel as floats */
+
+static PyObject *Image_setPixelF( BPy_Image * self, PyObject * args )
+{
+ ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL);
+ 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( !ibuf || !ibuf->rect ) /* didn't work */
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "couldn't load image data in Blender" );
+
+ if( ibuf->type == 1 ) /* bitplane image */
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "unsupported bitplane image format" );
+
+ if( x > ( ibuf->x - 1 )
+ || y > ( ibuf->y - 1 )
+ || x < ibuf->xorig || y < ibuf->yorig )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "x or y is out of ruange" );
+
+ 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 * ibuf->x ) * pixel_size;
+
+ pixel = ( char * ) ibuf->rect;
+
+ pixel[index] = ( char ) ( p[0] * 255.0 );
+ pixel[index + 1] = ( char ) ( p[1] * 255.0 );
+ pixel[index + 2] = ( char ) ( p[2] * 255.0 );
+ pixel[index + 3] = ( char ) ( p[3] * 255.0 );
+
+ ibuf->userflags |= IB_BITMAPDIRTY;
+ Py_RETURN_NONE;
+}
/* get max extent of image */
diff --git a/source/blender/python/api2_2x/doc/Image.py b/source/blender/python/api2_2x/doc/Image.py
index 6b725fa9f78..92a05c2604d 100644
--- a/source/blender/python/api2_2x/doc/Image.py
+++ b/source/blender/python/api2_2x/doc/Image.py
@@ -141,7 +141,7 @@ class Image:
@rtype: int
"""
- def getPixelF(x, y):
+ def getPixelHDR(x, y):
"""
Get the the colors of the current pixel in the form [r,g,b,a].
For float image types, returned values can be greater then the useual [0.0, 1.0] range.
@@ -153,6 +153,20 @@ class Image:
@param x: the x coordinate of pixel.
@param y: the y coordinate of pixel.
"""
+
+ def getPixelF(x, y):
+ """
+ Get the the colors of the current pixel in the form [r,g,b,a].
+ Returned values are floats normalized to 0.0 - 1.0.
+ Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY}
+ @returns: [ r, g, b, a]
+ @rtype: list of 4 floats
+ @type x: int
+ @type y: int
+ @param x: the x coordinate of pixel.
+ @param y: the y coordinate of pixel.
+ """
+
def getPixelI(x, y):
"""
Get the the colors of the current pixel in the form [r,g,b,a].
@@ -309,7 +323,7 @@ class Image:
@param speed: The new value in [1, 100].
"""
- def setPixelF(x, y, (r, g, b,a )):
+ def setPixelHDR(x, y, (r, g, b,a )):
"""
Set the the colors of the current pixel in the form [r,g,b,a].
For float image types, returned values can be greater then the useual [0.0, 1.0] range.
@@ -324,6 +338,21 @@ class Image:
@rtype: none
"""
+ def setPixelF(x, y, (r, g, b,a )):
+ """
+ Set the the colors of the current pixel in the form [r,g,b,a].
+ Color values must be floats in the range 0.0 - 1.0.
+ Pixel coordinates are in the range from 0 to N-1. See L{getMaxXY}
+ @type x: int
+ @type y: int
+ @type r: float
+ @type g: float
+ @type b: float
+ @type a: float
+ @returns: nothing
+ @rtype: none
+ """
+
def setPixelI(x, y, (r, g, b, a)):
"""
Set the the colors of the current pixel in the form [r,g,b,a].