From 24cc88505749f222e93f224d8e5254798e03bb85 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 21 Oct 2015 02:26:23 +1100 Subject: RNA: Change behavior of Image.save() Previously it would save packed file(s), which would ignore the image.filepath, making it impossible to set the destination. Add image.packed_files[...].save() so you can save packed files if its needed. --- source/blender/makesrna/intern/rna_image_api.c | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'source/blender/makesrna/intern/rna_image_api.c') diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index f187a0e1804..1efa41d1b00 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -63,6 +63,14 @@ #include "MEM_guardedalloc.h" +static void rna_ImagePackedFile_save(ImagePackedFile *imapf, ReportList *reports) +{ + if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) { + BKE_reportf(reports, RPT_ERROR, "Image could not save packed file to '%s'", + imapf->filepath); + } +} + static void rna_Image_save_render(Image *image, bContext *C, ReportList *reports, const char *path, Scene *scene) { ImBuf *ibuf; @@ -115,17 +123,10 @@ static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *r BLI_strncpy(filename, image->name, sizeof(filename)); BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id)); - if (BKE_image_has_packedfile(image)) { - ImagePackedFile *imapf; + /* note, we purposefully ignore packed files here, + * developers need to explicitly write them via 'packed_files' */ - for (imapf = image->packedfiles.first; imapf; imapf = imapf->next) { - if (writePackedFile(reports, imapf->filepath, imapf->packedfile, 0) != RET_OK) { - BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'", - image->id.name + 2, imapf->filepath); - } - } - } - else if (IMB_saveiff(ibuf, filename, ibuf->flags)) { + if (IMB_saveiff(ibuf, filename, ibuf->flags)) { image->type = IMA_TYPE_IMAGE; if (image->source == IMA_SRC_GENERATED) @@ -295,6 +296,15 @@ static void rna_Image_buffers_free(Image *image) #else +void RNA_api_image_packed_file(StructRNA *srna) +{ + FunctionRNA *func; + + func = RNA_def_function(srna, "save", "rna_ImagePackedFile_save"); + RNA_def_function_ui_description(func, "Save the packed file to its filepath"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); +} + void RNA_api_image(StructRNA *srna) { FunctionRNA *func; -- cgit v1.2.3