[Bf-blender-cvs] [24cc885] master: RNA: Change behavior of Image.save()

Campbell Barton noreply at git.blender.org
Tue Oct 20 17:34:56 CEST 2015


Commit: 24cc88505749f222e93f224d8e5254798e03bb85
Author: Campbell Barton
Date:   Wed Oct 21 02:26:23 2015 +1100
Branches: master
https://developer.blender.org/rB24cc88505749f222e93f224d8e5254798e03bb85

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.

===================================================================

M	source/blender/makesrna/intern/rna_image.c
M	source/blender/makesrna/intern/rna_image_api.c
M	source/blender/makesrna/intern/rna_internal.h

===================================================================

diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index 2fa2fde..64b4d17 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -576,9 +576,9 @@ static void rna_def_image_packed_files(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
 	RNA_def_property_string_sdna(prop, NULL, "filepath");
-	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_struct_name_property(srna, prop);
-	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+	RNA_api_image_packed_file(srna);
 }
 
 static void rna_def_render_slot(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c
index f187a0e..1efa41d 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;
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index eab14be..72cd2ce 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -260,6 +260,7 @@ void RNA_api_camera(StructRNA *srna);
 void RNA_api_curve(StructRNA *srna);
 void RNA_api_fcurves(StructRNA *srna);
 void RNA_api_drivers(StructRNA *srna);
+void RNA_api_image_packed_file(struct StructRNA *srna);
 void RNA_api_image(struct StructRNA *srna);
 void RNA_api_lattice(struct StructRNA *srna);
 void RNA_api_operator(struct StructRNA *srna);




More information about the Bf-blender-cvs mailing list