Color management: Use default view with no extra transform when not specified
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 6 Dec 2018 11:21:37 +0000 (12:21 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 6 Dec 2018 11:31:50 +0000 (12:31 +0100)
source/blender/blenkernel/BKE_colortools.h
source/blender/blenkernel/intern/colortools.c
source/blender/blenkernel/intern/image.c
source/blender/imbuf/IMB_colormanagement.h
source/blender/imbuf/intern/IMB_colormanagement_intern.h
source/blender/imbuf/intern/colormanagement.c

index d509bf5eb6c0a6166b14cecca6f8405340e49515..aa3721d7a142cb37561693dc213489112a5a665d 100644 (file)
@@ -107,6 +107,12 @@ void BKE_color_managed_view_settings_init_render(
         struct ColorManagedViewSettings *settings,
         const struct ColorManagedDisplaySettings *display_settings);
 
+/* Initialize view settings which are best suitable for viewing non-render
+ * images. For example,s movie clips while tracking. */
+void BKE_color_managed_view_settings_init_default(
+        struct ColorManagedViewSettings *settings,
+        const struct ColorManagedDisplaySettings *display_settings);
+
 void BKE_color_managed_view_settings_copy(
         struct ColorManagedViewSettings *new_settings,
         const struct ColorManagedViewSettings *settings);
index d86dddd4e399daee69d6ec5b3b00f87e048053c4..554a5a63b1a7f41654e28cfb7e70496765cff712 100644 (file)
@@ -1588,6 +1588,14 @@ void BKE_color_managed_view_settings_init_render(
        view_settings->exposure = 0.0f;
 }
 
+void BKE_color_managed_view_settings_init_default(
+        struct ColorManagedViewSettings *view_settings,
+        const struct ColorManagedDisplaySettings *display_settings)
+{
+       IMB_colormanagement_init_default_view_settings(
+               view_settings, display_settings);
+}
+
 void BKE_color_managed_view_settings_copy(ColorManagedViewSettings *new_settings,
                                           const ColorManagedViewSettings *settings)
 {
index e08ca35aca8d61a8cf42d48f20bb21dab0a6f670..67dca475650a9838c42abb9f8d6323c17573331c 100644 (file)
@@ -1402,8 +1402,8 @@ void BKE_imformat_defaults(ImageFormatData *im_format)
        im_format->compress = 15;
 
        BKE_color_managed_display_settings_init(&im_format->display_settings);
-       BKE_color_managed_view_settings_init_render(&im_format->view_settings,
-                                                   &im_format->display_settings);
+       BKE_color_managed_view_settings_init_default(&im_format->view_settings,
+                                                    &im_format->display_settings);
 }
 
 void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *imbuf)
index 1a224639366cff45353c8870413d6646305df87d..8c903af2420cb57e438f78754d0d858c963855de 100644 (file)
@@ -222,6 +222,11 @@ bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C
 /* Finish GLSL-based display space conversion */
 void IMB_colormanagement_finish_glsl_draw(void);
 
