2009-07-24 15:27:59 +00:00
|
|
|
/**
|
2009-09-22 16:35:07 +00:00
|
|
|
* $Id$
|
2009-07-24 15:27:59 +00:00
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
2009-09-22 16:35:07 +00:00
|
|
|
* Contributor(s): Arystanbek Dyussenov
|
2009-07-24 15:27:59 +00:00
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
#include "RNA_types.h"
|
|
|
|
|
|
|
|
#ifdef RNA_RUNTIME
|
|
|
|
|
|
|
|
#include "BKE_image.h"
|
2009-09-27 09:19:29 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
|
|
|
#include "DNA_image_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
2009-07-24 15:27:59 +00:00
|
|
|
|
2009-08-19 09:52:13 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2009-08-05 07:59:49 +00:00
|
|
|
/*
|
|
|
|
User should check if returned path exists before copying a file there.
|
|
|
|
|
|
|
|
TODO: it would be better to return a (abs, rel) tuple.
|
|
|
|
*/
|
2009-08-03 12:02:40 +00:00
|
|
|
static char *rna_Image_get_export_path(Image *image, char *dest_dir, int rel)
|
2009-07-24 15:27:59 +00:00
|
|
|
{
|
|
|
|
int length = FILE_MAX;
|
|
|
|
char *path= MEM_callocN(length, "image file path");
|
|
|
|
|
2009-08-03 12:02:40 +00:00
|
|
|
if (!BKE_get_image_export_path(image, dest_dir, rel ? NULL : path, length, rel ? path : NULL, length )) {
|
2009-07-24 15:27:59 +00:00
|
|
|
MEM_freeN(path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2010-01-08 17:47:27 +00:00
|
|
|
static void rna_Image_save(Image *image, bContext *C, ReportList *reports, char *path, Scene *scene)
|
2010-01-06 21:38:26 +00:00
|
|
|
{
|
|
|
|
ImBuf *ibuf;
|
2010-01-08 17:47:27 +00:00
|
|
|
|
|
|
|
if (scene == NULL) {
|
|
|
|
scene = CTX_data_scene(C);
|
|
|
|
}
|
2010-01-06 21:38:26 +00:00
|
|
|
|
|
|
|
if (scene) {
|
2010-01-07 20:25:51 +00:00
|
|
|
ImageUser iuser;
|
|
|
|
void *lock;
|
2010-01-06 21:38:26 +00:00
|
|
|
|
2010-01-07 20:25:51 +00:00
|
|
|
iuser.scene = scene;
|
|
|
|
iuser.ok = 1;
|
|
|
|
|
|
|
|
ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
|
2010-01-06 21:38:26 +00:00
|
|
|
|
2010-01-08 02:45:51 +00:00
|
|
|
if (ibuf == NULL) {
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "Couldn't acquire buffer from image");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!BKE_write_ibuf(NULL, ibuf, path, scene->r.imtype, scene->r.subimtype, scene->r.quality)) {
|
2010-01-06 21:38:26 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-27 09:19:29 +00:00
|
|
|
char *rna_Image_get_abs_filename(Image *image, bContext *C)
|
|
|
|
{
|
|
|
|
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);
|
2010-01-30 22:33:47 +00:00
|
|
|
BLI_convertstringframe(filename, CTX_data_scene(C)->r.cfra, 0);
|
2009-09-27 09:19:29 +00:00
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2009-07-24 15:27:59 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
void RNA_api_image(StructRNA *srna)
|
|
|
|
{
|
|
|
|
FunctionRNA *func;
|
|
|
|
PropertyRNA *parm;
|
|
|
|
|
2009-08-06 12:22:50 +00:00
|
|
|
func= RNA_def_function(srna, "get_export_path", "rna_Image_get_export_path");
|
2009-08-03 12:02:40 +00:00
|
|
|
RNA_def_function_ui_description(func, "Produce image export path.");
|
2009-07-24 15:27:59 +00:00
|
|
|
parm= RNA_def_string(func, "dest_dir", "", 0, "", "Destination directory.");
|
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2009-08-03 12:02:40 +00:00
|
|
|
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.");
|
2009-07-24 15:27:59 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
2009-09-27 09:19:29 +00:00
|
|
|
|
|
|
|
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);
|
2010-01-06 21:38:26 +00:00
|
|
|
|
|
|
|
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);
|
2010-01-08 17:47:27 +00:00
|
|
|
parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene to take image parameters from.");
|
2009-07-24 15:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|