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);
|
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) {
|
if (imf) {
|
||||||
ImageSaveData *isd = op->customdata;
|
|
||||||
BKE_color_managed_view_settings_free(&opts->im_format.view_settings);
|
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")) {
|
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;
|
Image *image = NULL;
|
||||||
ImageUser *iuser = NULL;
|
ImageUser *iuser = NULL;
|
||||||
|
ImageFormatData *imf = NULL;
|
||||||
if (op->customdata) {
|
if (op->customdata) {
|
||||||
ImageSaveData *isd = op->customdata;
|
ImageSaveData *isd = op->customdata;
|
||||||
image = isd->image;
|
image = isd->image;
|
||||||
iuser = isd->iuser;
|
iuser = isd->iuser;
|
||||||
|
imf = &isd->im_format;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
image = image_from_context(C);
|
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. */
|
* these should be set on invoke or by the caller. */
|
||||||
image_save_options_init(bmain, &opts, image, iuser, false, false);
|
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;
|
opts.do_newpath = true;
|
||||||
|
|
||||||
save_image_op(bmain, image, iuser, op, &opts);
|
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) {
|
if (image_save_options_init(bmain, &opts, image, iuser, false, false) == 0) {
|
||||||
return OPERATOR_CANCELLED;
|
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 (BLI_exists(opts.filepath) && BLI_file_is_writable(opts.filepath)) {
|
||||||
if (save_image_op(bmain, image, iuser, op, &opts)) {
|
if (save_image_op(bmain, image, iuser, op, &opts)) {
|
||||||
|
Reference in New Issue
Block a user