Fixing a blenderplayer compile error reported by Meino Christian Cramer:
[blender-staging.git] / source / blender / python / api2_2x / Image.c
1 /* 
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * This is a new part of Blender.
27  *
28  * Contributor(s): Willian P. Germano, Campbell Barton
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31 */
32
33 #include <BKE_main.h>
34 #include <BKE_global.h>
35 #include <BKE_library.h>
36 #include <BKE_image.h>
37 #include <BIF_drawimage.h>
38 #include <BLI_blenlib.h>
39 #include <IMB_imbuf_types.h> /* for the IB_rect define */
40 #include "gen_utils.h"
41
42 #include "Image.h"
43
44 /*****************************************************************************/
45 /* Python BPy_Image defaults:                                                                                                                                                                                            */
46 /*****************************************************************************/
47 #define EXPP_IMAGE_REP                  1
48 #define EXPP_IMAGE_REP_MIN      1
49 #define EXPP_IMAGE_REP_MAX 16
50
51
52 /************************/
53 /*** The Image Module ***/
54 /************************/
55
56 /*****************************************************************************/
57 /* Python API function prototypes for the Image module.                                                                                  */
58 /*****************************************************************************/
59 static PyObject *M_Image_New (PyObject *self, PyObject *args,
60                                                                 PyObject *keywords);
61 static PyObject *M_Image_Get (PyObject *self, PyObject *args);
62 static PyObject *M_Image_Load (PyObject *self, PyObject *args);
63
64 /*****************************************************************************/
65 /* The following string definitions are used for documentation strings.                  */
66 /* In Python these will be written to the console when doing a                                                   */
67 /* Blender.Image.__doc__                                                                                                                                                                                                                 */
68 /*****************************************************************************/
69 static char M_Image_doc[] =
70 "The Blender Image module\n\n";
71
72 static char M_Image_New_doc[] =
73 "() - return a new Image object -- unimplemented";
74
75 static char M_Image_Get_doc[] =
76 "(name) - return the image with the name 'name', \
77 returns None if not found.\n If 'name' is not specified, \
78 it returns a list of all images in the\ncurrent scene.";
79
80 static char M_Image_Load_doc[] =
81 "(filename) - return image from file filename as Image Object, \
82 returns None if not found.\n";
83
84 /*****************************************************************************/
85 /* Python method structure definition for Blender.Image module:                                                  */
86 /*****************************************************************************/
87 struct PyMethodDef M_Image_methods[] = {
88         {"New",(PyCFunction)M_Image_New, METH_VARARGS|METH_KEYWORDS,
89                                         M_Image_New_doc},
90         {"Get",                                 M_Image_Get,                             METH_VARARGS, M_Image_Get_doc},
91         {"get",                                 M_Image_Get,                             METH_VARARGS, M_Image_Get_doc},
92         {"Load",                                M_Image_Load,                            METH_VARARGS, M_Image_Load_doc},
93         {NULL, NULL, 0, NULL}
94 };
95
96 /*****************************************************************************/
97 /* Function:                                                    M_Image_New                                                                                                                                                              */
98 /* Python equivalent:                   Blender.Image.New                                                                                                                                        */
99 /*****************************************************************************/
100 static PyObject *M_Image_New(PyObject *self, PyObject *args, PyObject *keywords)
101 {
102         printf ("In Image_New() - unimplemented in 2.25\n");
103
104         Py_INCREF(Py_None);
105         return Py_None;
106 }
107
108 /*****************************************************************************/
109 /* Function:                                                    M_Image_Get                                                                                                                                                              */
110 /* Python equivalent:                   Blender.Image.Get                                                                                                                                        */
111 /* Description:                                         Receives a string and returns the image object           */
112 /*                                                                                              whose name matches the string.  If no argument is  */
113 /*                                                                                              passed in, a list of all image names in the                              */
114 /*                                                                                              current scene is returned.                                                                                               */
115 /*****************************************************************************/
116 static PyObject *M_Image_Get(PyObject *self, PyObject *args)
117 {
118         char    *name = NULL;
119         Image *img_iter;
120
121         if (!PyArg_ParseTuple(args, "|s", &name))
122                 return (EXPP_ReturnPyObjError (PyExc_TypeError,
123                                                 "expected string argument (or nothing)"));
124
125         img_iter = G.main->image.first;
126
127         if (name) { /* (name) - Search image by name */
128
129                 BPy_Image *wanted_image = NULL;
130
131                 while ((img_iter) && (wanted_image == NULL)) {
132                         if (strcmp (name, img_iter->id.name+2) == 0) {
133                                 wanted_image = (BPy_Image *)PyObject_NEW(BPy_Image, &Image_Type);
134                                 if (wanted_image) wanted_image->image = img_iter;
135                         }
136                         img_iter = img_iter->id.next;
137                 }
138
139                 if (wanted_image == NULL) { /* Requested image doesn't exist */
140                         char error_msg[64];
141                         PyOS_snprintf(error_msg, sizeof(error_msg),
142                                                                                         "Image \"%s\" not found", name);
143                         return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
144                 }
145
146                 return (PyObject *)wanted_image;
147         }
148
149         else { /* () - return a list of all images in the scene */
150                 int index = 0;
151                 PyObject *img_list, *pyobj;
152
153                 img_list = PyList_New (BLI_countlist (&(G.main->image)));
154
155                 if (img_list == NULL)
156                         return (EXPP_ReturnPyObjError (PyExc_MemoryError,
157                                                         "couldn't create PyList"));
158
159                 while (img_iter) {
160                         pyobj = Image_CreatePyObject (img_iter);
161
162                         if (!pyobj)
163                                 return (EXPP_ReturnPyObjError (PyExc_MemoryError,
164                                                                         "couldn't create PyObject"));
165
166                         PyList_SET_ITEM (img_list, index, pyobj);
167
168                         img_iter = img_iter->id.next;
169                         index++;
170                 }
171
172                 return (img_list);
173         }
174 }
175
176 /*****************************************************************************/
177 /* Function:                                                    M_Image_Load                                                                                                                                                     */
178 /* Python equivalent:                   Blender.Image.Load                                                                                                                               */
179 /* Description:                                         Receives a string and returns the image object           */
180 /*                                                                                              whose filename matches the string.                                                               */
181 /*****************************************************************************/
182 static PyObject *M_Image_Load(PyObject *self, PyObject *args)
183 {
184         char            *fname;
185         Image           *img_ptr;
186         BPy_Image *img;
187
188         if (!PyArg_ParseTuple(args, "s", &fname))
189                 return (EXPP_ReturnPyObjError (PyExc_TypeError,
190                                                 "expected string argument"));
191
192         img = (BPy_Image *)PyObject_NEW(BPy_Image, &Image_Type);
193
194         if (!img)
195                 return (EXPP_ReturnPyObjError (PyExc_MemoryError,
196                                                 "couldn't create PyObject Image_Type"));
197
198         img_ptr = add_image(fname);
199         if (!img_ptr)
200                 return (EXPP_ReturnPyObjError (PyExc_IOError,
201                                                 "couldn't load image"));
202
203         img->image = img_ptr;
204
205         return (PyObject *)img;
206 }
207
208 /*****************************************************************************/
209 /* Function:                                                    Image_Init                                                                                                                                                               */
210 /*****************************************************************************/
211 PyObject *Image_Init (void)
212 {
213         PyObject        *submodule;
214
215         Image_Type.ob_type = &PyType_Type;
216
217         submodule = Py_InitModule3("Blender.Image", M_Image_methods, M_Image_doc);
218
219         return (submodule);
220 }
221
222 /************************/
223 /*** The Image PyType ***/
224 /************************/
225
226 /*****************************************************************************/
227 /* Python BPy_Image methods declarations:                                                                                                                                                */
228 /*****************************************************************************/
229 static PyObject *Image_getName(BPy_Image *self);
230 static PyObject *Image_getFilename(BPy_Image *self);
231 static PyObject *Image_getSize(BPy_Image *self);
232 static PyObject *Image_getDepth(BPy_Image *self);
233 static PyObject *Image_getXRep(BPy_Image *self);
234 static PyObject *Image_getYRep(BPy_Image *self);
235 static PyObject *Image_getBindCode(BPy_Image *self); 
236 static PyObject *Image_setName(BPy_Image *self, PyObject *args);
237 static PyObject *Image_setXRep(BPy_Image *self, PyObject *args);
238 static PyObject *Image_setYRep(BPy_Image *self, PyObject *args);
239 static PyObject *Image_reload(BPy_Image *self); /* by Campbell */
240
241 /*****************************************************************************/
242 /* Python BPy_Image methods table:                                                                                                                                                                       */
243 /*****************************************************************************/
244 static PyMethodDef BPy_Image_methods[] = {
245  /* name, method, flags, doc */
246         {"getName", (PyCFunction)Image_getName, METH_NOARGS,
247                         "() - Return Image object name"},
248         {"getFilename", (PyCFunction)Image_getFilename, METH_NOARGS,
249                         "() - Return Image object filename"},
250         {"getSize", (PyCFunction)Image_getSize, METH_NOARGS,
251                         "() - Return Image object [width, height] dimension in pixels"},
252         {"getDepth", (PyCFunction)Image_getDepth, METH_NOARGS,
253                         "() - Return Image object pixel depth"},
254         {"getXRep", (PyCFunction)Image_getXRep, METH_NOARGS,
255                         "() - Return Image object x repetition value"},
256         {"getYRep", (PyCFunction)Image_getYRep, METH_NOARGS,
257                         "() - Return Image object y repetition value"},
258         {"getBindCode", (PyCFunction)Image_getBindCode, METH_NOARGS,
259                         "() - Return Image object's bind code value"},                                                                                  
260         {"reload", (PyCFunction)Image_reload, METH_NOARGS,
261                         "() - Reload the image from the filesystem"},
262         {"setName", (PyCFunction)Image_setName, METH_VARARGS,
263                                         "(str) - Change Image object name"},
264         {"setXRep", (PyCFunction)Image_setXRep, METH_VARARGS,
265                                         "(int) - Change Image object x repetition value"},
266         {"setYRep", (PyCFunction)Image_setYRep, METH_VARARGS,
267                                         "(int) - Change Image object y repetition value"},
268         {NULL, NULL, 0, NULL}
269 };
270
271 /*****************************************************************************/
272 /* Python Image_Type callback function prototypes:                                                                                                       */
273 /*****************************************************************************/
274 static void Image_dealloc (BPy_Image *self);
275 static int Image_setAttr (BPy_Image *self, char *name, PyObject *v);
276 static int Image_compare (BPy_Image *a, BPy_Image *b);
277 static PyObject *Image_getAttr (BPy_Image *self, char *name);
278 static PyObject *Image_repr (BPy_Image *self);
279
280 /*****************************************************************************/
281 /* Python Image_Type structure definition:                                                                                                                                       */
282 /*****************************************************************************/
283 PyTypeObject Image_Type =
284 {
285         PyObject_HEAD_INIT(NULL)
286         0,                                                                                                                                               /* ob_size */
287         "Blender Image",                                                                                         /* tp_name */
288         sizeof (BPy_Image),                                                                              /* tp_basicsize */
289         0,                                                                                                                                               /* tp_itemsize */
290         /* methods */
291         (destructor)Image_dealloc,                                               /* tp_dealloc */
292         0,                                                                                                                                               /* tp_print */
293         (getattrfunc)Image_getAttr,                                              /* tp_getattr */
294         (setattrfunc)Image_setAttr,                                              /* tp_setattr */
295         (cmpfunc)Image_compare,                                                          /* tp_compare */
296         (reprfunc)Image_repr,                                                                    /* tp_repr */
297         0,                                                                                                                                               /* tp_as_number */
298         0,                                                                                                                                               /* tp_as_sequence */
299         0,                                                                                                                                               /* tp_as_mapping */
300         0,                                                                                                                                               /* tp_as_hash */
301         0,0,0,0,0,0,
302         0,                                                                                                                                               /* tp_doc */ 
303         0,0,0,0,0,0,
304         BPy_Image_methods,                                                                                       /* tp_methods */
305         0,                                                                                                                                               /* tp_members */
306 };
307
308 /*****************************************************************************/
309 /* Function:            Image_dealloc                                                                                                                                                                                            */
310 /* Description: This is a callback function for the BPy_Image type. It is                */
311 /*                                                      the destructor function.                                                                                                                                                 */
312 /*****************************************************************************/
313 static void Image_dealloc (BPy_Image *self)
314 {
315         PyObject_DEL (self);
316 }
317
318 /*****************************************************************************/
319 /* Function:            Image_CreatePyObject                                                                                                                                                             */
320 /* Description: This function will create a new BPy_Image from an existing       */
321 /*                                                      Blender image structure.                                                                                                                                                 */
322 /*****************************************************************************/
323 PyObject *Image_CreatePyObject (Image *image)
324 {
325         BPy_Image *py_img;
326
327         py_img = (BPy_Image *)PyObject_NEW (BPy_Image, &Image_Type);
328
329         if (!py_img)
330                 return EXPP_ReturnPyObjError (PyExc_MemoryError,
331                                                 "couldn't create BPy_Image object");
332
333         py_img->image = image;
334
335         return (PyObject *)py_img;
336 }
337
338 /*****************************************************************************/
339 /* Function:            Image_CheckPyObject                                                                                                                                                                      */
340 /* Description: This function returns true when the given PyObject is of the */
341 /*                                                      type Image. Otherwise it will return false.                                                                      */
342 /*****************************************************************************/
343 int Image_CheckPyObject (PyObject *pyobj)
344 {
345         return (pyobj->ob_type == &Image_Type);
346 }
347
348 /*****************************************************************************/
349 /* Function:            Image_FromPyObject                                                                                                                                                                       */
350 /* Description: Returns the Blender Image associated with this object                            */
351 /*****************************************************************************/
352 Image *Image_FromPyObject (PyObject *pyobj)
353 {
354         return ((BPy_Image *)pyobj)->image;
355 }
356
357 /*****************************************************************************/
358 /* Python BPy_Image methods:                                                                                                                                                                                             */
359 /*****************************************************************************/
360 static PyObject *Image_getName(BPy_Image *self)
361 {
362         PyObject *attr = PyString_FromString(self->image->id.name+2);
363
364         if (attr) return attr;
365
366         return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
367                                         "couldn't get Image.name attribute"));
368 }
369
370 static PyObject *Image_getFilename(BPy_Image *self)
371 {
372         PyObject *attr = PyString_FromString(self->image->name);
373
374         if (attr) return attr;
375
376         return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
377                                         "couldn't get Image.filename attribute"));
378 }
379
380 static PyObject *Image_getSize(BPy_Image *self)
381 {
382         PyObject *attr;
383         Image *image = self->image;
384
385         if (!image->ibuf) /* if no image data available */
386                 load_image(image, IB_rect, "", 0); /* loading it */
387
388         if (!image->ibuf) /* didn't work */
389                 return EXPP_ReturnPyObjError (PyExc_RuntimeError,
390                                         "couldn't load image data in Blender");
391
392         attr = Py_BuildValue("[hh]", image->ibuf->x, image->ibuf->y);
393
394         if (attr) return attr;
395
396         return EXPP_ReturnPyObjError (PyExc_RuntimeError,
397                                         "couldn't get Image.size attribute");
398 }
399
400 static PyObject *Image_getDepth(BPy_Image *self)
401 {
402         PyObject *attr;
403         Image *image = self->image;
404
405         if (!image->ibuf) /* if no image data available */
406                 load_image(image, IB_rect, "", 0); /* loading it */
407
408         if (!image->ibuf) /* didn't work */
409                 return EXPP_ReturnPyObjError (PyExc_RuntimeError,
410                                         "couldn't load image data in Blender");
411
412         attr = Py_BuildValue("h", image->ibuf->depth);
413
414         if (attr) return attr;
415
416         return EXPP_ReturnPyObjError (PyExc_RuntimeError,
417                                         "couldn't get Image.depth attribute");
418 }
419
420
421 static PyObject *Image_getXRep(BPy_Image *self)
422 {
423         PyObject *attr = PyInt_FromLong(self->image->xrep);
424
425         if (attr) return attr;
426
427         return EXPP_ReturnPyObjError (PyExc_RuntimeError,
428                                         "couldn't get Image.xrep attribute");
429 }
430
431 static PyObject *Image_getYRep(BPy_Image *self)
432 {
433         PyObject *attr = PyInt_FromLong(self->image->yrep);
434
435         if (attr) return attr;
436
437         return EXPP_ReturnPyObjError (PyExc_RuntimeError,
438                                         "couldn't get Image.yrep attribute");
439 }
440
441 static PyObject *Image_getBindCode(BPy_Image *self)
442 {
443         PyObject *attr = PyLong_FromUnsignedLong(self->image->bindcode);
444
445         if (attr) return attr;
446
447         return EXPP_ReturnPyObjError (PyExc_RuntimeError,
448                 "couldn't get Image.bindcode attribute");
449 }
450
451 static PyObject *Image_reload(BPy_Image *self)
452 {
453         Image *img = self->image;
454         
455         free_image_buffers(img); /* force read again */
456         img->ok = 1;
457         image_changed(G.sima, 0);
458         
459         Py_INCREF(Py_None);
460         return Py_None;
461 }
462
463 static PyObject *Image_setName(BPy_Image *self, PyObject *args)
464 {
465         char *name;
466         char buf[21];
467
468         if (!PyArg_ParseTuple(args, "s", &name))
469                 return (EXPP_ReturnPyObjError (PyExc_TypeError,
470                                                 "expected string argument"));
471         
472         PyOS_snprintf(buf, sizeof(buf), "%s", name);
473         
474         rename_id(&self->image->id, buf);
475
476         Py_INCREF(Py_None);
477         return Py_None;
478 }
479
480 static PyObject *Image_setXRep(BPy_Image *self, PyObject *args)
481 {
482         short value;
483
484         if (!PyArg_ParseTuple(args, "h", &value))
485                 return (EXPP_ReturnPyObjError (PyExc_TypeError,
486                                                 "expected int argument in [1,16]"));
487
488         if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX)
489                 self->image->xrep = value;
490         else
491                 return (EXPP_ReturnPyObjError (PyExc_ValueError,
492                                                 "expected int argument in [1,16]"));
493
494         Py_INCREF(Py_None);
495         return Py_None;
496 }
497
498 static PyObject *Image_setYRep(BPy_Image *self, PyObject *args)
499 {
500         short value;
501
502         if (!PyArg_ParseTuple(args, "h", &value))
503                 return (EXPP_ReturnPyObjError (PyExc_TypeError,
504                                                 "expected int argument in [1,16]"));
505
506         if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX)
507                 self->image->yrep = value;
508         else
509                 return (EXPP_ReturnPyObjError (PyExc_ValueError,
510                                                 "expected int argument in [1,16]"));
511
512         Py_INCREF(Py_None);
513         return Py_None;
514 }
515
516 /*****************************************************************************/
517 /* Function:            Image_getAttr                                                                                                                                                                                            */
518 /* Description: This is a callback function for the BPy_Image type. It is                */
519 /*                                                      the function that accesses BPy_Image member variables and                */
520 /*                                                      methods.                                                                                                                                                                                                                 */
521 /*****************************************************************************/
522 static PyObject *Image_getAttr (BPy_Image *self, char *name)
523 {
524         PyObject *attr = Py_None;
525
526         if (strcmp(name, "name") == 0)
527                 attr = PyString_FromString(self->image->id.name+2);
528         else if (strcmp(name, "filename") == 0)
529                 attr = PyString_FromString(self->image->name);
530         else if (strcmp(name, "size") == 0)
531                 attr = Image_getSize(self);
532         else if (strcmp(name, "depth") == 0)
533                 attr = Image_getDepth(self);
534         else if (strcmp(name, "xrep") == 0)
535                 attr = PyInt_FromLong(self->image->xrep);
536         else if (strcmp(name, "yrep") == 0)
537                 attr = PyInt_FromLong(self->image->yrep);
538         else if (strcmp(name, "bindcode") == 0)
539                 attr = PyInt_FromLong(self->image->bindcode);
540
541         else if (strcmp(name, "__members__") == 0)
542                 attr = Py_BuildValue("[s,s,s,s,s,s,s]",
543                         "name", "filename", "size", "depth", "xrep", "yrep", "bindcode");
544
545         if (!attr)
546                 return (EXPP_ReturnPyObjError (PyExc_MemoryError,
547                                                                                                                 "couldn't create PyObject"));
548
549         if (attr != Py_None) return attr; /* attribute found, return its value */
550
551         /* not an attribute, search the methods table */
552         return Py_FindMethod(BPy_Image_methods, (PyObject *)self, name);
553 }
554
555 /*****************************************************************************/
556 /* Function:            Image_setAttr                                                                                                                                                                                            */
557 /* Description: This is a callback function for the BPy_Image type. It is the*/
558 /*                                                      function that changes Image object members values. If this       */
559 /*                                                      data is linked to a Blender Image, it also gets updated.                 */
560 /*****************************************************************************/
561 static int Image_setAttr (BPy_Image *self, char *name, PyObject *value)
562 {
563         PyObject *valtuple; 
564         PyObject *error = NULL;
565
566 /* We're playing a trick on the Python API users here.  Even if they use
567  * Image.member = val instead of Image.setMember(value), we end up using the
568  * function anyway, since it already has error checking, clamps to the right
569  * interval and updates the Blender Image structure when necessary. */
570
571         valtuple = Py_BuildValue("(O)", value); /*the set* functions expect a tuple*/
572
573         if (!valtuple)
574                 return EXPP_ReturnIntError(PyExc_MemoryError,
575                                                                         "ImageSetAttr: couldn't create PyTuple");
576
577         if (strcmp (name, "name") == 0)
578                 error = Image_setName (self, valtuple);
579         else if (strcmp (name, "xrep") == 0)
580                 error = Image_setXRep (self, valtuple);
581         else if (strcmp (name, "yrep") == 0)
582                 error = Image_setYRep (self, valtuple);
583         else { /* Error: no such member in the Image object structure */
584                 Py_DECREF(value);
585                 Py_DECREF(valtuple);
586                 return (EXPP_ReturnIntError (PyExc_KeyError,
587                                                 "attribute not found or immutable"));
588         }
589
590         Py_DECREF(valtuple);
591
592         if (error != Py_None) return -1;
593
594         Py_DECREF(Py_None); /* incref'ed by the called set* function */
595         return 0; /* normal exit */
596 }
597
598 /*****************************************************************************/
599 /* Function:            Image_compare                                                                                                                                                                                            */
600 /* Description: This is a callback function for the BPy_Image type. It                   */
601 /*                                                      compares two Image_Type objects. Only the "==" and "!="                  */
602 /*                                                      comparisons are meaninful. Returns 0 for equality and -1 if  */
603 /*                                                      they don't point to the same Blender Image struct.                                       */
604 /*                                                      In Python it becomes 1 if they are equal, 0 otherwise.                   */
605 /*****************************************************************************/
606 static int Image_compare (BPy_Image *a, BPy_Image *b)
607 {
608         Image *pa = a->image, *pb = b->image;
609         return (pa == pb) ? 0:-1;
610 }
611
612 /*****************************************************************************/
613 /* Function:            Image_repr                                                                                                                                                                                                       */
614 /* Description: This is a callback function for the BPy_Image type. It                   */
615 /*                                                      builds a meaninful string to represent image objects.                            */
616 /*****************************************************************************/
617 static PyObject *Image_repr (BPy_Image *self)
618 {
619         return PyString_FromFormat("[Image \"%s\"]", self->image->id.name+2);
620 }