merge with trunk at r27259 and commit of a patch by anthony jones to fix msvc (though...
[blender-staging.git] / source / blender / makesrna / intern / rna_image_api.c
index 3a978196a29f5d748578a703e10f9ba554c5213d..892370a9f72d79cabb60c0af72ec4f064c765cdf 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2009 Blender Foundation.
  * All rights reserved.
 #ifdef RNA_RUNTIME
 
 #include "BKE_image.h"
+#include "BKE_packedFile.h"
 #include "BKE_main.h"
 #include "BKE_utildefines.h"
 
+#include "IMB_imbuf.h"
+
 #include "DNA_image_types.h"
 #include "DNA_scene_types.h"
 
 #include "MEM_guardedalloc.h"
 
-/*
-  User should check if returned path exists before copying a file there.
-
-  TODO: it would be better to return a (abs, rel) tuple.
-*/
-static char *rna_Image_get_export_path(Image *image, char *dest_dir, int rel)
-{
-       int length = FILE_MAX;
-       char *path= MEM_callocN(length, "image file path");
-
-       if (!BKE_get_image_export_path(image, dest_dir, rel ? NULL : path, length, rel ? path : NULL, length )) {
-               MEM_freeN(path);
-               return NULL;
-       }
-
-       return path;
-}
-
-static void rna_Image_save(Image *image, bContext *C, ReportList *reports, char *path, Scene *scene)
+static void rna_Image_save_render(Image *image, bContext *C, ReportList *reports, char *path, Scene *scene)
 {
        ImBuf *ibuf;
 
@@ -92,15 +77,25 @@ static void rna_Image_save(Image *image, bContext *C, ReportList *reports, char
        }
 }
 
-char *rna_Image_get_abs_filename(Image *image, bContext *C)
+static void rna_Image_save(Image *image, ReportList *reports)
 {
-       char *filename= MEM_callocN(FILE_MAX, "Image.get_abs_filename()");
-
-       BLI_strncpy(filename, image->name, FILE_MAXDIR + FILE_MAXFILE);
-       BLI_convertstringcode(filename, CTX_data_main(C)->name);
-       BLI_convertstringframe(filename, CTX_data_scene(C)->r.cfra);
-
-       return filename;
+       ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);
+       if(ibuf) {
+               if(image->packedfile) {
+                       if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) {
+                               BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could saved packed file to \"%s\"", image->id.name+2, image->name);
+                       }
+               }
+               else if (IMB_saveiff(ibuf, image->name, ibuf->flags)) {
+                       ibuf->userflags &= ~IB_BITMAPDIRTY;
+               }
+               else {
+                       BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could not be saved to \"%s\"", image->id.name+2, image->name);
+               }
+       }
+       else {
+               BKE_reportf(reports, RPT_ERROR, "Image \"%s\" does not have any image data", image->id.name+2);
+       }
 }
 
 #else
@@ -110,27 +105,16 @@ void RNA_api_image(StructRNA *srna)
        FunctionRNA *func;
        PropertyRNA *parm;
 
-       func= RNA_def_function(srna, "get_export_path", "rna_Image_get_export_path");
-       RNA_def_function_ui_description(func, "Produce image export path.");
-       parm= RNA_def_string(func, "dest_dir", "", 0, "", "Destination directory.");
-       RNA_def_property_flag(parm, PROP_REQUIRED);
-       parm= RNA_def_boolean(func, "get_rel_path", 1, "", "Return relative path if True.");
-       RNA_def_property_flag(parm, PROP_REQUIRED);
-       parm= RNA_def_string(func, "path", "", 0, "", "Absolute export path.");
-       RNA_def_function_return(func, parm);
-
-       func= RNA_def_function(srna, "get_abs_filename", "rna_Image_get_abs_filename");
-       RNA_def_function_ui_description(func, "Get absolute filename.");
-       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.");
+       func= RNA_def_function(srna, "save_render", "rna_Image_save_render");
+       RNA_def_function_ui_description(func, "Save image to a specific path using a scenes render settings.");
        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);
        parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene to take image parameters from.");
+
+       func= RNA_def_function(srna, "save", "rna_Image_save");
+       RNA_def_function_ui_description(func, "Save image to its source path.");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
 }
 
 #endif