| 
									
										
										
										
											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, | 
					
						
							|  |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is a new part of Blender. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Willian P. Germano | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | #include <BKE_main.h>
 | 
					
						
							|  |  |  | #include <BKE_global.h>
 | 
					
						
							|  |  |  | #include <BKE_library.h>
 | 
					
						
							|  |  |  | #include <BKE_image.h>
 | 
					
						
							|  |  |  | #include <BLI_blenlib.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "gen_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | #include "Image.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | /* Python C_Image defaults:                                                  */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | #define EXPP_IMAGE_REP      1
 | 
					
						
							|  |  |  | #define EXPP_IMAGE_REP_MIN  1
 | 
					
						
							|  |  |  | #define EXPP_IMAGE_REP_MAX 16
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /************************/ | 
					
						
							|  |  |  | /*** The Image Module ***/ | 
					
						
							|  |  |  | /************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python API function prototypes for the Image module.                      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *M_Image_New (PyObject *self, PyObject *args, | 
					
						
							|  |  |  |                 PyObject *keywords); | 
					
						
							|  |  |  | static PyObject *M_Image_Get (PyObject *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *M_Image_Load (PyObject *self, PyObject *args); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* The following string definitions are used for documentation strings.      */ | 
					
						
							|  |  |  | /* In Python these will be written to the console when doing a               */ | 
					
						
							|  |  |  | /* Blender.Image.__doc__                                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static char M_Image_doc[] = | 
					
						
							|  |  |  | "The Blender Image module\n\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char M_Image_New_doc[] = | 
					
						
							|  |  |  | "() - return a new Image object -- unimplemented"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char M_Image_Get_doc[] = | 
					
						
							|  |  |  | "(name) - return the image with the name 'name', \
 | 
					
						
							|  |  |  | returns None if not found.\n If 'name' is not specified, \ | 
					
						
							|  |  |  | it returns a list of all images in the\ncurrent scene."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char M_Image_Load_doc[] = | 
					
						
							|  |  |  | "(filename) - return image from file filename as Image Object, \
 | 
					
						
							|  |  |  | returns None if not found.\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python method structure definition for Blender.Image module:              */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | struct PyMethodDef M_Image_methods[] = { | 
					
						
							|  |  |  |   {"New",(PyCFunction)M_Image_New, METH_VARARGS|METH_KEYWORDS, | 
					
						
							|  |  |  |           M_Image_New_doc}, | 
					
						
							|  |  |  |   {"Get",         M_Image_Get,         METH_VARARGS, M_Image_Get_doc}, | 
					
						
							|  |  |  |   {"get",         M_Image_Get,         METH_VARARGS, M_Image_Get_doc}, | 
					
						
							|  |  |  |   {"Load",        M_Image_Load,        METH_VARARGS, M_Image_Load_doc}, | 
					
						
							|  |  |  |   {NULL, NULL, 0, NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:              M_Image_New                                        */ | 
					
						
							|  |  |  | /* Python equivalent:     Blender.Image.New                                  */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *M_Image_New(PyObject *self, PyObject *args, PyObject *keywords) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   printf ("In Image_New() - unimplemented in 2.25\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +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
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *M_Image_Get(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |   char  *name = NULL; | 
					
						
							|  |  |  |   Image *img_iter; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +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
										 |  |  | 
 | 
					
						
							|  |  |  |   img_iter = G.main->image.first; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 	if (name) { /* (name) - Search image by name */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     C_Image *wanted_image = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ((img_iter) && (wanted_image == NULL)) { | 
					
						
							|  |  |  |       if (strcmp (name, img_iter->id.name+2) == 0) { | 
					
						
							|  |  |  |         wanted_image = (C_Image *)PyObject_NEW(C_Image, &Image_Type); | 
					
						
							|  |  |  | 				if (wanted_image) wanted_image->image = img_iter; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       img_iter = img_iter->id.next; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     if (wanted_image == NULL) { /* Requested image doesn't exist */ | 
					
						
							|  |  |  |       char error_msg[64]; | 
					
						
							|  |  |  |       PyOS_snprintf(error_msg, sizeof(error_msg), | 
					
						
							|  |  |  |                       "Image \"%s\" not found", name); | 
					
						
							|  |  |  |       return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     return (PyObject *)wanted_image; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	else { /* () - return a list of all images in the scene */ | 
					
						
							|  |  |  |     int index = 0; | 
					
						
							|  |  |  |     PyObject *img_list, *pystr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     img_list = PyList_New (BLI_countlist (&(G.main->image))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (img_list == NULL) | 
					
						
							|  |  |  |       return (PythonReturnErrorObject (PyExc_MemoryError, | 
					
						
							|  |  |  |               "couldn't create PyList")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		while (img_iter) { | 
					
						
							|  |  |  |       pystr = PyString_FromString (img_iter->id.name+2); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 			if (!pystr) | 
					
						
							|  |  |  | 				return (PythonReturnErrorObject (PyExc_MemoryError, | 
					
						
							|  |  |  | 									"couldn't create PyString")); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 			PyList_SET_ITEM (img_list, index, pystr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       img_iter = img_iter->id.next; | 
					
						
							|  |  |  |       index++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return (img_list); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +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-04-08 19:54:14 +00:00
										 |  |  | static PyObject *M_Image_Load(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |   char    *fname; | 
					
						
							|  |  |  |   Image   *img_ptr; | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   C_Image *img; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "s", &fname)) | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |             "expected string argument")); | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   img = (C_Image *)PyObject_NEW(C_Image, &Image_Type); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!img) | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  |             "couldn't create PyObject Image_Type")); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   img->image = img_ptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return (PyObject *)img; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:              M_Image_Init                                      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyObject *M_Image_Init (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-09 04:34:40 +00:00
										 |  |  |   PyObject  *submodule; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-02 20:15:50 +00:00
										 |  |  |   Image_Type.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-09 04:34:40 +00:00
										 |  |  |   submodule = Py_InitModule3("Blender.Image", M_Image_methods, M_Image_doc); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-09 04:34:40 +00:00
										 |  |  |   return (submodule); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | /************************/ | 
					
						
							|  |  |  | /*** The Image PyType ***/ | 
					
						
							|  |  |  | /************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python C_Image methods declarations:                                      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *Image_getName(C_Image *self); | 
					
						
							|  |  |  | static PyObject *Image_getFilename(C_Image *self); | 
					
						
							|  |  |  | static PyObject *Image_setName(C_Image *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *Image_setXRep(C_Image *self, PyObject *args); | 
					
						
							|  |  |  | static PyObject *Image_setYRep(C_Image *self, PyObject *args); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python C_Image methods table:                                             */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyMethodDef C_Image_methods[] = { | 
					
						
							|  |  |  |  /* name, method, flags, doc */ | 
					
						
							|  |  |  |   {"getName", (PyCFunction)Image_getName, METH_NOARGS, | 
					
						
							|  |  |  |           "() - Return Image Data name"}, | 
					
						
							|  |  |  |   {"getFilename", (PyCFunction)Image_getFilename, METH_VARARGS, | 
					
						
							|  |  |  |           "() - Return Image Data filename"}, | 
					
						
							|  |  |  |   {"setName", (PyCFunction)Image_setName, METH_VARARGS, | 
					
						
							|  |  |  |           "(str) - Change Image Data name"}, | 
					
						
							|  |  |  |   {"setXRep", (PyCFunction)Image_setXRep, METH_VARARGS, | 
					
						
							|  |  |  |           "(int) - Change Image Data x repetition value"}, | 
					
						
							|  |  |  |   {"setYRep", (PyCFunction)Image_setYRep, METH_VARARGS, | 
					
						
							|  |  |  |           "(int) - Change Image Data y repetition value"}, | 
					
						
							|  |  |  |   {0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python Image_Type callback function prototypes:                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static void Image_Dealloc (C_Image *self); | 
					
						
							|  |  |  | static int Image_SetAttr (C_Image *self, char *name, PyObject *v); | 
					
						
							|  |  |  | static int Image_Compare (C_Image *a, C_Image *b); | 
					
						
							|  |  |  | static int Image_Print (C_Image *self, FILE *fp, int flags); | 
					
						
							|  |  |  | static PyObject *Image_GetAttr (C_Image *self, char *name); | 
					
						
							|  |  |  | static PyObject *Image_Repr (C_Image *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python Image_Type structure definition:                                   */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyTypeObject Image_Type = | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-02 20:15:50 +00:00
										 |  |  |   PyObject_HEAD_INIT(NULL) | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  |   0,                                     /* ob_size */ | 
					
						
							|  |  |  |   "Image",                               /* tp_name */ | 
					
						
							|  |  |  |   sizeof (C_Image),                      /* tp_basicsize */ | 
					
						
							|  |  |  |   0,                                     /* tp_itemsize */ | 
					
						
							|  |  |  |   /* methods */ | 
					
						
							|  |  |  |   (destructor)Image_Dealloc,             /* tp_dealloc */ | 
					
						
							|  |  |  |   (printfunc)Image_Print,                /* 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, | 
					
						
							|  |  |  |   C_Image_methods,                       /* tp_methods */ | 
					
						
							|  |  |  |   0,                                     /* tp_members */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    ImageDealloc                                                 */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Image type. It is      */ | 
					
						
							|  |  |  | /*              the destructor function.                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static void Image_Dealloc (C_Image *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject_DEL (self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    Image_CreatePyObject                                         */ | 
					
						
							|  |  |  | /* Description: This function will create a new C_Image from an existing     */ | 
					
						
							|  |  |  | /*              Blender image structure.                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyObject *Image_CreatePyObject (Image *image) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	C_Image *py_img; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	py_img = (C_Image *)PyObject_NEW (C_Image, &Image_Type); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!py_img) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  | 						"couldn't create C_Image object"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	py_img->image = image; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (PyObject *)py_img; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    Image_CheckPyObject                                          */ | 
					
						
							|  |  |  | /* Description: This function returns true when the given PyObject is of the */ | 
					
						
							|  |  |  | /*              type Image. Otherwise it will return false.                  */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | int Image_CheckPyObject (PyObject *pyobj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (pyobj->ob_type == &Image_Type); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python C_Image methods:                                                  */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *Image_getName(C_Image *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = PyString_FromString(self->image->id.name+2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return (EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |           "couldn't get Image.name attribute")); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Image_getFilename(C_Image *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *attr = PyString_FromString(self->image->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (attr) return attr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return (EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							|  |  |  |           "couldn't get Image.filename attribute")); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  | static PyObject *Image_setName(C_Image *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   char *name; | 
					
						
							|  |  |  |   char buf[21]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "s", &name)) | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |             "expected string argument")); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   PyOS_snprintf(buf, sizeof(buf), "%s", name); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   rename_id(&self->image->id, buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Image_setXRep(C_Image *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   short value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "h", &value)) | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |             "expected int argument in [1,16]")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX) | 
					
						
							|  |  |  |     self->image->xrep = value; | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |             "expected int argument in [1,16]")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Image_setYRep(C_Image *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   short value; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "h", &value)) | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |             "expected int argument in [1,16]")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX) | 
					
						
							|  |  |  |     self->image->yrep = value; | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2003-05-13 01:54:28 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |             "expected int argument in [1,16]")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | /* Function:    Image_GetAttr                                                */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Image type. It is      */ | 
					
						
							|  |  |  | /*              the function that accesses C_Image member variables and      */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /*              methods.                                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | static PyObject *Image_GetAttr (C_Image *self, char *name) | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PyObject *attr = Py_None; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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, "xrep") == 0) | 
					
						
							|  |  |  |     attr = PyInt_FromLong(self->image->xrep); | 
					
						
							|  |  |  |   else if (strcmp(name, "yrep") == 0) | 
					
						
							|  |  |  |     attr = PyInt_FromLong(self->image->yrep); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   else if (strcmp(name, "__members__") == 0) | 
					
						
							|  |  |  |     attr = Py_BuildValue("[s,s,s,s]", | 
					
						
							|  |  |  |                     "name", "filename", "xrep", "yrep"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!attr) | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  |                             "couldn't create PyObject")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (attr != Py_None) return attr; /* attribute found, return its value */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* not an attribute, search the methods table */ | 
					
						
							|  |  |  |   return Py_FindMethod(C_Image_methods, (PyObject *)self, name); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | /* Function:    Image_SetAttr                                                */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Image type. It is the  */ | 
					
						
							|  |  |  | /*              function that changes Image Data members values. If this     */ | 
					
						
							|  |  |  | /*              data is linked to a Blender Image, it also gets updated.     */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | static int Image_SetAttr (C_Image *self, char *name, PyObject *value) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   PyObject *valtuple;  | 
					
						
							|  |  |  |   PyObject *error = NULL; | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* We're playing a trick on the Python API users here.  Even if they use
 | 
					
						
							|  |  |  |  * 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. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-09 04:01:48 +00:00
										 |  |  |   valtuple = Py_BuildValue("(O)", value); /*the set* functions expect a tuple*/ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (!valtuple) | 
					
						
							|  |  |  |     return EXPP_ReturnIntError(PyExc_MemoryError, | 
					
						
							|  |  |  |                   "ImageSetAttr: couldn't create PyTuple"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   if (strcmp (name, "name") == 0) | 
					
						
							| 
									
										
										
										
											2003-05-17 04:29:49 +00:00
										 |  |  |     error = Image_setName (self, valtuple); | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   else if (strcmp (name, "xrep") == 0) | 
					
						
							|  |  |  |     error = Image_setXRep (self, valtuple); | 
					
						
							|  |  |  |   else if (strcmp (name, "yrep") == 0) | 
					
						
							|  |  |  |     error = Image_setYRep (self, valtuple); | 
					
						
							|  |  |  |   else { /* Error: no such member in the Image Data structure */ | 
					
						
							|  |  |  |     Py_DECREF(value); | 
					
						
							|  |  |  |     Py_DECREF(valtuple); | 
					
						
							|  |  |  |     return (EXPP_ReturnIntError (PyExc_KeyError, | 
					
						
							|  |  |  |             "attribute not found or immutable")); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_DECREF(valtuple); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (error != Py_None) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_DECREF(Py_None); /* incref'ed by the called set* function */ | 
					
						
							|  |  |  |   return 0; /* normal exit */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | /* Function:    Image_Compare                                                */ | 
					
						
							| 
									
										
										
										
											2003-05-21 19:58:31 +00:00
										 |  |  | /* Description: This is a callback function for the C_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-31 04:43:10 +00:00
										 |  |  | static int Image_Compare (C_Image *a, C_Image *b) | 
					
						
							| 
									
										
										
										
											2003-05-21 19:58:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Image *pa = a->image, *pb = b->image; | 
					
						
							|  |  |  | 	return (pa == pb) ? 0:-1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | /* Function:    Image_Print                                                  */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Image type. It         */ | 
					
						
							|  |  |  | /*              builds a meaninful string to 'print' image objects.          */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | static int Image_Print(C_Image *self, FILE *fp, int flags) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | {  | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   fprintf(fp, "[Image \"%s\"]", self->image->id.name+2); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | /* Function:    Image_Repr                                                   */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Image type. It         */ | 
					
						
							|  |  |  | /*              builds a meaninful string to represent image objects.        */ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-05-31 04:43:10 +00:00
										 |  |  | static PyObject *Image_Repr (C_Image *self) | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:06:46 +00:00
										 |  |  |   return PyString_FromString(self->image->id.name+2); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | } |