patch [#28684] Image pack/unpack() implementation.
from Bill Currie (taniwha)
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user