From d6cbdabfe1c8c6ceea6fafbf8af09a6c4ddd84c9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 May 2007 19:40:11 +0000 Subject: Bugfix for python Image.save() [ #6702 ] Image doesn't get saved after painting & packing IMB_saveiff - (general saving function), does not write a file when the image is packed. so write a file with writePackedFile for packed files. --- source/blender/python/api2_2x/Image.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source/blender/python/api2_2x/Image.c') diff --git a/source/blender/python/api2_2x/Image.c b/source/blender/python/api2_2x/Image.c index 449ebcdfa7a..7ba3284e04e 100644 --- a/source/blender/python/api2_2x/Image.c +++ b/source/blender/python/api2_2x/Image.c @@ -657,7 +657,7 @@ static PyObject *Image_unpack( BPy_Image * self, PyObject * args ) /*get the absolute path */ if( !PyArg_ParseTuple( args, "i", &mode ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected 1 integer" ); + "expected 1 integer from Blender.UnpackModes" ); if (image->packedfile==NULL) return EXPP_ReturnPyObjError( PyExc_RuntimeError, @@ -716,10 +716,21 @@ static PyObject *Image_makeCurrent( BPy_Image * self ) static PyObject *Image_save( BPy_Image * self ) { ImBuf *ibuf= BKE_image_get_ibuf(self->image, NULL); + + if(!ibuf) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "could not save image (no image buffer)" ); - if(!ibuf || !IMB_saveiff( ibuf, self->image->name, ibuf->flags ) ) + /* If this is a packed file, write using writePackedFile + * because IMB_saveiff wont save to a file */ + if (self->image->packedfile) { + if (writePackedFile(self->image->name, self->image->packedfile, 0) != RET_OK) { + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "could not save image (writing image from packedfile failed)" ); + } + } else if (!IMB_saveiff( ibuf, self->image->name, ibuf->flags)) return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "could not save image" ); + "could not save image (writing the image buffer failed)" ); Py_RETURN_NONE; /* normal return, image saved */ } -- cgit v1.2.3