[Bf-blender-cvs] [3b5224b57c3] master: Cleanup: refactor passing of color management settings for image save

Brecht Van Lommel noreply at git.blender.org
Tue Mar 22 14:19:02 CET 2022


Commit: 3b5224b57c3cfc39a7998ecfc482e13bd6940e68
Author: Brecht Van Lommel
Date:   Fri Mar 11 18:21:05 2022 +0100
Branches: master
https://developer.blender.org/rB3b5224b57c3cfc39a7998ecfc482e13bd6940e68

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

===================================================================

M	source/blender/blenkernel/BKE_image_format.h
M	source/blender/blenkernel/intern/image_format.cc
M	source/blender/blenkernel/intern/image_save.cc
M	source/blender/compositor/COM_compositor.h
M	source/blender/compositor/intern/COM_CompositorContext.cc
M	source/blender/compositor/intern/COM_CompositorContext.h
M	source/blender/compositor/intern/COM_ExecutionSystem.cc
M	source/blender/compositor/intern/COM_ExecutionSystem.h
M	source/blender/compositor/intern/COM_NodeOperationBuilder.cc
M	source/blender/compositor/intern/COM_compositor.cc
M	source/blender/compositor/nodes/COM_OutputFileNode.cc
M	source/blender/compositor/nodes/COM_SplitViewerNode.cc
M	source/blender/compositor/nodes/COM_TextureNode.cc
M	source/blender/compositor/nodes/COM_ViewerNode.cc
M	source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc
M	source/blender/compositor/operations/COM_OutputFileMultiViewOperation.h
M	source/blender/compositor/operations/COM_OutputFileOperation.cc
M	source/blender/compositor/operations/COM_OutputFileOperation.h
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_node/node_edit.cc
M	source/blender/imbuf/IMB_colormanagement.h
M	source/blender/imbuf/intern/colormanagement.c
M	source/blender/makesrna/intern/rna_image_api.c
M	source/blender/nodes/NOD_composite.h
M	source/blender/nodes/composite/node_composite_tree.cc
M	source/blender/render/intern/pipeline.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_image_format.h b/source/blender/blenkernel/BKE_image_format.h
index 189d2db1b4f..633af54ea4f 100644
--- a/source/blender/blenkernel/BKE_image_format.h
+++ b/source/blender/blenkernel/BKE_image_format.h
@@ -16,6 +16,7 @@ struct BlendWriter;
 struct ImbFormatOptions;
 struct ImageFormatData;
 struct ImBuf;
+struct Scene;
 
 /* Init/Copy/Free */
 
@@ -75,6 +76,22 @@ char BKE_imtype_from_arg(const char *arg);
 void BKE_image_format_from_imbuf(struct ImageFormatData *im_format, const struct ImBuf *imbuf);
 void BKE_image_format_to_imbuf(struct ImBuf *ibuf, const struct ImageFormatData *imf);
 
+/* Color Management */
+
+void BKE_image_format_color_management_copy(struct ImageFormatData *imf,
+                                            const struct ImageFormatData *imf_src);
+void BKE_image_format_color_management_copy_from_scene(struct ImageFormatData *imf,
+                                                       const struct Scene *scene);
+
+/* Image Output
+ *
+ * Initialize an image format that can be used for file writing, including
+ * color management settings from the scene. */
+
+void BKE_image_format_init_for_write(struct ImageFormatData *imf,
+                                     const struct Scene *scene_src,
+                                     const struct ImageFormatData *imf_src);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/image_format.cc b/source/blender/blenkernel/intern/image_format.cc
index f0400417ffc..49f9ca6418f 100644
--- a/source/blender/blenkernel/intern/image_format.cc
+++ b/source/blender/blenkernel/intern/image_format.cc
@@ -14,6 +14,7 @@
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
@@ -872,3 +873,39 @@ void BKE_image_format_from_imbuf(ImageFormatData *im_format, const ImBuf *imbuf)
   /* planes */
   im_format->planes = imbuf->planes;
 }
+
+/* Color Management */
+
+void BKE_image_format_color_management_copy(ImageFormatData *imf, const ImageFormatData *imf_src)
+{
+  BKE_color_managed_view_settings_free(&imf->view_settings);
+
+  BKE_color_managed_display_settings_copy(&imf->display_settings, &imf_src->display_settings);
+  BKE_color_managed_view_settings_copy(&imf->view_settings, &imf_src->view_settings);
+  BKE_color_managed_colorspace_settings_copy(&imf->linear_colorspace_settings,
+                                             &imf_src->linear_colorspace_settings);
+}
+
+void BKE_image_format_color_management_copy_from_scene(ImageFormatData *imf, const Scene *scene)
+{
+  BKE_color_managed_view_settings_free(&imf->view_settings);
+
+  BKE_color_managed_display_settings_copy(&imf->display_settings, &scene->display_settings);
+  BKE_color_managed_view_settings_copy(&imf->view_settings, &scene->view_settings);
+  STRNCPY(imf->linear_colorspace_settings.name,
+          IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR));
+}
+
+/* Output */
+
+void BKE_image_format_init_for_write(ImageFormatData *imf,
+                                     const Scene *scene_src,
+                                     const ImageFormatData *imf_src)
+{
+  *imf = (imf_src) ? *imf_src : scene_src->r.im_format;
+
+  /* Use general scene settings also used for display. */
+  BKE_color_managed_display_settings_copy(&imf->display_settings, &scene_src->display_settings);
+  BKE_color_managed_view_settings_copy(&imf->view_settings, &scene_src->view_settings);
+  BKE_color_managed_colorspace_settings_init(&imf->linear_colorspace_settings);
+}
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_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list