diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-03-18 23:28:04 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-03-21 18:38:13 +0300 |
commit | 8530e48f8692f4b92c43489029f2d2ef67c7cb62 (patch) | |
tree | d335479baf037b897ddf14f42c238184f65d0472 /source/blender/render/intern/pipeline.c | |
parent | b96462519f748fcf04028084354fbbf97eb8ce92 (diff) |
Cleanup: move render image and multilayer EXR write code to image_save.cc
These share a lot of logic with regular image saving and should be unified
more in the future.
Diffstat (limited to 'source/blender/render/intern/pipeline.c')
-rw-r--r-- | source/blender/render/intern/pipeline.c | 171 |
1 files changed, 7 insertions, 164 deletions
diff --git a/source/blender/render/intern/pipeline.c b/source/blender/render/intern/pipeline.c index 614c03eba11..0ca2ca82cf7 100644 --- a/source/blender/render/intern/pipeline.c +++ b/source/blender/render/intern/pipeline.c @@ -45,6 +45,7 @@ #include "BKE_global.h" #include "BKE_image.h" #include "BKE_image_format.h" +#include "BKE_image_save.h" #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_lib_remap.h" @@ -223,41 +224,6 @@ static void stats_background(void *UNUSED(arg), RenderStats *rs) fflush(stdout); } -static void render_print_save_message(ReportList *reports, const char *name, int ok, int err) -{ - if (ok) { - /* no need to report, just some helpful console info */ - printf("Saved: '%s'\n", name); - } - else { - /* report on error since users will want to know what failed */ - BKE_reportf(reports, RPT_ERROR, "Render error (%s) cannot save: '%s'", strerror(err), name); - } -} - -static int render_imbuf_write_stamp_test(ReportList *reports, - Scene *scene, - struct RenderResult *rr, - ImBuf *ibuf, - const char *name, - const ImageFormatData *imf, - bool stamp) -{ - int ok; - - if (stamp) { - /* writes the name of the individual cameras */ - ok = BKE_imbuf_write_stamp(scene, rr, ibuf, name, imf); - } - else { - ok = BKE_imbuf_write(ibuf, name, imf); - } - - render_print_save_message(reports, name, ok, errno); - - return ok; -} - void RE_FreeRenderResult(RenderResult *rr) { render_result_free(rr); @@ -1385,7 +1351,7 @@ static void do_render_sequencer(Render *re) if (ibuf_arr[view_id]) { /* copy ibuf into combined pixel rect */ - RE_render_result_rect_from_ibuf(rr, &re->r, ibuf_arr[view_id], view_id); + RE_render_result_rect_from_ibuf(rr, ibuf_arr[view_id], view_id); if (ibuf_arr[view_id]->metadata && (re->r.stamp & R_STAMP_STRIPMETA)) { /* ensure render stamp info first */ @@ -1979,129 +1945,6 @@ void RE_RenderFreestyleExternal(Render *re) /** \name Read/Write Render Result (Images & Movies) * \{ */ -bool RE_WriteRenderViewsImage( - ReportList *reports, RenderResult *rr, Scene *scene, const bool stamp, char *name) -{ - bool ok = true; - RenderData *rd = &scene->r; - - if (!rr) { - return false; - } - - bool is_mono = BLI_listbase_count_at_most(&rr->views, 2) < 2; - bool is_exr_rr = ELEM(rd->im_format.imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER) && - RE_HasFloatPixels(rr); - - if (rd->im_format.views_format == R_IMF_VIEWS_MULTIVIEW && is_exr_rr) { - ok = RE_WriteRenderResult(reports, rr, name, &rd->im_format, NULL, -1); - render_print_save_message(reports, name, ok, errno); - } - - /* mono, legacy code */ - else if (is_mono || (rd->im_format.views_format == R_IMF_VIEWS_INDIVIDUAL)) { - RenderView *rv; - int view_id; - char filepath[FILE_MAX]; - - BLI_strncpy(filepath, name, sizeof(filepath)); - - for (view_id = 0, rv = rr->views.first; rv; rv = rv->next, view_id++) { - if (!is_mono) { - BKE_scene_multiview_view_filepath_get(&scene->r, filepath, rv->name, name); - } - - if (is_exr_rr) { - ok = RE_WriteRenderResult(reports, rr, name, &rd->im_format, rv->name, -1); - render_print_save_message(reports, name, 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 (BLI_path_extension_check(name, ".exr")) { - name[strlen(name) - 4] = 0; - } - BKE_image_path_ensure_ext_from_imformat(name, &imf); - - ImBuf *ibuf = render_result_rect_to_ibuf(rr, rd, view_id); - ibuf->planes = 24; - IMB_colormanagement_imbuf_for_write( - ibuf, true, false, &scene->view_settings, &scene->display_settings, &imf); - - ok = render_imbuf_write_stamp_test(reports, scene, rr, ibuf, name, &imf, stamp); - - IMB_freeImBuf(ibuf); - } - } - else { - ImBuf *ibuf = render_result_rect_to_ibuf(rr, rd, view_id); - - IMB_colormanagement_imbuf_for_write( - ibuf, true, false, &scene->view_settings, &scene->display_settings, &rd->im_format); - - ok = render_imbuf_write_stamp_test(reports, scene, rr, ibuf, name, &rd->im_format, stamp); - - /* imbuf knows which rects are not part of ibuf */ - IMB_freeImBuf(ibuf); - } - } - } - else { /* R_IMF_VIEWS_STEREO_3D */ - BLI_assert(scene->r.im_format.views_format == R_IMF_VIEWS_STEREO_3D); - - if (rd->im_format.imtype == R_IMF_IMTYPE_MULTILAYER) { - printf("Stereo 3D not supported for MultiLayer image: %s\n", name); - } - else { - ImBuf *ibuf_arr[3] = {NULL}; - const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; - int i; - - for (i = 0; i < 2; i++) { - int view_id = BLI_findstringindex(&rr->views, names[i], offsetof(RenderView, name)); - ibuf_arr[i] = render_result_rect_to_ibuf(rr, rd, view_id); - IMB_colormanagement_imbuf_for_write(ibuf_arr[i], - true, - false, - &scene->view_settings, - &scene->display_settings, - &scene->r.im_format); - IMB_prepare_write_ImBuf(IMB_isfloat(ibuf_arr[i]), ibuf_arr[i]); - } - - ibuf_arr[2] = IMB_stereo3d_ImBuf(&scene->r.im_format, ibuf_arr[0], ibuf_arr[1]); - - ok = render_imbuf_write_stamp_test( - reports, scene, rr, ibuf_arr[2], name, &rd->im_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 (BLI_path_extension_check(name, ".exr")) { - name[strlen(name) - 4] = 0; - } - - BKE_image_path_ensure_ext_from_imformat(name, &imf); - ibuf_arr[2]->planes = 24; - - ok = render_imbuf_write_stamp_test( - reports, scene, rr, ibuf_arr[2], name, &rd->im_format, stamp); - } - - /* imbuf knows which rects are not part of ibuf */ - for (i = 0; i < 3; i++) { - IMB_freeImBuf(ibuf_arr[i]); - } - } - } - - return ok; -} - bool RE_WriteRenderViewsMovie(ReportList *reports, RenderResult *rr, Scene *scene, @@ -2111,20 +1954,20 @@ bool RE_WriteRenderViewsMovie(ReportList *reports, const int totvideos, bool preview) { - bool is_mono; bool ok = true; if (!rr) { return false; } - is_mono = BLI_listbase_count_at_most(&rr->views, 2) < 2; + const bool is_mono = BLI_listbase_count_at_most(&rr->views, 2) < 2; + const float dither = scene->r.dither_intensity; if (is_mono || (scene->r.im_format.views_format == R_IMF_VIEWS_INDIVIDUAL)) { int view_id; for (view_id = 0; view_id < totvideos; view_id++) { const char *suffix = BKE_scene_multiview_view_id_suffix_get(&scene->r, view_id); - ImBuf *ibuf = render_result_rect_to_ibuf(rr, &scene->r, view_id); + ImBuf *ibuf = RE_render_result_rect_to_ibuf(rr, &rd->im_format, dither, view_id); IMB_colormanagement_imbuf_for_write( ibuf, true, false, &scene->view_settings, &scene->display_settings, &scene->r.im_format); @@ -2153,7 +1996,7 @@ bool RE_WriteRenderViewsMovie(ReportList *reports, for (i = 0; i < 2; i++) { int view_id = BLI_findstringindex(&rr->views, names[i], offsetof(RenderView, name)); - ibuf_arr[i] = render_result_rect_to_ibuf(rr, &scene->r, view_id); + 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, @@ -2225,7 +2068,7 @@ static int do_write_image_or_movie(Render *re, } /* write images as individual images or stereo */ - ok = RE_WriteRenderViewsImage(re->reports, &rres, scene, true, name); + ok = BKE_image_render_write(re->reports, &rres, scene, true, name); } RE_ReleaseResultImageViews(re, &rres); |