diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-09-18 15:47:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-09-18 15:47:17 +0400 |
commit | 82e6547a3637136fd9e411e7531669bb96a141a3 (patch) | |
tree | 5cf3ed1c3b9d9092a06669ebe56c4121554a9f7a /source | |
parent | b17a62d1b37a5a38d9e8a37680ee11d66b8a327b (diff) |
patch [#28684] Image pack/unpack() implementation.
from Bill Currie (taniwha)
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesrna/intern/rna_image_api.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index 7327c7203b9..083e87dfd4e 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -37,6 +37,9 @@ #include <time.h> #include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "DNA_packedFile_types.h" #include "BIF_gl.h" @@ -127,6 +130,38 @@ static void rna_Image_save(Image *image, ReportList *reports) } } +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 @@ void RNA_api_image(StructRNA *srna) 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"); |