From bd03fe1ab0d09aa7bb29bdcd3d57db772b1dadbd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 25 Feb 2020 20:32:20 +1100 Subject: Cleanup: avoid Operator.customdata cast which could lead to errors Both save and save-as share utility functions which cast from customdata in an error prone way. Avoid this by passing image format data directly. --- source/blender/editors/space_image/image_ops.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index d6355bb88fe..a3fa03b18b7 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -2043,12 +2043,14 @@ static int image_save_options_init(Main *bmain, return (ibuf != NULL); } -static void image_save_options_from_op(Main *bmain, ImageSaveOptions *opts, wmOperator *op) +static void image_save_options_from_op(Main *bmain, + ImageSaveOptions *opts, + wmOperator *op, + ImageFormatData *imf) { - if (op->customdata) { - ImageSaveData *isd = op->customdata; + if (imf) { BKE_color_managed_view_settings_free(&opts->im_format.view_settings); - opts->im_format = isd->im_format; + opts->im_format = *imf; } if (RNA_struct_property_is_set(op->ptr, "filepath")) { @@ -2111,10 +2113,12 @@ static int image_save_as_exec(bContext *C, wmOperator *op) Image *image = NULL; ImageUser *iuser = NULL; + ImageFormatData *imf = NULL; if (op->customdata) { ImageSaveData *isd = op->customdata; image = isd->image; iuser = isd->iuser; + imf = &isd->im_format; } else { image = image_from_context(C); @@ -2127,7 +2131,7 @@ static int image_save_as_exec(bContext *C, wmOperator *op) * these should be set on invoke or by the caller. */ image_save_options_init(bmain, &opts, image, iuser, false, false); - image_save_options_from_op(bmain, &opts, op); + image_save_options_from_op(bmain, &opts, op, imf); opts.do_newpath = true; save_image_op(bmain, image, iuser, op, &opts); @@ -2371,7 +2375,7 @@ static int image_save_exec(bContext *C, wmOperator *op) if (image_save_options_init(bmain, &opts, image, iuser, false, false) == 0) { return OPERATOR_CANCELLED; } - image_save_options_from_op(bmain, &opts, op); + image_save_options_from_op(bmain, &opts, op, NULL); if (BLI_exists(opts.filepath) && BLI_file_is_writable(opts.filepath)) { if (save_image_op(bmain, image, iuser, op, &opts)) { -- cgit v1.2.3