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.
This commit is contained in:
@@ -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)) {
|
||||
|
Reference in New Issue
Block a user