+/* ** View transform ** */
+void IMB_colormanagement_init_default_view_settings(
+        struct ColorManagedViewSettings *view_settings,
+        const struct ColorManagedDisplaySettings *display_settings);
+
 /* Roles */
 enum {
        COLOR_ROLE_SCENE_LINEAR = 0,
index 0b4557e7bef9cde8c34d5b0e3d9c6a29e6c90c4b..84e0bd6c599a0d3e44a518c5f689af821dc65d31 100644 (file)
@@ -103,6 +103,8 @@ struct ColorManagedView *colormanage_view_get_default(const ColorManagedDisplay
 struct ColorManagedView *colormanage_view_add(const char *name);
 struct ColorManagedView *colormanage_view_get_indexed(int index);
 struct ColorManagedView *colormanage_view_get_named(const char *name);
+struct ColorManagedView *colormanage_view_get_named_for_display(
+        const char *display_name, const char *name);
 
 struct ColorSpace *colormanage_colorspace_add(const char *name, const char *description, bool is_invertible, bool is_data);
 struct ColorSpace *colormanage_colorspace_get_named(const char *name);
index f9c0f6754478731221121ec98125c2f9fc30d67b..5d0e59e17881a718d6ae80d82416bd171164b5a3 100644 (file)
@@ -930,23 +930,33 @@ static OCIO_ConstProcessorRcPtr *display_to_scene_linear_processor(ColorManagedD
        return (OCIO_ConstProcessorRcPtr *) display->to_scene_linear;
 }
 
-static void init_render_view_settings(const ColorManagedDisplaySettings *display_settings,
-                                      ColorManagedViewSettings *view_settings)
-{
-       ColorManagedDisplay *display;
-       ColorManagedView *default_view = NULL;
-
-       display = colormanage_display_get_named(display_settings->display_device);
-
-       if (display)
-               default_view = colormanage_view_get_default(display);
-
-       if (default_view)
-               BLI_strncpy(view_settings->view_transform, default_view->name, sizeof(view_settings->view_transform));
-       else
+void IMB_colormanagement_init_default_view_settings(
+        ColorManagedViewSettings *view_settings,
+        const ColorManagedDisplaySettings *display_settings)
+{
+       /* First, try use "Default" view transform of the requested device. */
+       ColorManagedView *default_view = colormanage_view_get_named_for_display(
+               display_settings->display_device, "Default");
+       /* If that fails, we fall back to the default view transform of the display
+        * as per OCIO configuration. */
+       if (default_view == NULL) {
+               ColorManagedDisplay *display = colormanage_display_get_named(
+                       display_settings->display_device);
+               if (display != NULL) {
+                       default_view = colormanage_view_get_default(display);
+               }
+       }
+       if (default_view != NULL) {
+               BLI_strncpy(view_settings->view_transform,
+                           default_view->name,
+                           sizeof(view_settings->view_transform));
+       }
+       else {
                view_settings->view_transform[0] = '\0';
-
+       }
+       /* TODO(sergey): Find a way to safely/reliable un-hardcode this. */
        BLI_strncpy(view_settings->look, "None", sizeof(view_settings->look));
+       /* Initialize rest of the settings. */
        view_settings->flag = 0;
        view_settings->gamma = 1.0f;
        view_settings->exposure = 0.0f;
@@ -2138,11 +2148,10 @@ unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf, const ColorManagedViewSet
                applied_view_settings = view_settings;
        }
        else {
-               /* if no view settings were specified, use default display transformation
-                * this happens for images which don't want to be displayed with render settings
-                */
-
-               init_render_view_settings(display_settings,  &default_view_settings);
+               /* If no view settings were specified, use default ones, which will
+                * attempt not to do any extra color correction. */
+               IMB_colormanagement_init_default_view_settings(
+                       &default_view_settings, display_settings);
                applied_view_settings = &default_view_settings;
        }
 
@@ -2427,6 +2436,22 @@ ColorManagedView *colormanage_view_get_indexed(int index)
        return BLI_findlink(&global_views, index - 1);
 }
 
+ColorManagedView *colormanage_view_get_named_for_display(
+        const char *display_name, const char *name)
+{
+       ColorManagedDisplay *display = colormanage_display_get_named(display_name);
+       if (display == NULL) {
+               return NULL;
+       }
+       LISTBASE_FOREACH(LinkData *, view_link, &display->views) {
+               ColorManagedView *view = view_link->data;
+               if (STRCASEEQ(name, view->name)) {
+                       return view;
+               }
+       }
+       return NULL;
+}
+
 int IMB_colormanagement_view_get_named_index(const char *name)
 {
        ColorManagedView *view = colormanage_view_get_named(name);
@@ -3144,7 +3169,8 @@ ColormanageProcessor *IMB_colormanagement_display_processor_new(const ColorManag
                applied_view_settings = view_settings;
        }
        else {
-               init_render_view_settings(display_settings,  &default_view_settings);
+               IMB_colormanagement_init_default_view_settings(
+                       &default_view_settings, display_settings);
                applied_view_settings = &default_view_settings;
        }
 
@@ -3441,11 +3467,10 @@ bool IMB_colormanagement_setup_glsl_draw_from_space(const ColorManagedViewSettin
                applied_view_settings = view_settings;
        }
        else {
-               /* if no view settings were specified, use default display transformation
-                * this happens for images which don't want to be displayed with render settings
-                */
-
-               init_render_view_settings(display_settings,  &default_view_settings);
+               /* If no view settings were specified, use default ones, which will
+                * attempt not to do any extra color correction. */
+               IMB_colormanagement_init_default_view_settings(
+                       &default_view_settings, display_settings);
                applied_view_settings = &default_view_settings;
        }