diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-03-11 20:21:05 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-03-22 16:15:20 +0300 |
commit | 3b5224b57c3cfc39a7998ecfc482e13bd6940e68 (patch) | |
tree | 1111ceb0a6501b7de81d4e0e59b6d424c9773665 /source/blender/blenkernel/intern/image_save.cc | |
parent | 2ebcb7fab3e237b7d00de3088c34780cd24f397b (diff) |
Cleanup: refactor passing of color management settings for image save
Make a copy of ImageFormatData that contains the effective color management
settings, and pass that along to the various functions. This will make it
possible to add more complex logic later.
For compositing nodes, passing along view and display settings through
many functions made it harder to add additional settings, so just get those
from the scene now.
Differential Revision: https://developer.blender.org/D14401
Diffstat (limited to 'source/blender/blenkernel/intern/image_save.cc')
-rw-r--r-- | source/blender/blenkernel/intern/image_save.cc | 77 |
1 files changed, 35 insertions, 42 deletions
diff --git a/source/blender/blenkernel/intern/image_save.cc b/source/blender/blenkernel/intern/image_save.cc index f6ea814cbc0..b7f234aea59 100644 --- a/source/blender/blenkernel/intern/image_save.cc +++ b/source/blender/blenkernel/intern/image_save.cc @@ -230,8 +230,7 @@ static bool image_save_single(ReportList *reports, ok = BKE_image_render_write_exr(reports, rr, opts->filepath, imf, nullptr, layer); } else { - colormanaged_ibuf = IMB_colormanagement_imbuf_for_write( - ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); + colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, imf); ok = BKE_imbuf_write_as(colormanaged_ibuf, opts->filepath, imf, save_copy); imbuf_save_post(ibuf, colormanaged_ibuf); } @@ -292,8 +291,7 @@ static bool image_save_single(ReportList *reports, BKE_scene_multiview_view_filepath_get(&opts->scene->r, opts->filepath, view, filepath); - colormanaged_ibuf = IMB_colormanagement_imbuf_for_write( - ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); + colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, imf); ok_view = BKE_imbuf_write_as(colormanaged_ibuf, filepath, &opts->im_format, save_copy); imbuf_save_post(ibuf, colormanaged_ibuf); image_save_post(reports, ima, ibuf, ok_view, opts, true, filepath, r_colorspace_changed); @@ -358,8 +356,7 @@ static bool image_save_single(ReportList *reports, ibuf->planes = planes; /* color manage the ImBuf leaving it ready for saving */ - colormanaged_ibuf = IMB_colormanagement_imbuf_for_write( - ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); + colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, save_as_render, true, imf); BKE_image_format_to_imbuf(colormanaged_ibuf, imf); IMB_prepare_write_ImBuf(IMB_isfloat(colormanaged_ibuf), colormanaged_ibuf); @@ -652,26 +649,27 @@ bool BKE_image_render_write(ReportList *reports, const char *filename) { bool ok = true; - const RenderData *rd = &scene->r; if (!rr) { return false; } + ImageFormatData image_format; + BKE_image_format_init_for_write(&image_format, scene, nullptr); + const bool is_mono = BLI_listbase_count_at_most(&rr->views, 2) < 2; - const bool is_exr_rr = ELEM(rd->im_format.imtype, - R_IMF_IMTYPE_OPENEXR, - R_IMF_IMTYPE_MULTILAYER) && + const bool is_exr_rr = ELEM( + image_format.imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER) && RE_HasFloatPixels(rr); const float dither = scene->r.dither_intensity; - if (rd->im_format.views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) { - ok = BKE_image_render_write_exr(reports, rr, filename, &rd->im_format, nullptr, -1); + if (image_format.views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) { + ok = BKE_image_render_write_exr(reports, rr, filename, &image_format, nullptr, -1); image_render_print_save_message(reports, filename, ok, errno); } /* mono, legacy code */ - else if (is_mono || (rd->im_format.views_format == R_IMF_VIEWS_INDIVIDUAL)) { + else if (is_mono || (image_format.views_format == R_IMF_VIEWS_INDIVIDUAL)) { int view_id = 0; for (const RenderView *rv = (const RenderView *)rr->views.first; rv; rv = rv->next, view_id++) { @@ -684,37 +682,35 @@ bool BKE_image_render_write(ReportList *reports, } if (is_exr_rr) { - ok = BKE_image_render_write_exr(reports, rr, filepath, &rd->im_format, rv->name, -1); + ok = BKE_image_render_write_exr(reports, rr, filepath, &image_format, rv->name, -1); image_render_print_save_message(reports, filepath, ok, errno); /* optional preview images for exr */ - if (ok && (rd->im_format.flag & R_IMF_FLAG_PREVIEW_JPG)) { - ImageFormatData imf = rd->im_format; - imf.imtype = R_IMF_IMTYPE_JPEG90; + if (ok && (image_format.flag & R_IMF_FLAG_PREVIEW_JPG)) { + image_format.imtype = R_IMF_IMTYPE_JPEG90; if (BLI_path_extension_check(filepath, ".exr")) { filepath[strlen(filepath) - 4] = 0; } - BKE_image_path_ensure_ext_from_imformat(filepath, &imf); + BKE_image_path_ensure_ext_from_imformat(filepath, &image_format); - ImBuf *ibuf = RE_render_result_rect_to_ibuf(rr, &imf, dither, view_id); + ImBuf *ibuf = RE_render_result_rect_to_ibuf(rr, &image_format, dither, view_id); ibuf->planes = 24; - IMB_colormanagement_imbuf_for_write( - ibuf, true, false, &scene->view_settings, &scene->display_settings, &imf); + IMB_colormanagement_imbuf_for_write(ibuf, true, false, &image_format); - ok = image_render_write_stamp_test(reports, scene, rr, ibuf, filepath, &imf, stamp); + ok = image_render_write_stamp_test( + reports, scene, rr, ibuf, filepath, &image_format, stamp); IMB_freeImBuf(ibuf); } } else { - ImBuf *ibuf = RE_render_result_rect_to_ibuf(rr, &rd->im_format, dither, view_id); + ImBuf *ibuf = RE_render_result_rect_to_ibuf(rr, &image_format, dither, view_id); - IMB_colormanagement_imbuf_for_write( - ibuf, true, false, &scene->view_settings, &scene->display_settings, &rd->im_format); + IMB_colormanagement_imbuf_for_write(ibuf, true, false, &image_format); ok = image_render_write_stamp_test( - reports, scene, rr, ibuf, filepath, &rd->im_format, stamp); + reports, scene, rr, ibuf, filepath, &image_format, stamp); /* imbuf knows which rects are not part of ibuf */ IMB_freeImBuf(ibuf); @@ -722,12 +718,12 @@ bool BKE_image_render_write(ReportList *reports, } } else { /* R_IMF_VIEWS_STEREO_3D */ - BLI_assert(rd->im_format.views_format == R_IMF_VIEWS_STEREO_3D); + BLI_assert(image_format.views_format == R_IMF_VIEWS_STEREO_3D); char filepath[FILE_MAX]; STRNCPY(filepath, filename); - if (rd->im_format.imtype == R_IMF_IMTYPE_MULTILAYER) { + if (image_format.imtype == R_IMF_IMTYPE_MULTILAYER) { printf("Stereo 3D not supported for MultiLayer image: %s\n", filepath); } else { @@ -737,34 +733,29 @@ bool BKE_image_render_write(ReportList *reports, for (i = 0; i < 2; i++) { int view_id = BLI_findstringindex(&rr->views, names[i], offsetof(RenderView, name)); - ibuf_arr[i] = RE_render_result_rect_to_ibuf(rr, &rd->im_format, dither, view_id); - IMB_colormanagement_imbuf_for_write(ibuf_arr[i], - true, - false, - &scene->view_settings, - &scene->display_settings, - &rd->im_format); + ibuf_arr[i] = RE_render_result_rect_to_ibuf(rr, &image_format, dither, view_id); + IMB_colormanagement_imbuf_for_write(ibuf_arr[i], true, false, &image_format); IMB_prepare_write_ImBuf(IMB_isfloat(ibuf_arr[i]), ibuf_arr[i]); } - ibuf_arr[2] = IMB_stereo3d_ImBuf(&rd->im_format, ibuf_arr[0], ibuf_arr[1]); + ibuf_arr[2] = IMB_stereo3d_ImBuf(&image_format, ibuf_arr[0], ibuf_arr[1]); ok = image_render_write_stamp_test( - reports, scene, rr, ibuf_arr[2], filepath, &rd->im_format, stamp); + reports, scene, rr, ibuf_arr[2], filepath, &image_format, stamp); /* optional preview images for exr */ - if (ok && is_exr_rr && (rd->im_format.flag & R_IMF_FLAG_PREVIEW_JPG)) { - ImageFormatData imf = rd->im_format; - imf.imtype = R_IMF_IMTYPE_JPEG90; + if (ok && is_exr_rr && (image_format.flag & R_IMF_FLAG_PREVIEW_JPG)) { + image_format.imtype = R_IMF_IMTYPE_JPEG90; if (BLI_path_extension_check(filepath, ".exr")) { filepath[strlen(filepath) - 4] = 0; } - BKE_image_path_ensure_ext_from_imformat(filepath, &imf); + BKE_image_path_ensure_ext_from_imformat(filepath, &image_format); ibuf_arr[2]->planes = 24; - ok = image_render_write_stamp_test(reports, scene, rr, ibuf_arr[2], filepath, &imf, stamp); + ok = image_render_write_stamp_test( + reports, scene, rr, ibuf_arr[2], filepath, &image_format, stamp); } /* imbuf knows which rects are not part of ibuf */ @@ -774,5 +765,7 @@ bool BKE_image_render_write(ReportList *reports, } } + BKE_image_format_free(&image_format); + return ok; } |