Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_image_api.c
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| if (BKE_packedfile_write_to_file( | if (BKE_packedfile_write_to_file( | ||||
| reports, BKE_main_blendfile_path(bmain), imapf->filepath, imapf->packedfile, 0) != | reports, BKE_main_blendfile_path(bmain), imapf->filepath, imapf->packedfile, 0) != | ||||
| RET_OK) { | RET_OK) { | ||||
| BKE_reportf(reports, RPT_ERROR, "Could not save packed file to disk as '%s'", imapf->filepath); | BKE_reportf(reports, RPT_ERROR, "Could not save packed file to disk as '%s'", imapf->filepath); | ||||
| } | } | ||||
| } | } | ||||
| static void rna_Image_save_render( | static void rna_Image_save_render(Image *image, | ||||
| Image *image, bContext *C, ReportList *reports, const char *path, Scene *scene) | bContext *C, | ||||
| ReportList *reports, | |||||
| const char *path, | |||||
| Scene *scene, | |||||
| const int quality) | |||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| if (scene == NULL) { | if (scene == NULL) { | ||||
| scene = CTX_data_scene(C); | scene = CTX_data_scene(C); | ||||
| } | } | ||||
| ImageSaveOptions opts; | ImageSaveOptions opts; | ||||
| if (BKE_image_save_options_init(&opts, bmain, scene, image, NULL, false, true)) { | if (BKE_image_save_options_init(&opts, bmain, scene, image, NULL, false, true)) { | ||||
| opts.save_copy = true; | opts.save_copy = true; | ||||
| STRNCPY(opts.filepath, path); | STRNCPY(opts.filepath, path); | ||||
| if (quality != 0) { | |||||
| opts.im_format.quality = clamp_i(quality, 0, 100); | |||||
| } | |||||
| if (!BKE_image_save(reports, bmain, image, NULL, &opts)) { | if (!BKE_image_save(reports, bmain, image, NULL, &opts)) { | ||||
| BKE_reportf( | BKE_reportf( | ||||
| reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, path); | reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, path); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2); | BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2); | ||||
| } | } | ||||
| BKE_image_save_options_free(&opts); | BKE_image_save_options_free(&opts); | ||||
| WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image); | WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, image); | ||||
| } | } | ||||
| static void rna_Image_save(Image *image, Main *bmain, bContext *C, ReportList *reports) | static void rna_Image_save(Image *image, | ||||
| Main *bmain, | |||||
| bContext *C, | |||||
| ReportList *reports, | |||||
| const char *path, | |||||
| const int quality) | |||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ImageSaveOptions opts; | ImageSaveOptions opts; | ||||
| if (BKE_image_save_options_init(&opts, bmain, scene, image, NULL, false, false)) { | if (BKE_image_save_options_init(&opts, bmain, scene, image, NULL, false, false)) { | ||||
| if (path && path[0]) { | |||||
| STRNCPY(opts.filepath, path); | |||||
| } | |||||
| if (quality != 0) { | |||||
| opts.im_format.quality = clamp_i(quality, 0, 100); | |||||
| } | |||||
| if (!BKE_image_save(reports, bmain, image, NULL, &opts)) { | if (!BKE_image_save(reports, bmain, image, NULL, &opts)) { | ||||
| BKE_reportf(reports, | BKE_reportf(reports, | ||||
| RPT_ERROR, | RPT_ERROR, | ||||
| "Image '%s' could not be saved to '%s'", | "Image '%s' could not be saved to '%s'", | ||||
| image->id.name + 2, | image->id.name + 2, | ||||
| image->filepath); | image->filepath); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| FunctionRNA *func; | FunctionRNA *func; | ||||
| PropertyRNA *parm; | PropertyRNA *parm; | ||||
| func = RNA_def_function(srna, "save_render", "rna_Image_save_render"); | func = RNA_def_function(srna, "save_render", "rna_Image_save_render"); | ||||
| RNA_def_function_ui_description(func, | RNA_def_function_ui_description(func, | ||||
| "Save image to a specific path using a scenes render settings"); | "Save image to a specific path using a scenes render settings"); | ||||
| RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS); | RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS); | ||||
| parm = RNA_def_string_file_path(func, "filepath", NULL, 0, "", "Save path"); | parm = RNA_def_string_file_path(func, "filepath", NULL, 0, "", "Output path"); | ||||
| RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); | ||||
| RNA_def_pointer(func, "scene", "Scene", "", "Scene to take image parameters from"); | RNA_def_pointer(func, "scene", "Scene", "", "Scene to take image parameters from"); | ||||
| RNA_def_int(func, | |||||
| "quality", | |||||
| 0, | |||||
| 0, | |||||
| 100, | |||||
| "Quality", | |||||
| "Quality for image formats that support lossy compression, uses default quality if " | |||||
| "not specified", | |||||
| 0, | |||||
| 100); | |||||
| func = RNA_def_function(srna, "save", "rna_Image_save"); | func = RNA_def_function(srna, "save", "rna_Image_save"); | ||||
| RNA_def_function_ui_description(func, "Save image to its source path"); | RNA_def_function_ui_description(func, "Save image"); | ||||
| RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS); | RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS); | ||||
| RNA_def_string_file_path(func, | |||||
| "filepath", | |||||
| NULL, | |||||
| 0, | |||||
| "", | |||||
| "Output path, uses image data-block filepath if not specified"); | |||||
| RNA_def_int(func, | |||||
| "quality", | |||||
| 0, | |||||
| 0, | |||||
| 100, | |||||
| "Quality", | |||||
| "Quality for image formats that support lossy compression, uses default quality if " | |||||
| "not specified", | |||||
| 0, | |||||
| 100); | |||||
| func = RNA_def_function(srna, "pack", "rna_Image_pack"); | 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_ui_description(func, "Pack an image as embedded data into the .blend file"); | ||||
| RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS); | RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS); | ||||
| parm = RNA_def_property(func, "data", PROP_STRING, PROP_BYTESTRING); | 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_property_ui_text(parm, "data", "Raw data (bytes, exact content of the embedded file)"); | ||||
| RNA_def_int(func, | RNA_def_int(func, | ||||
| "data_len", | "data_len", | ||||
| ▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines | |||||