2003-04-08 19:54:14 +00:00
|
|
|
/*
|
2004-05-25 10:36:58 +00:00
|
|
|
* $Id$
|
2003-04-08 19:54:14 +00:00
|
|
|
*
|
|
|
|
|
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version. The Blender
|
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
|
* about this.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2004-05-25 10:36:58 +00:00
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2003-04-08 19:54:14 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This is a new part of Blender.
|
|
|
|
|
*
|
2005-04-30 19:30:35 +00:00
|
|
|
* Contributor(s): Willian P. Germano, Campbell Barton, Joilnen B. Leite,
|
|
|
|
|
* Austin Benesh
|
2003-04-08 19:54:14 +00:00
|
|
|
*
|
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*/
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
#include "Image.h" /*This must come first */
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "BDR_drawmesh.h" /* free_realtime_image */
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_image.h"
|
|
|
|
|
#include "BIF_drawimage.h"
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "DNA_space_types.h" /* FILE_MAXDIR = 160 */
|
|
|
|
|
#include "IMB_imbuf_types.h" /* for the IB_rect define */
|
|
|
|
|
#include "BIF_gl.h"
|
2003-05-31 04:43:10 +00:00
|
|
|
#include "gen_utils.h"
|
|
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
/*
|
|
|
|
|
fixme
|
|
|
|
|
this belongs in a header
|
|
|
|
|
sswaney 10-aug-2005
|
|
|
|
|
*/
|
|
|
|
|
short IMB_saveiff( struct ImBuf *ibuf, char *naam, int flags );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-05-25 10:36:58 +00:00
|
|
|
/* Python BPy_Image defaults: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-05-25 10:36:58 +00:00
|
|
|
#define EXPP_IMAGE_REP 1
|
|
|
|
|
#define EXPP_IMAGE_REP_MIN 1
|
2003-05-31 04:43:10 +00:00
|
|
|
#define EXPP_IMAGE_REP_MAX 16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************/
|
|
|
|
|
/*** The Image Module ***/
|
|
|
|
|
/************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python API function prototypes for the Image module. */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2005-12-14 03:27:35 +00:00
|
|
|
static PyObject *M_Image_New( PyObject * self, PyObject * args );
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Image_Get( PyObject * self, PyObject * args );
|
2005-12-13 00:00:11 +00:00
|
|
|
static PyObject *M_Image_GetCurrent( PyObject * self );
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Image_Load( PyObject * self, PyObject * args );
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* The following string definitions are used for documentation strings. */
|
|
|
|
|
/* In Python these will be written to the console when doing a */
|
|
|
|
|
/* Blender.Image.__doc__ */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static char M_Image_doc[] = "The Blender Image module\n\n";
|
2003-05-31 04:43:10 +00:00
|
|
|
|
2005-12-14 03:27:35 +00:00
|
|
|
static char M_Image_New_doc[] =
|
|
|
|
|
"() - return a new Image object";
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
static char M_Image_Get_doc[] =
|
2004-09-25 20:30:40 +00:00
|
|
|
"(name) - return the image with the name 'name', \
|
2003-05-31 04:43:10 +00:00
|
|
|
returns None if not found.\n If 'name' is not specified, \
|
|
|
|
|
it returns a list of all images in the\ncurrent scene.";
|
|
|
|
|
|
2005-12-13 00:00:11 +00:00
|
|
|
static char M_Image_GetCurrent_doc[] =
|
|
|
|
|
"() - return the current image, from last active the uv/image view, \
|
|
|
|
|
returns None no image is in the view.\n";
|
|
|
|
|
|
2003-05-31 04:43:10 +00:00
|
|
|
static char M_Image_Load_doc[] =
|
2004-09-25 20:30:40 +00:00
|
|
|
"(filename) - return image from file filename as Image Object, \
|
2003-05-31 04:43:10 +00:00
|
|
|
returns None if not found.\n";
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python method structure definition for Blender.Image module: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
struct PyMethodDef M_Image_methods[] = {
|
2005-12-14 03:27:35 +00:00
|
|
|
{"New", M_Image_New, METH_VARARGS, M_Image_New_doc},
|
|
|
|
|
{"Get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
2005-12-15 02:06:37 +00:00
|
|
|
{"GetCurrent", ( PyCFunction ) M_Image_GetCurrent, METH_NOARGS, M_Image_GetCurrent_doc},
|
2005-12-14 03:27:35 +00:00
|
|
|
{"get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
|
|
|
|
{"Load", M_Image_Load, METH_VARARGS, M_Image_Load_doc},
|
2004-05-25 10:36:58 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
2003-05-31 04:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
2005-12-14 03:27:35 +00:00
|
|
|
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2005-12-14 03:27:35 +00:00
|
|
|
/* Function: M_Image_New */
|
|
|
|
|
/* Python equivalent: Blender.Image.New */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2005-12-14 03:27:35 +00:00
|
|
|
static PyObject *M_Image_New( PyObject * self, PyObject * args)
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2005-12-14 03:27:35 +00:00
|
|
|
int width, height, depth;
|
|
|
|
|
char *name;
|
|
|
|
|
Image *img;
|
|
|
|
|
if( !PyArg_ParseTuple( args, "siii", &name, &width, &height, &depth ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected 1 string and 3 ints" ) );
|
|
|
|
|
if (width > 5000 || height > 5000 || width < 1 || height < 1)
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"Image width and height must be between 1 and 5000" ) );
|
|
|
|
|
img = new_image(width, height, name, 0);
|
|
|
|
|
if( !img )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyObject Image_Type" ) );
|
2005-12-18 08:47:55 +00:00
|
|
|
|
2005-12-14 03:27:35 +00:00
|
|
|
return Image_CreatePyObject( img );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
2005-12-14 03:27:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: M_Image_Get */
|
|
|
|
|
/* Python equivalent: Blender.Image.Get */
|
|
|
|
|
/* Description: Receives a string and returns the image object */
|
|
|
|
|
/* whose name matches the string. If no argument is */
|
|
|
|
|
/* passed in, a list of all image names in the */
|
|
|
|
|
/* current scene is returned. */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Image_Get( PyObject * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *name = NULL;
|
2004-05-25 10:36:58 +00:00
|
|
|
Image *img_iter;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument (or nothing)" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
img_iter = G.main->image.first;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( name ) { /* (name) - Search image by name */
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
BPy_Image *wanted_image = NULL;
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( ( img_iter ) && ( wanted_image == NULL ) ) {
|
|
|
|
|
if( strcmp( name, img_iter->id.name + 2 ) == 0 ) {
|
2005-04-30 19:30:35 +00:00
|
|
|
wanted_image = ( BPy_Image * )
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject_NEW( BPy_Image, &Image_Type );
|
|
|
|
|
if( wanted_image )
|
|
|
|
|
wanted_image->image = img_iter;
|
2004-05-25 10:36:58 +00:00
|
|
|
}
|
|
|
|
|
img_iter = img_iter->id.next;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( wanted_image == NULL ) { /* Requested image doesn't exist */
|
2004-05-25 10:36:58 +00:00
|
|
|
char error_msg[64];
|
2004-09-25 20:30:40 +00:00
|
|
|
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
|
|
|
|
"Image \"%s\" not found", name );
|
|
|
|
|
return ( EXPP_ReturnPyObjError
|
|
|
|
|
( PyExc_NameError, error_msg ) );
|
2004-05-25 10:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) wanted_image;
|
2003-05-13 01:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
else { /* () - return a list of all images in the scene */
|
2004-05-25 10:36:58 +00:00
|
|
|
int index = 0;
|
|
|
|
|
PyObject *img_list, *pyobj;
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
img_list = PyList_New( BLI_countlist( &( G.main->image ) ) );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( img_list == NULL )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyList" ) );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( img_iter ) {
|
|
|
|
|
pyobj = Image_CreatePyObject( img_iter );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyList_SET_ITEM( img_list, index, pyobj );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
img_iter = img_iter->id.next;
|
|
|
|
|
index++;
|
2003-05-13 01:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( img_list );
|
2003-05-13 01:54:28 +00:00
|
|
|
}
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-13 00:00:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2005-12-14 03:27:35 +00:00
|
|
|
/* Function: M_Image_GetCurrent*/
|
2005-12-13 00:00:11 +00:00
|
|
|
/* Python equivalent: Blender.Image.GetCurrent */
|
|
|
|
|
/* Description: Returns the active current (G.sima) */
|
|
|
|
|
/* This will be the image last under the mouse cursor */
|
|
|
|
|
/* None if there is no Image. */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
static PyObject *M_Image_GetCurrent( PyObject * self )
|
|
|
|
|
{
|
2005-12-13 00:27:10 +00:00
|
|
|
if (!G.sima || !G.sima->image) {
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
2005-12-14 03:27:35 +00:00
|
|
|
return Image_CreatePyObject( G.sima->image );
|
2005-12-13 00:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-13 01:54:28 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: M_Image_Load */
|
|
|
|
|
/* Python equivalent: Blender.Image.Load */
|
|
|
|
|
/* Description: Receives a string and returns the image object */
|
|
|
|
|
/* whose filename matches the string. */
|
2003-05-13 01:54:28 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Image_Load( PyObject * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *fname;
|
|
|
|
|
Image *img_ptr;
|
2004-05-25 10:36:58 +00:00
|
|
|
BPy_Image *img;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "s", &fname ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument" ) );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
img = ( BPy_Image * ) PyObject_NEW( BPy_Image, &Image_Type );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !img )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyObject Image_Type" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
img_ptr = add_image( fname );
|
|
|
|
|
if( !img_ptr )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_IOError,
|
|
|
|
|
"couldn't load image" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
img->image = img_ptr;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) img;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-30 19:30:35 +00:00
|
|
|
|
|
|
|
|
/**
|
2005-05-22 18:43:29 +00:00
|
|
|
* getPixelF( x, y )
|
|
|
|
|
* returns float list of pixel colors in rgba order.
|
|
|
|
|
* returned values are floats normalized to 0.0 - 1.0.
|
2005-04-30 19:30:35 +00:00
|
|
|
* blender images are all 4x8 bit at the moment apr-2005
|
|
|
|
|
*/
|
|
|
|
|
|
2005-05-22 18:43:29 +00:00
|
|
|
static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args )
|
2005-04-30 19:30:35 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
PyObject *attr;
|
|
|
|
|
Image *image = self->image;
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
char *pixel; /* image data */
|
2005-04-30 19:30:35 +00:00
|
|
|
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( "[f,f,f,f]",
|
|
|
|
|
( ( float ) pixel[index] ) / 255.0,
|
|
|
|
|
( ( float ) pixel[index + 1] ) / 255.0,
|
|
|
|
|
( ( float ) pixel[index + 2] ) / 255.0,
|
|
|
|
|
( ( float ) pixel[index + 3] / 255.0 ) );
|
|
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
if( attr ) /* normal return */
|
|
|
|
|
return attr;
|
|
|
|
|
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get pixel colors" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getPixelI( x, y )
|
|
|
|
|
* returns integer list of pixel colors in rgba order.
|
|
|
|
|
* returned values are ints normalized to 0-255.
|
|
|
|
|
* blender images are all 4x8 bit at the moment apr-2005
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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 */
|
2005-04-30 19:30:35 +00:00
|
|
|
return attr;
|
|
|
|
|
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get pixel colors" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
/* set pixel as floats */
|
|
|
|
|
|
|
|
|
|
static PyObject *Image_setPixelF( BPy_Image * self, PyObject * args )
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2005-08-17 14:26:00 +00:00
|
|
|
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 );
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* set pixel as ints */
|
|
|
|
|
|
|
|
|
|
static PyObject *Image_setPixelI( BPy_Image * self, PyObject * args )
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2005-08-17 14:26:00 +00:00
|
|
|
pixel[index] = ( char ) p[0];
|
|
|
|
|
pixel[index + 1] = ( char ) p[1];
|
|
|
|
|
pixel[index + 2] = ( char ) p[2];
|
|
|
|
|
pixel[index + 3] = ( char ) p[3];
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* get max extent of image */
|
|
|
|
|
|
2005-04-30 19:30:35 +00:00
|
|
|
static PyObject *Image_getMaxXY( 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 );
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
|
2005-04-30 19:30:35 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
|
2005-04-30 19:30:35 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"could not determine max x or y" );
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* get min extent of image */
|
2005-04-30 19:30:35 +00:00
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
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" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* save image to file */
|
|
|
|
|
|
|
|
|
|
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" );
|
|
|
|
|
|
|
|
|
|
Py_RETURN_NONE; /* normal return, image saved */
|
2005-04-30 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_Init */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Image_Init( void )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *submodule;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
Image_Type.ob_type = &PyType_Type;
|
2003-06-02 20:15:50 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
submodule =
|
|
|
|
|
Py_InitModule3( "Blender.Image", M_Image_methods,
|
|
|
|
|
M_Image_doc );
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( submodule );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-31 04:43:10 +00:00
|
|
|
/************************/
|
|
|
|
|
/*** The Image PyType ***/
|
|
|
|
|
/************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Image methods declarations: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getName( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getFilename( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getSize( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getDepth( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getXRep( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getYRep( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getBindCode( BPy_Image * self );
|
2005-12-14 03:27:35 +00:00
|
|
|
static PyObject *Image_getStart( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getEnd( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_getSpeed( BPy_Image * self );
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setName( BPy_Image * self, PyObject * args );
|
2005-02-09 05:19:24 +00:00
|
|
|
static PyObject *Image_setFilename( BPy_Image * self, PyObject * args );
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setXRep( BPy_Image * self, PyObject * args );
|
|
|
|
|
static PyObject *Image_setYRep( BPy_Image * self, PyObject * args );
|
2005-12-14 03:27:35 +00:00
|
|
|
static PyObject *Image_setStart( BPy_Image * self, PyObject * args );
|
|
|
|
|
static PyObject *Image_setEnd( BPy_Image * self, PyObject * args );
|
|
|
|
|
static PyObject *Image_setSpeed( BPy_Image * self, PyObject * args );
|
2005-04-30 19:30:35 +00:00
|
|
|
static PyObject *Image_reload( BPy_Image * self );
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_glLoad( BPy_Image * self );
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
static PyObject *Image_glFree( BPy_Image * self );
|
2005-05-22 18:43:29 +00:00
|
|
|
static PyObject *Image_getPixelF( BPy_Image * self, PyObject * args );
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
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 );
|
2005-04-30 19:30:35 +00:00
|
|
|
static PyObject *Image_getMaxXY( BPy_Image * self );
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
static PyObject *Image_getMinXY( BPy_Image * self );
|
|
|
|
|
static PyObject *Image_save( BPy_Image * self );
|
|
|
|
|
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Image methods table: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2003-06-28 07:38:21 +00:00
|
|
|
static PyMethodDef BPy_Image_methods[] = {
|
2004-09-25 20:30:40 +00:00
|
|
|
/* name, method, flags, doc */
|
2005-05-22 18:43:29 +00:00
|
|
|
{"getPixelF", ( PyCFunction ) Image_getPixelF, METH_VARARGS,
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
"(int, int) - Get pixel color as floats 0.0-1.0 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 0.0-1.0"},
|
|
|
|
|
{"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,
|
2005-04-30 19:30:35 +00:00
|
|
|
"() - Get maximum x & y coordinates of current image as [x, y]"},
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
{"getMinXY", ( PyCFunction ) Image_getMinXY, METH_NOARGS,
|
|
|
|
|
"() - Get minimun x & y coordinates of image as [x, y]"},
|
2004-09-25 20:30:40 +00:00
|
|
|
{"getName", ( PyCFunction ) Image_getName, METH_NOARGS,
|
|
|
|
|
"() - Return Image object name"},
|
|
|
|
|
{"getFilename", ( PyCFunction ) Image_getFilename, METH_NOARGS,
|
|
|
|
|
"() - Return Image object filename"},
|
|
|
|
|
{"getSize", ( PyCFunction ) Image_getSize, METH_NOARGS,
|
|
|
|
|
"() - Return Image object [width, height] dimension in pixels"},
|
|
|
|
|
{"getDepth", ( PyCFunction ) Image_getDepth, METH_NOARGS,
|
|
|
|
|
"() - Return Image object pixel depth"},
|
|
|
|
|
{"getXRep", ( PyCFunction ) Image_getXRep, METH_NOARGS,
|
|
|
|
|
"() - Return Image object x repetition value"},
|
|
|
|
|
{"getYRep", ( PyCFunction ) Image_getYRep, METH_NOARGS,
|
|
|
|
|
"() - Return Image object y repetition value"},
|
2005-12-14 03:27:35 +00:00
|
|
|
{"getStart", ( PyCFunction ) Image_getStart, METH_NOARGS,
|
|
|
|
|
"() - Return Image object start frame."},
|
|
|
|
|
{"getEnd", ( PyCFunction ) Image_getEnd, METH_NOARGS,
|
|
|
|
|
"() - Return Image object end frame."},
|
|
|
|
|
{"getSpeed", ( PyCFunction ) Image_getSpeed, METH_NOARGS,
|
|
|
|
|
"() - Return Image object speed (fps)."},
|
2004-09-25 20:30:40 +00:00
|
|
|
{"getBindCode", ( PyCFunction ) Image_getBindCode, METH_NOARGS,
|
|
|
|
|
"() - Return Image object's bind code value"},
|
|
|
|
|
{"reload", ( PyCFunction ) Image_reload, METH_NOARGS,
|
|
|
|
|
"() - Reload the image from the filesystem"},
|
|
|
|
|
{"glLoad", ( PyCFunction ) Image_glLoad, METH_NOARGS,
|
|
|
|
|
"() - Load the image data in OpenGL texture memory.\n\
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
The bindcode (int) is returned."},
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
{"glFree", ( PyCFunction ) Image_glFree, METH_NOARGS,
|
|
|
|
|
"() - Free the image data from OpenGL texture memory only,\n\
|
|
|
|
|
see also image.glLoad()."},
|
2004-09-25 20:30:40 +00:00
|
|
|
{"setName", ( PyCFunction ) Image_setName, METH_VARARGS,
|
|
|
|
|
"(str) - Change Image object name"},
|
2005-02-09 05:19:24 +00:00
|
|
|
{"setFilename", ( PyCFunction ) Image_setFilename, METH_VARARGS,
|
2005-04-30 19:30:35 +00:00
|
|
|
"(str) - Change Image file name"},
|
2004-09-25 20:30:40 +00:00
|
|
|
{"setXRep", ( PyCFunction ) Image_setXRep, METH_VARARGS,
|
|
|
|
|
"(int) - Change Image object x repetition value"},
|
|
|
|
|
{"setYRep", ( PyCFunction ) Image_setYRep, METH_VARARGS,
|
|
|
|
|
"(int) - Change Image object y repetition value"},
|
2005-12-14 03:27:35 +00:00
|
|
|
{"setStart", ( PyCFunction ) Image_setStart, METH_VARARGS,
|
|
|
|
|
"(int) - Change Image object animation start value"},
|
|
|
|
|
{"setEnd", ( PyCFunction ) Image_setEnd, METH_VARARGS,
|
|
|
|
|
"(int) - Change Image object animation end value"},
|
2005-12-16 22:40:20 +00:00
|
|
|
{"setSpeed", ( PyCFunction ) Image_setSpeed, METH_VARARGS,
|
2005-12-14 03:27:35 +00:00
|
|
|
"(int) - Change Image object animation speed (fps)"},
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
{"save", ( PyCFunction ) Image_save, METH_NOARGS,
|
|
|
|
|
"() - Write image buffer to file"},
|
2004-06-06 22:42:51 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
2003-05-31 04:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python Image_Type callback function prototypes: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Image_dealloc( BPy_Image * self );
|
|
|
|
|
static int Image_setAttr( BPy_Image * self, char *name, PyObject * v );
|
|
|
|
|
static int Image_compare( BPy_Image * a, BPy_Image * b );
|
|
|
|
|
static PyObject *Image_getAttr( BPy_Image * self, char *name );
|
|
|
|
|
static PyObject *Image_repr( BPy_Image * self );
|
2003-05-31 04:43:10 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python Image_Type structure definition: */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyTypeObject Image_Type = {
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
PyObject_HEAD_INIT( NULL ) /* required macro. ( no comma needed ) */
|
2004-09-25 20:30:40 +00:00
|
|
|
0, /* ob_size */
|
|
|
|
|
"Blender Image", /* tp_name */
|
|
|
|
|
sizeof( BPy_Image ), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
2004-05-25 10:36:58 +00:00
|
|
|
/* methods */
|
2004-09-25 20:30:40 +00:00
|
|
|
( destructor ) Image_dealloc, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
( getattrfunc ) Image_getAttr, /* tp_getattr */
|
|
|
|
|
( setattrfunc ) Image_setAttr, /* tp_setattr */
|
|
|
|
|
( cmpfunc ) Image_compare, /* tp_compare */
|
|
|
|
|
( reprfunc ) Image_repr, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_as_hash */
|
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, /* tp_doc */
|
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
|
BPy_Image_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
2005-04-30 19:30:35 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* up to tp_del, to avoid a warning */
|
2003-05-31 04:43:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_dealloc */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Image type. It is */
|
|
|
|
|
/* the destructor function. */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Image_dealloc( BPy_Image * self )
|
2003-05-31 04:43:10 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject_DEL( self );
|
2003-05-31 04:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_CreatePyObject */
|
|
|
|
|
/* Description: This function will create a new BPy_Image from an existing */
|
|
|
|
|
/* Blender image structure. */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Image_CreatePyObject( Image * image )
|
2003-05-31 04:43:10 +00:00
|
|
|
{
|
2003-06-28 07:38:21 +00:00
|
|
|
BPy_Image *py_img;
|
2004-09-25 20:30:40 +00:00
|
|
|
py_img = ( BPy_Image * ) PyObject_NEW( BPy_Image, &Image_Type );
|
2005-12-13 00:00:11 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !py_img )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create BPy_Image object" );
|
2005-12-13 00:00:11 +00:00
|
|
|
|
2003-05-31 04:43:10 +00:00
|
|
|
py_img->image = image;
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) py_img;
|
2003-05-31 04:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_CheckPyObject */
|
2003-05-31 04:43:10 +00:00
|
|
|
/* Description: This function returns true when the given PyObject is of the */
|
2004-09-25 20:30:40 +00:00
|
|
|
/* type Image. Otherwise it will return false. */
|
2003-05-31 04:43:10 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
int Image_CheckPyObject( PyObject * pyobj )
|
2003-05-31 04:43:10 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( pyobj->ob_type == &Image_Type );
|
2003-05-31 04:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-23 17:46:06 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_FromPyObject */
|
|
|
|
|
/* Description: Returns the Blender Image associated with this object */
|
2003-11-23 17:46:06 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
Image *Image_FromPyObject( PyObject * pyobj )
|
2003-11-23 17:46:06 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( ( BPy_Image * ) pyobj )->image;
|
2003-11-23 17:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Python BPy_Image methods: */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getName( BPy_Image * self )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyString_FromString( self->image->id.name + 2 );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.name attribute" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getFilename( BPy_Image * self )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyString_FromString( self->image->name );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.filename attribute" ) );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getSize( BPy_Image * self )
|
2003-07-30 21:15:41 +00:00
|
|
|
{
|
|
|
|
|
PyObject *attr;
|
|
|
|
|
Image *image = self->image;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !image->ibuf ) /* if no image data available */
|
|
|
|
|
load_image( image, IB_rect, "", 0 ); /* loading it */
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !image->ibuf ) /* didn't work */
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't load image data in Blender" );
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
attr = Py_BuildValue( "[hh]", image->ibuf->x, image->ibuf->y );
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.size attribute" );
|
2003-07-30 21:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getDepth( BPy_Image * self )
|
2003-07-30 21:15:41 +00:00
|
|
|
{
|
|
|
|
|
PyObject *attr;
|
|
|
|
|
Image *image = self->image;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !image->ibuf ) /* if no image data available */
|
|
|
|
|
load_image( image, IB_rect, "", 0 ); /* loading it */
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !image->ibuf ) /* didn't work */
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't load image data in Blender" );
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
attr = Py_BuildValue( "h", image->ibuf->depth );
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-07-30 21:15:41 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.depth attribute" );
|
2003-07-30 21:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getXRep( BPy_Image * self )
|
2003-07-12 18:02:54 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyInt_FromLong( self->image->xrep );
|
2003-07-12 18:02:54 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-07-12 18:02:54 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.xrep attribute" );
|
2003-07-12 18:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getYRep( BPy_Image * self )
|
2003-07-12 18:02:54 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyInt_FromLong( self->image->yrep );
|
2003-07-12 18:02:54 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2004-05-25 10:36:58 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.yrep attribute" );
|
2004-05-25 10:36:58 +00:00
|
|
|
}
|
2003-07-12 18:02:54 +00:00
|
|
|
|
2005-12-14 03:27:35 +00:00
|
|
|
static PyObject *Image_getStart( BPy_Image * self )
|
|
|
|
|
{
|
|
|
|
|
PyObject *attr = PyInt_FromLong( self->image->twsta );
|
|
|
|
|
|
|
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
|
|
|
|
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.start attribute" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *Image_getEnd( BPy_Image * self )
|
|
|
|
|
{
|
|
|
|
|
PyObject *attr = PyInt_FromLong( self->image->twend );
|
|
|
|
|
|
|
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
|
|
|
|
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.end attribute" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *Image_getSpeed( BPy_Image * self )
|
|
|
|
|
{
|
|
|
|
|
PyObject *attr = PyInt_FromLong( self->image->animspeed );
|
|
|
|
|
|
|
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
|
|
|
|
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.speed attribute" );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getBindCode( BPy_Image * self )
|
2004-07-16 06:00:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyLong_FromUnsignedLong( self->image->bindcode );
|
2004-07-16 06:00:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2004-07-16 06:00:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Image.bindcode attribute" );
|
2004-07-16 06:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_reload( BPy_Image * self )
|
2004-05-25 10:36:58 +00:00
|
|
|
{
|
|
|
|
|
Image *img = self->image;
|
2004-09-25 20:30:40 +00:00
|
|
|
|
|
|
|
|
free_image_buffers( img ); /* force read again */
|
2004-05-25 10:36:58 +00:00
|
|
|
img->ok = 1;
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
Py_RETURN_NONE;
|
2003-07-12 18:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
static PyObject *Image_glFree( BPy_Image * self )
|
|
|
|
|
{
|
|
|
|
|
Image *img = self->image;
|
|
|
|
|
|
|
|
|
|
free_realtime_image( img );
|
3D view orbit option: Around Active
This fixes the active object in place when orbiting the view.
Choppy 15fps demo can be seen there: http://www.elysiun.com/~theeth/bf/around_active.html
Image Memory Grabage Collection
This adds memory handling to the image code. An image is tagged each time it is used.
During a collection cycle (frequency of cycles is user defined), if an image is older
than a user defined limit, its buffer gets deallocated. This also applies to gl memory buffers.
Images that are loading in GL memory needs to go through two time outs before being fully deallocated: the first time out deallocated the gl memorry, the second the buffer in ram.
Notes:
Image buffer loaded from python gets tagged as permanent upon load. That tag is removed when python stops using the image.
I might have missed some tagging spots, especially in the rendering pipeline. Someone with more knowledge about this code should check to be careful.
Tagging is done on every access, for rendering, this will probably be a performance hit. A scheme should be developped to only tag when the rendering is completed.
Collecting is called in draw_object, most likely not the best place to do it.
Safe from undo, since using undo deallocates memory anyway (like when loading a blend file with one currently opened)
Userpref DNA changes:
I've changed a couple of flagging variables from short to int. Some because they needed more space, others to keep SDNA happy.
Info window changes:
I've grouped a couple of buttons in aligned blocks and changed the color of mutually exclusive options to make them clearer.
Matt didn't do any changes on that in tuhopuu, so hopefully I'm not stepping on anyone's feet with this.
Also changed double constants into floats with f in a couple of places (mostly space.c) to make compiler happier.
2005-07-06 00:33:41 +00:00
|
|
|
/* remove the nocollect flag, image is available for garbage collection again */
|
|
|
|
|
img->flag &= ~IMA_NOCOLLECT;
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
Py_RETURN_NONE;
|
BPython:
- Blender.Window: added function GetPerspMatrix() (Tom Musgrave's patch, thanks);
- added Chris Want's patch to tell argc, argv to the Python interpreter (thanks, Hos);
- Blender.Image: added image.glFree() to free textures bound by the recently added
image.glLoad() (both suggested by Campbell Barton -- thanks, with these Blender can
be used to load textures for scripts);
- Blender.Sound: removed for now at least a few get/set methods of vars that can't be
accessed via interface;
- renamed Get/makeActive to Get/setCurrent in Blender.World (actually added alias for
now), same in Blender.Sound: renamed makeActive to setCurrent. Stephen Swaney
pointed this some weeks ago, we should stick to one naming convention.
- added documentation for Sound and Window.Theme modules and the other added
functions, made other small updates.
- Blender.Object: made 'worldspace' become the default output of .getMatrix and .mat/.matrix:
after reading a discussion on blender.org's Python forum where eeshlo mentioned the
pre 2.34 default was worldspace, I took a better look at Blender's relevant code,
confirmed, talked to Theeth about this and as he suggested am changing the default
back to 'worldspace'.
2004-10-20 05:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_glLoad( BPy_Image * self )
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
{
|
|
|
|
|
Image *img = self->image;
|
|
|
|
|
unsigned int *bind = &img->bindcode;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( *bind == 0 ) {
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !img->ibuf ) /* if no image data is available */
|
|
|
|
|
load_image( img, IB_rect, "", 0 ); /* loading it */
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !img->ibuf ) /* didn't work */
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't load image data in Blender" );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
glGenTextures( 1, ( GLuint * ) bind );
|
|
|
|
|
glBindTexture( GL_TEXTURE_2D, *bind );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, img->ibuf->x,
|
|
|
|
|
img->ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
|
img->ibuf->rect );
|
|
|
|
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
|
|
|
|
GL_LINEAR_MIPMAP_NEAREST );
|
|
|
|
|
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
|
|
|
|
GL_LINEAR );
|
|
|
|
|
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, img->ibuf->x,
|
|
|
|
|
img->ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
|
img->ibuf->rect );
|
3D view orbit option: Around Active
This fixes the active object in place when orbiting the view.
Choppy 15fps demo can be seen there: http://www.elysiun.com/~theeth/bf/around_active.html
Image Memory Grabage Collection
This adds memory handling to the image code. An image is tagged each time it is used.
During a collection cycle (frequency of cycles is user defined), if an image is older
than a user defined limit, its buffer gets deallocated. This also applies to gl memory buffers.
Images that are loading in GL memory needs to go through two time outs before being fully deallocated: the first time out deallocated the gl memorry, the second the buffer in ram.
Notes:
Image buffer loaded from python gets tagged as permanent upon load. That tag is removed when python stops using the image.
I might have missed some tagging spots, especially in the rendering pipeline. Someone with more knowledge about this code should check to be careful.
Tagging is done on every access, for rendering, this will probably be a performance hit. A scheme should be developped to only tag when the rendering is completed.
Collecting is called in draw_object, most likely not the best place to do it.
Safe from undo, since using undo deallocates memory anyway (like when loading a blend file with one currently opened)
Userpref DNA changes:
I've changed a couple of flagging variables from short to int. Some because they needed more space, others to keep SDNA happy.
Info window changes:
I've grouped a couple of buttons in aligned blocks and changed the color of mutually exclusive options to make them clearer.
Matt didn't do any changes on that in tuhopuu, so hopefully I'm not stepping on anyone's feet with this.
Also changed double constants into floats with f in a couple of places (mostly space.c) to make compiler happier.
2005-07-06 00:33:41 +00:00
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
/* raise the nocollect flag,
|
|
|
|
|
image is not available for garbage collection
|
3D view orbit option: Around Active
This fixes the active object in place when orbiting the view.
Choppy 15fps demo can be seen there: http://www.elysiun.com/~theeth/bf/around_active.html
Image Memory Grabage Collection
This adds memory handling to the image code. An image is tagged each time it is used.
During a collection cycle (frequency of cycles is user defined), if an image is older
than a user defined limit, its buffer gets deallocated. This also applies to gl memory buffers.
Images that are loading in GL memory needs to go through two time outs before being fully deallocated: the first time out deallocated the gl memorry, the second the buffer in ram.
Notes:
Image buffer loaded from python gets tagged as permanent upon load. That tag is removed when python stops using the image.
I might have missed some tagging spots, especially in the rendering pipeline. Someone with more knowledge about this code should check to be careful.
Tagging is done on every access, for rendering, this will probably be a performance hit. A scheme should be developped to only tag when the rendering is completed.
Collecting is called in draw_object, most likely not the best place to do it.
Safe from undo, since using undo deallocates memory anyway (like when loading a blend file with one currently opened)
Userpref DNA changes:
I've changed a couple of flagging variables from short to int. Some because they needed more space, others to keep SDNA happy.
Info window changes:
I've grouped a couple of buttons in aligned blocks and changed the color of mutually exclusive options to make them clearer.
Matt didn't do any changes on that in tuhopuu, so hopefully I'm not stepping on anyone's feet with this.
Also changed double constants into floats with f in a couple of places (mostly space.c) to make compiler happier.
2005-07-06 00:33:41 +00:00
|
|
|
(python GL might use it directly)
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
*/
|
3D view orbit option: Around Active
This fixes the active object in place when orbiting the view.
Choppy 15fps demo can be seen there: http://www.elysiun.com/~theeth/bf/around_active.html
Image Memory Grabage Collection
This adds memory handling to the image code. An image is tagged each time it is used.
During a collection cycle (frequency of cycles is user defined), if an image is older
than a user defined limit, its buffer gets deallocated. This also applies to gl memory buffers.
Images that are loading in GL memory needs to go through two time outs before being fully deallocated: the first time out deallocated the gl memorry, the second the buffer in ram.
Notes:
Image buffer loaded from python gets tagged as permanent upon load. That tag is removed when python stops using the image.
I might have missed some tagging spots, especially in the rendering pipeline. Someone with more knowledge about this code should check to be careful.
Tagging is done on every access, for rendering, this will probably be a performance hit. A scheme should be developped to only tag when the rendering is completed.
Collecting is called in draw_object, most likely not the best place to do it.
Safe from undo, since using undo deallocates memory anyway (like when loading a blend file with one currently opened)
Userpref DNA changes:
I've changed a couple of flagging variables from short to int. Some because they needed more space, others to keep SDNA happy.
Info window changes:
I've grouped a couple of buttons in aligned blocks and changed the color of mutually exclusive options to make them clearer.
Matt didn't do any changes on that in tuhopuu, so hopefully I'm not stepping on anyone's feet with this.
Also changed double constants into floats with f in a couple of places (mostly space.c) to make compiler happier.
2005-07-06 00:33:41 +00:00
|
|
|
img->flag |= IMA_NOCOLLECT;
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return PyLong_FromUnsignedLong( img->bindcode );
|
- Blender: added option 'scriptsdir' to Blender.Get();
- small updates to the docs;
- Object: small fix to getMatrix: check during_script() to avoid undesired loops; added old behavior (pre 2.34) as option: .getMatrix('oldlocal');
- tentative fix for bug #1275: scene REDRAW scriptlinks were not being executed (the call to do so was missing):
http://projects.blender.org/tracker/index.php?func=detail&aid=1275&group_id=9&atid=125
added the call in drawview.c, in drawview3dspace(). This causes the scriptlink to be called for each visible view3d, but that's what happens with object redraw scriptlinks, too. Anyway, this is still a test. The place was chosen based on the idea that a scene redraw scriptlink is like an object redraw one, but for all objs in the scene at once.
- Window.Theme: new submodule, to get/set theme options in Blender;
- Added the script save_theme.py (Help menu for now), to save the current theme in Blender as an executable script (currently shown in the Scripts->Misc menu).
There's more work to do for themes, like defining a proper place for them in the interface, adding documentation (for now the added script and the ones it generates can give a pretty good idea of how to use the new module), probably extending themes to support SpaceScript and so on.
2004-09-21 05:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setName( BPy_Image * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-05-25 10:36:58 +00:00
|
|
|
char *name;
|
|
|
|
|
char buf[21];
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "s", &name ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument" ) );
|
|
|
|
|
|
|
|
|
|
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
|
|
|
|
|
|
|
|
|
|
rename_id( &self->image->id, buf );
|
2004-05-25 10:36:58 +00:00
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
Py_RETURN_NONE;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-09 05:19:24 +00:00
|
|
|
static PyObject *Image_setFilename( BPy_Image * self, PyObject * args )
|
|
|
|
|
{
|
|
|
|
|
char *name;
|
2005-02-09 15:53:35 +00:00
|
|
|
int namelen = 0;
|
2005-02-09 05:19:24 +00:00
|
|
|
|
2005-02-09 15:53:35 +00:00
|
|
|
/* max len is FILE_MAXDIR = 160 chars like done in DNA_image_types.h */
|
|
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "s#", &name, &namelen ) )
|
2005-02-09 05:19:24 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
2005-04-30 19:30:35 +00:00
|
|
|
"expected a string argument" ) );
|
2005-02-09 05:19:24 +00:00
|
|
|
|
2005-04-30 19:30:35 +00:00
|
|
|
if( namelen >= FILE_MAXDIR )
|
2005-02-09 15:53:35 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
2005-04-30 19:30:35 +00:00
|
|
|
"string argument is limited to 160 chars at most" ) );
|
2005-02-09 05:19:24 +00:00
|
|
|
|
2005-04-30 19:30:35 +00:00
|
|
|
PyOS_snprintf( self->image->name, FILE_MAXDIR * sizeof( char ), "%s",
|
|
|
|
|
name );
|
2005-02-09 05:19:24 +00:00
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
Py_RETURN_NONE;
|
2005-02-09 05:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setXRep( BPy_Image * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-05-25 10:36:58 +00:00
|
|
|
short value;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "h", &value ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument in [1,16]" ) );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2005-08-21 15:00:17 +00:00
|
|
|
if( value >= EXPP_IMAGE_REP_MIN && value <= EXPP_IMAGE_REP_MAX )
|
2004-05-25 10:36:58 +00:00
|
|
|
self->image->xrep = value;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"expected int argument in [1,16]" ) );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
Py_RETURN_NONE;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_setYRep( BPy_Image * self, PyObject * args )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-05-25 10:36:58 +00:00
|
|
|
short value;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "h", &value ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument in [1,16]" ) );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2005-08-21 15:00:17 +00:00
|
|
|
if( value >= EXPP_IMAGE_REP_MIN && value <= EXPP_IMAGE_REP_MAX )
|
2004-05-25 10:36:58 +00:00
|
|
|
self->image->yrep = value;
|
|
|
|
|
else
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"expected int argument in [1,16]" ) );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
Patch #2758 Update of image module.
New Image methods from Austin Benesh:
- getPixelI(x, y)
- getMinXY()
- setPixelF(x, y, [r, g, b, a])
- setPixelI(x, y, [r, g, b, a])
- save()
sorry for the delay.
Thanks.
2005-08-10 17:50:18 +00:00
|
|
|
Py_RETURN_NONE;
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-14 03:27:35 +00:00
|
|
|
|
|
|
|
|
static PyObject *Image_setStart( BPy_Image * self, PyObject * args )
|
|
|
|
|
{
|
|
|
|
|
short value;
|
|
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "h", &value ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument in [0,128]" ) );
|
|
|
|
|
|
|
|
|
|
if( value >= 0 && value <= 128 )
|
|
|
|
|
self->image->twsta = value;
|
|
|
|
|
else
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"expected int argument in [0,128]" ) );
|
|
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static PyObject *Image_setEnd( BPy_Image * self, PyObject * args )
|
|
|
|
|
{
|
|
|
|
|
short value;
|
|
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "h", &value ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument in [0,128]" ) );
|
|
|
|
|
|
|
|
|
|
if( value >= 0 && value <= 128 )
|
|
|
|
|
self->image->twend = value;
|
|
|
|
|
else
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"expected int argument in [0,128]" ) );
|
|
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *Image_setSpeed( BPy_Image * self, PyObject * args )
|
|
|
|
|
{
|
|
|
|
|
short value;
|
|
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "h", &value ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected int argument in [0,128]" ) );
|
|
|
|
|
|
|
|
|
|
if( value >= 1 && value <= 100 )
|
|
|
|
|
self->image->animspeed = value;
|
|
|
|
|
else
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_ValueError,
|
|
|
|
|
"expected int argument in [0,128]" ) );
|
|
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_getAttr */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Image type. It is */
|
|
|
|
|
/* the function that accesses BPy_Image member variables and */
|
|
|
|
|
/* methods. */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_getAttr( BPy_Image * self, char *name )
|
2003-05-08 03:06:46 +00:00
|
|
|
{
|
2004-05-25 10:36:58 +00:00
|
|
|
PyObject *attr = Py_None;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
|
attr = PyString_FromString( self->image->id.name + 2 );
|
|
|
|
|
else if( strcmp( name, "filename" ) == 0 )
|
|
|
|
|
attr = PyString_FromString( self->image->name );
|
|
|
|
|
else if( strcmp( name, "size" ) == 0 )
|
|
|
|
|
attr = Image_getSize( self );
|
|
|
|
|
else if( strcmp( name, "depth" ) == 0 )
|
|
|
|
|
attr = Image_getDepth( self );
|
|
|
|
|
else if( strcmp( name, "xrep" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->xrep );
|
|
|
|
|
else if( strcmp( name, "yrep" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->yrep );
|
2005-12-14 03:27:35 +00:00
|
|
|
else if( strcmp( name, "start" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->twsta );
|
|
|
|
|
else if( strcmp( name, "end" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->twend );
|
|
|
|
|
else if( strcmp( name, "speed" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->animspeed );
|
|
|
|
|
else if( strcmp( name, "packed" ) == 0 ) {
|
|
|
|
|
if (self->image->packedfile) {
|
2005-12-18 08:47:55 +00:00
|
|
|
attr = EXPP_incr_ret_True();
|
2005-12-14 03:27:35 +00:00
|
|
|
} else {
|
2005-12-18 08:47:55 +00:00
|
|
|
attr = EXPP_incr_ret_False();
|
2005-12-14 03:27:35 +00:00
|
|
|
}
|
|
|
|
|
} else if( strcmp( name, "bindcode" ) == 0 )
|
2004-09-25 20:30:40 +00:00
|
|
|
attr = PyInt_FromLong( self->image->bindcode );
|
2005-01-13 03:04:12 +00:00
|
|
|
else if( strcmp( name, "users" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->image->id.us );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( strcmp( name, "__members__" ) == 0 )
|
2005-12-14 03:27:35 +00:00
|
|
|
attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s]",
|
2004-09-25 20:30:40 +00:00
|
|
|
"name", "filename", "size", "depth",
|
2005-12-14 03:27:35 +00:00
|
|
|
"xrep", "yrep", "start", "end",
|
|
|
|
|
"speed", "packed",
|
|
|
|
|
"bindcode", "users" );
|
2004-09-25 20:30:40 +00:00
|
|
|
|
|
|
|
|
if( !attr )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyObject" ) );
|
|
|
|
|
|
|
|
|
|
if( attr != Py_None )
|
|
|
|
|
return attr; /* attribute found, return its value */
|
2004-05-25 10:36:58 +00:00
|
|
|
|
|
|
|
|
/* not an attribute, search the methods table */
|
2004-09-25 20:30:40 +00:00
|
|
|
return Py_FindMethod( BPy_Image_methods, ( PyObject * ) self, name );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_setAttr */
|
2003-06-28 07:38:21 +00:00
|
|
|
/* Description: This is a callback function for the BPy_Image type. It is the*/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* function that changes Image object members values. If this */
|
|
|
|
|
/* data is linked to a Blender Image, it also gets updated. */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Image_setAttr( BPy_Image * self, char *name, PyObject * value )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *valtuple;
|
2004-05-25 10:36:58 +00:00
|
|
|
PyObject *error = NULL;
|
2003-04-08 19:54:14 +00:00
|
|
|
|
2004-05-25 10:36:58 +00:00
|
|
|
/* We're playing a trick on the Python API users here. Even if they use
|
2003-04-08 19:54:14 +00:00
|
|
|
* Image.member = val instead of Image.setMember(value), we end up using the
|
|
|
|
|
* function anyway, since it already has error checking, clamps to the right
|
|
|
|
|
* interval and updates the Blender Image structure when necessary. */
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
valtuple = Py_BuildValue( "(O)", value ); /*the set* functions expect a tuple */
|
|
|
|
|
|
|
|
|
|
if( !valtuple )
|
|
|
|
|
return EXPP_ReturnIntError( PyExc_MemoryError,
|
|
|
|
|
"ImageSetAttr: couldn't create PyTuple" );
|
|
|
|
|
|
|
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
|
error = Image_setName( self, valtuple );
|
2005-02-09 05:19:24 +00:00
|
|
|
if( strcmp( name, "filename" ) == 0 )
|
2005-04-30 19:30:35 +00:00
|
|
|
error = Image_setFilename( self, valtuple );
|
2004-09-25 20:30:40 +00:00
|
|
|
else if( strcmp( name, "xrep" ) == 0 )
|
|
|
|
|
error = Image_setXRep( self, valtuple );
|
|
|
|
|
else if( strcmp( name, "yrep" ) == 0 )
|
|
|
|
|
error = Image_setYRep( self, valtuple );
|
2005-12-14 03:27:35 +00:00
|
|
|
else if( strcmp( name, "start" ) == 0 )
|
|
|
|
|
error = Image_setStart( self, valtuple );
|
|
|
|
|
else if( strcmp( name, "end" ) == 0 )
|
|
|
|
|
error = Image_setEnd( self, valtuple );
|
|
|
|
|
else if( strcmp( name, "speed" ) == 0 )
|
|
|
|
|
error = Image_setSpeed( self, valtuple );
|
2004-09-25 20:30:40 +00:00
|
|
|
else { /* Error: no such member in the Image object structure */
|
2005-06-17 05:37:24 +00:00
|
|
|
/*Py_DECREF( value ); borrowed ref, no need to decref */
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( valtuple );
|
|
|
|
|
return ( EXPP_ReturnIntError( PyExc_KeyError,
|
|
|
|
|
"attribute not found or immutable" ) );
|
2004-05-25 10:36:58 +00:00
|
|
|
}
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( valtuple );
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( error != Py_None )
|
|
|
|
|
return -1;
|
2003-05-08 03:06:46 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( Py_None ); /* incref'ed by the called set* function */
|
|
|
|
|
return 0; /* normal exit */
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_compare */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Image type. It */
|
|
|
|
|
/* compares two Image_Type objects. Only the "==" and "!=" */
|
|
|
|
|
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
|
|
|
|
/* they don't point to the same Blender Image struct. */
|
|
|
|
|
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
2003-05-21 19:58:31 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Image_compare( BPy_Image * a, BPy_Image * b )
|
2003-05-21 19:58:31 +00:00
|
|
|
{
|
|
|
|
|
Image *pa = a->image, *pb = b->image;
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( pa == pb ) ? 0 : -1;
|
2003-05-21 19:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
/* Function: Image_repr */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Image type. It */
|
|
|
|
|
/* builds a meaninful string to represent image objects. */
|
2003-04-08 19:54:14 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Image_repr( BPy_Image * self )
|
2003-04-08 19:54:14 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
return PyString_FromFormat( "[Image \"%s\"]",
|
|
|
|
|
self->image->id.name + 2 );
|
2003-04-08 19:54:14 +00:00
|
|
|
}
|