rna/py api

rename image.save() --> image.save_render() because it uses render settings for saving.
added image.save() which is like pressing save in the image view, saving to the images path and removing the dirty flag.
This commit is contained in:
Campbell Barton 2010-02-26 12:28:44 +00:00
parent d616286ffb
commit bbf6dde277
4 changed files with 40 additions and 11 deletions

@ -202,7 +202,7 @@ def thumbnail(filename):
scene.render.quality = 90
bpy.ops.image.open(path = filename)
img = bpy.data.images[imagename]
img.save(thumbname, scene=scene)
img.save_render(thumbname, scene=scene)
try:
process = subprocess.Popen(["convert", thumbname, "-resize", "300x300", thumbname])

@ -38,7 +38,7 @@ class SaveDirty(bpy.types.Operator):
self.report({'WARNING'}, "Path used by more then one image: " + path)
else:
unique_paths.add(path)
image.save(path=path)
image.save()
return {'FINISHED'}

@ -37,15 +37,18 @@
#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"
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;
@ -74,6 +77,27 @@ static void rna_Image_save(Image *image, bContext *C, ReportList *reports, char
}
}
static void rna_Image_save(Image *image, ReportList *reports)
{
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
void RNA_api_image(StructRNA *srna)
@ -81,12 +105,16 @@ void RNA_api_image(StructRNA *srna)
FunctionRNA *func;
PropertyRNA *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

@ -2882,7 +2882,7 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
ParameterIterator iter;
PropertyRNA *parm;
PyObject *ret, *item;
int i, args_len, parms_len, ret_len, flag, err= 0, kw_tot= 0, kw_arg;
int i, pyargs_len, pykw_len, parms_len, ret_len, flag, err= 0, kw_tot= 0, kw_arg;
const char *parm_id;
PropertyRNA *pret_single= NULL;
@ -2904,16 +2904,17 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
* the same ID as the functions. */
RNA_pointer_create(self_ptr->id.data, &RNA_Function, self_func, &funcptr);
args_len= PyTuple_GET_SIZE(args);
pyargs_len= PyTuple_GET_SIZE(args);
pykw_len= kw ? PyDict_Size(kw) : 0;
RNA_parameter_list_create(&parms, self_ptr, self_func);
RNA_parameter_list_begin(&parms, &iter);
parms_len= RNA_parameter_list_size(&parms);
ret_len= 0;
if(args_len + (kw ? PyDict_Size(kw):0) > parms_len) {
if(pyargs_len + pykw_len > parms_len) {
RNA_parameter_list_end(&iter);
PyErr_Format(PyExc_TypeError, "%.200s.%.200s(): takes at most %d arguments, got %d", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), parms_len, args_len);
PyErr_Format(PyExc_TypeError, "%.200s.%.200s(): takes at most %d arguments, got %d", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), parms_len, pyargs_len + pykw_len);
err= -1;
}
@ -2936,7 +2937,7 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
parm_id= RNA_property_identifier(parm);
item= NULL;
if ((i < args_len) && (flag & PROP_REQUIRED)) {
if ((i < pyargs_len) && (flag & PROP_REQUIRED)) {
item= PyTuple_GET_ITEM(args, i);
i++;
@ -2987,7 +2988,7 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
* the if below is quick, checking if it passed less keyword args then we gave.
* (Dont overwrite the error if we have one, otherwise can skip important messages and confuse with args)
*/
if(err == 0 && kw && (PyDict_Size(kw) > kw_tot)) {
if(err == 0 && kw && (pykw_len > kw_tot)) {
PyObject *key, *value;
Py_ssize_t pos = 0;