[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25786] trunk/blender/source/blender/ makesrna/intern/rna_image_api.c: RNA API: image.save(path)

Martin Poirier theeth at yahoo.com
Wed Jan 6 22:38:26 CET 2010


Revision: 25786
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25786
Author:   theeth
Date:     2010-01-06 22:38:26 +0100 (Wed, 06 Jan 2010)

Log Message:
-----------
RNA API: image.save(path)

Saves an image to the specified path. Uses format and other parameters from the scene (simpler this way than having to explicitly pass them to the function).

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	2010-01-06 20:29:49 UTC (rev 25785)
+++ trunk/blender/source/blender/makesrna/intern/rna_image_api.c	2010-01-06 21:38:26 UTC (rev 25786)
@@ -63,6 +63,24 @@
 	return path;
 }
 
+static void rna_Image_save(Image *image, bContext *C, ReportList *reports, char *path)
+{
+	ImBuf *ibuf;
+	Scene *scene = CTX_data_scene(C);
+
+	if (scene) {
+		ibuf = BKE_image_get_ibuf(image, NULL);
+
+		if (BKE_write_ibuf(NULL, ibuf, path, scene->r.imtype, scene->r.subimtype, scene->r.quality)) {
+
+		} else {
+			BKE_reportf(reports, RPT_ERROR, "Couldn't write image: %s", path);
+		}
+	} else {
+		BKE_reportf(reports, RPT_ERROR, "Scene not in context, couldn't get save parameters");
+	}
+}
+
 char *rna_Image_get_abs_filename(Image *image, bContext *C)
 {
 	char *filename= MEM_callocN(FILE_MAX, "Image.get_abs_filename()");
@@ -95,6 +113,12 @@
 	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
 	parm= RNA_def_string_file_path(func, "abs_filename", NULL, 0, "", "Image/movie absolute filename.");
 	RNA_def_function_return(func, parm);
+
+	func= RNA_def_function(srna, "save", "rna_Image_save");
+	RNA_def_function_ui_description(func, "Save image to a specific path.");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	parm= RNA_def_string(func, "path", "", 0, "", "Save path.");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
 }
 
 #endif





More information about the Bf-blender-cvs mailing list