[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40324] trunk/blender/source/blender/ makesrna/intern/rna_image_api.c: patch [#28684] Image pack/unpack() implementation.

Campbell Barton ideasman42 at gmail.com
Sun Sep 18 13:47:17 CEST 2011


Revision: 40324
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40324
Author:   campbellbarton
Date:     2011-09-18 11:47:17 +0000 (Sun, 18 Sep 2011)
Log Message:
-----------
patch [#28684] Image pack/unpack() implementation.
from Bill Currie (taniwha)

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_image_api.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_image_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_image_api.c	2011-09-18 11:25:50 UTC (rev 40323)
+++ trunk/blender/source/blender/makesrna/intern/rna_image_api.c	2011-09-18 11:47:17 UTC (rev 40324)
@@ -37,7 +37,10 @@
 #include <time.h>
 
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
+#include "DNA_packedFile_types.h"
+
 #include "BIF_gl.h"
 
 #ifdef RNA_RUNTIME
@@ -127,6 +130,38 @@
 	}
 }
 
+static void rna_Image_pack(Image *image, ReportList *reports, int as_png)
+{
+	ImBuf *ibuf = BKE_image_get_ibuf(image, NULL);
+
+	if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
+		BKE_reportf(reports, RPT_ERROR, "Can't pack edited image from disk, only as internal PNG.");
+	}
+	else {
+		if(as_png) {
+			BKE_image_memorypack(image);
+		}
+		else {
+			image->packedfile= newPackedFile(reports, image->name);
+		}
+	}
+}
+
+static void rna_Image_unpack(Image *image, ReportList *reports, int method)
+{
+	if (!image->packedfile) {
+		BKE_report(reports, RPT_ERROR, "Image not packed");
+	}
+	else if (image->source==IMA_SRC_SEQUENCE || image->source==IMA_SRC_MOVIE) {
+		BKE_report(reports, RPT_ERROR, "Unpacking movies or image sequences not supported.");
+		return;
+	}
+	else {
+		/* reports its own error on failier */
+		unpackImage (reports, image, method);
+	}
+}
+
 static void rna_Image_reload(Image *image)
 {
 	BKE_image_signal(image, NULL, IMA_SIGNAL_RELOAD);
@@ -211,6 +246,16 @@
 	RNA_def_function_ui_description(func, "Save image to its source path");
 	RNA_def_function_flag(func, FUNC_USE_REPORTS);
 
+	func= RNA_def_function(srna, "pack", "rna_Image_pack");
+	RNA_def_function_ui_description(func, "Pack an image as embedded data into the .blend file.");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	RNA_def_boolean(func, "as_png", 0, "as_png", "Pack the image as PNG (needed for generated/dirty images)");
+
+	func= RNA_def_function(srna, "unpack", "rna_Image_unpack");
+	RNA_def_function_ui_description(func, "Save an image packed in the .blend file to disk");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	RNA_def_enum(func, "method", unpack_method_items, PF_USE_LOCAL, "method", "How to unpack.");
+
 	func= RNA_def_function(srna, "reload", "rna_Image_reload");
 	RNA_def_function_ui_description(func, "Reload the image from its source path");
 




More information about the Bf-blender-cvs mailing list