diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_image_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_image_api.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index 90f90ea8632..5fc65ea385c 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -52,8 +52,6 @@ #include "BKE_packedFile.h" #include "BKE_main.h" -#include "BKE_global.h" /* grr: G.main->name */ - #include "IMB_imbuf.h" #include "IMB_colormanagement.h" @@ -109,13 +107,13 @@ static void rna_Image_save_render(Image *image, bContext *C, ReportList *reports } } -static void rna_Image_save(Image *image, bContext *C, ReportList *reports) +static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *reports) { ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL); if (ibuf) { char filename[FILE_MAX]; BLI_strncpy(filename, image->name, sizeof(filename)); - BLI_path_abs(filename, ID_BLEND_PATH(G.main, &image->id)); + BLI_path_abs(filename, ID_BLEND_PATH(bmain, &image->id)); if (image->packedfile) { if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) { @@ -144,7 +142,9 @@ static void rna_Image_save(Image *image, bContext *C, ReportList *reports) WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image); } -static void rna_Image_pack(Image *image, bContext *C, ReportList *reports, int as_png) +static void rna_Image_pack( + Image *image, Main *bmain, bContext *C, ReportList *reports, + int as_png, const char *data, int data_len) { ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL); @@ -152,11 +152,20 @@ static void rna_Image_pack(Image *image, bContext *C, ReportList *reports, int a BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG"); } else { + if (image->packedfile) { + freePackedFile(image->packedfile); + image->packedfile = NULL; + } if (as_png) { BKE_image_memorypack(image); } + else if (data) { + char *data_dup = MEM_mallocN(sizeof(*data_dup) * (size_t)data_len, __func__); + memcpy(data_dup, data, (size_t)data_len); + image->packedfile = newPackedFileMemory(data_dup, data_len); + } else { - image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(G.main, &image->id)); + image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(bmain, &image->id)); } } @@ -301,12 +310,16 @@ void RNA_api_image(StructRNA *srna) 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_CONTEXT | FUNC_USE_REPORTS); + RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_CONTEXT | 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_CONTEXT | FUNC_USE_REPORTS); + RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS); RNA_def_boolean(func, "as_png", 0, "as_png", "Pack the image as PNG (needed for generated/dirty images)"); + parm = RNA_def_property(func, "data", PROP_STRING, PROP_BYTESTRING); + RNA_def_property_ui_text(parm, "data", "Raw data (bytes, exact content of the embedded file)"); + RNA_def_int(func, "data_len", 0, 0, INT_MAX, + "data_len", "length of given data (mandatory if data is provided)", 0, INT_MAX); 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"); |