Color management refactor
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 2 Jul 2012 16:37:40 +0000 (16:37 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 2 Jul 2012 16:37:40 +0000 (16:37 +0000)
- Move color management display settings into own structure like it's
  done for view settings.

  This is helpful from two sides:

  * It is planned to support display calibration settings which
    should be taken into account by color management stuff to
    add needed transformations to OCIO processor.
  * File saving should be able to make the same display
    transformations as it's done by window when displaying the image.
    Having own DNA and RNA structures for display device settings
    helps avoiding having duplicated code.

- Small refactor of cacheing functions which are now accepts
  cache-like versions of view and display settings. This structures
  used for cache are quite the same as DNA structures but they contains
  indices of view and display which avoids extra lookup for this
  things.

  This also helps having reasonable amount of variables passing
  to cache functions.

14 files changed:
release/scripts/startup/bl_ui/properties_color_management.py
release/scripts/startup/bl_ui/space_info.py
source/blender/blenkernel/BKE_colortools.h
source/blender/blenkernel/intern/colortools.c
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_image/image_draw.c
source/blender/editors/space_node/drawnode.c
source/blender/imbuf/IMB_colormanagement.h
source/blender/imbuf/intern/colormanagement.c
source/blender/makesdna/DNA_color_types.h
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/makesrna/intern/rna_color.c
source/blender/makesrna/intern/rna_wm.c
source/blender/windowmanager/intern/wm_window.c

index 3022631b46c91c714dd14d910cd703e682492118..eee8fddbef59e90fed4a30c4a3e35d332fb331b9 100644 (file)
@@ -25,6 +25,7 @@ class ColorManagedViewSettingsPanel:
 
         space = context.space_data
         window = context.window
+        display_settings = context.window.display_settings
         space_view_settings = space.view_settings
 
         if space_view_settings.use_global_settings:
@@ -34,7 +35,7 @@ class ColorManagedViewSettingsPanel:
 
         col = layout.column()
         col.prop(space_view_settings, "use_global_settings")
-        col.prop(window, "display_device", text="Display")
+        col.prop(display_settings, "display_device", text="Display")
         col.prop(view_settings, "view_transform", text="View")
 
         col = layout.column()
index 13ea0a07533217cdd29ab6545c66b4269702490e..af2907050b46b3017abf4251c23ca87184624073 100644 (file)
@@ -357,6 +357,7 @@ class INFO_MT_window(Menu):
         import sys
 
         window = context.window
+        display_settings = window.display_settings
 
         layout = self.layout
 
@@ -367,7 +368,7 @@ class INFO_MT_window(Menu):
             layout.operator("wm.console_toggle", icon='CONSOLE')
 
         layout.separator()
-        layout.prop_menu_enum(window, "display_device", text="Display")
+        layout.prop_menu_enum(display_settings, "display_device", text="Display")
 
 
 class INFO_MT_help(Menu):
index 2e1cfb988962f78c2de80aa9a3ec3a2ea3fd1cb0..345ec68f45702e61b54835054ff978e2a904baa5 100644 (file)
@@ -31,6 +31,7 @@
  *  \ingroup bke
  */
 
+struct ColorManagedDisplaySettings;
 struct ColorManagedViewSettings;
 struct CurveMapping;
 struct CurveMap;
@@ -81,6 +82,10 @@ void                scopes_update(struct Scopes *scopes, struct ImBuf *ibuf, int
 void                scopes_free(struct Scopes *scopes);
 void                scopes_new(struct Scopes *scopes);
 
+void BKE_color_managed_display_settings_init(struct ColorManagedDisplaySettings *settings);
+void BKE_color_managed_display_settings_copy(struct ColorManagedDisplaySettings *new_settings,
+                                             const struct ColorManagedDisplaySettings *settings);
+
 void BKE_color_managed_view_settings_init(struct ColorManagedViewSettings *settings);
 void BKE_color_managed_view_settings_copy(struct ColorManagedViewSettings *new_settings,
                                           const struct ColorManagedViewSettings *settings);
index 8e0f27090a1dac4e7bfe329cabe640df34cb952b..29ab82cc15370099522a252135644b4ae5cc43b6 100644 (file)
@@ -49,6 +49,7 @@
 #include "BKE_fcurve.h"
 
 
+#include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
@@ -1208,6 +1209,19 @@ void scopes_new(Scopes *scopes)
        scopes->vecscope = NULL;
 }
 
+void BKE_color_managed_display_settings_init(ColorManagedDisplaySettings *settings)
+{
+       const char *display_name = IMB_colormanagement_display_get_default_name();
+
+       BLI_strncpy(settings->display_device, display_name, sizeof(settings->display_device));
+}
+
+void BKE_color_managed_display_settings_copy(ColorManagedDisplaySettings *new_settings,
+                                             const ColorManagedDisplaySettings *settings)
+{
+       BLI_strncpy(new_settings->display_device, settings->display_device, sizeof(new_settings->display_device));
+}
+
 void BKE_color_managed_view_settings_init(ColorManagedViewSettings *settings)
 {
        /* OCIO_TODO: use default view transform here when OCIO is completely integrated
@@ -1223,5 +1237,8 @@ void BKE_color_managed_view_settings_init(ColorManagedViewSettings *settings)
 void BKE_color_managed_view_settings_copy(ColorManagedViewSettings *new_settings,
                                           const ColorManagedViewSettings *settings)
 {
-       *new_settings = *settings;
+       BLI_strncpy(new_settings->view_transform, new_settings->view_transform, sizeof(new_settings->view_transform));
+
+       new_settings->exposure = settings->exposure;
+       new_settings->gamma = settings->gamma;
 }
index c293b699a41b17c59a909a72ab4b54520d7ef449..61834b19da421ec3647558b916c6d0cd908498f6 100644 (file)
@@ -273,7 +273,7 @@ static void draw_movieclip_buffer(wmWindow *win, SpaceClip *sc, ARegion *ar, ImB
                verify_buffer_float(ibuf);
 
                view_settings = IMB_view_settings_get_effective(win, &sc->view_settings);
-               display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, win->display_device, &cache_handle);
+               display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, &win->display_settings, &cache_handle);
 
                if (display_buffer) {
                        int need_fallback = 1;
index fa686608bc890afbc171a0e0f2f88a4a8a337f7f..a4211508ae4489f61ad553e6b26a5db5ea4e8ffe 100644 (file)
@@ -463,7 +463,7 @@ static void draw_image_buffer(wmWindow *win, SpaceImage *sima, ARegion *ar, Scen
                image_verify_buffer_float(ima, ibuf, color_manage);
 
                view_settings = IMB_view_settings_get_effective(win, &sima->view_settings);
-               display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, win->display_device, &cache_handle);
+               display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, &win->display_settings, &cache_handle);
 
                if (display_buffer)
                        glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer);
index 3af688dfca74e1812d09a13fe8b65cb20c2d2ae1..3f77623c928f0c406e82633d92fd2616979ce3c4 100644 (file)
@@ -2986,7 +2986,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode)
                        
 
                        view_settings = IMB_view_settings_get_effective(win, &snode->view_settings);
-                       display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, win->display_device, &cache_handle);
+                       display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, &win->display_settings, &cache_handle);
 
                        if (display_buffer) {
                                if (snode->flag & SNODE_SHOW_ALPHA) {
index d2c0a8f579b4c50ab912a328e14f747dc5fa88f4..70f0a7374af395fa19b4f652fd649a1543a0ad15 100644 (file)
@@ -33,6 +33,7 @@
 
 #define BCM_CONFIG_FILE "config.ocio"
 
+struct ColorManagedDisplaySettings;
 struct ColorManagedViewSettings;
 struct EnumPropertyItem;
 struct ImBuf;
@@ -54,7 +55,7 @@ void IMB_colormanage_flags_free(struct ImBuf *ibuf);
 void IMB_colormanage_cache_data_free(struct ImBuf *ibuf);
 
 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
-                                          const char *display, void **cache_handle);
+                                          const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
 void IMB_display_buffer_release(void *cache_handle);
 
 void IMB_display_buffer_invalidate(struct ImBuf *ibuf);
@@ -67,6 +68,7 @@ const struct ColorManagedViewSettings *IMB_view_settings_get_effective(struct wm
 /* ** Display funcrions ** */
 int IMB_colormanagement_display_get_named_index(const char *name);
 const char *IMB_colormanagement_display_get_indexed_name(int index);
+const char *IMB_colormanagement_display_get_default_name(void);
 
 /* ** View funcrions ** */
 int IMB_colormanagement_view_get_named_index(const char *name);
index 981c56c0f162d0e999025c7296246a34e773860a..ec2bd0b466840f33d43f487bb1556cb015e422d1 100644 (file)
@@ -124,9 +124,28 @@ static int global_tot_view = 0;
  *   becoming zero, original ImBuf is being freed completely.
  */
 
+/* NOTE: ColormanageCacheViewSettings and ColormanageCacheDisplaySettings are
+ *       quite the same as ColorManagedViewSettings and ColorManageDisplaySettings
+ *       but they holds indexes of all transformations and color spaces, not
+ *       their names.
+ *
+ *       This helps avoid extra colorsmace / display / view lookup without
+ *       requiring to pass all variables which affects on display buffer
+ *       to color management cache system and keeps calls small and nice.
+ */
+typedef struct ColormanageCacheViewSettings {
+       int view;
+       float exposure;
+       float gamma;
+} ColormanageCacheViewSettings;
+
+typedef struct ColormanageCacheDisplaySettings {
+       int display;
+} ColormanageCacheDisplaySettings;
+
 typedef struct ColormanageCacheKey {
        ImBuf *ibuf;         /* image buffer for which display buffer was created */
-       int view_transform;  /* view transformation used for display buffer */
+       int view;            /* view transformation used for display buffer */
        int display;         /* display device name */
 } ColormanageCacheKey;
 
@@ -156,9 +175,9 @@ static int colormanage_hashcmp(const void *av, const void *bv)
        else if (a->ibuf > b->ibuf)
                return 1;
 
-       if (a->view_transform < b->view_transform)
+       if (a->view < b->view)
                return -1;
-       else if (a->view_transform > b->view_transform)
+       else if (a->view > b->view)
                return 1;
 
        if (a->display < b->display)
@@ -201,28 +220,62 @@ static void colormanage_cache_exit(void)
 }
 
 #ifdef WITH_OCIO
-static ImBuf *colormanage_cache_get_ibuf(ImBuf *ibuf, int view_transform, int display, void **cache_handle)
+static void colormanage_view_settings_to_cache(ColormanageCacheViewSettings *cache_view_settings,
+                                               const ColorManagedViewSettings *view_settings)
+{
+       int view = IMB_colormanagement_view_get_named_index(view_settings->view_transform);
+
+       cache_view_settings->view = view;
+       cache_view_settings->exposure = view_settings->exposure;
+       cache_view_settings->gamma = view_settings->gamma;
+}
+
+static void colormanage_display_settings_to_cache(ColormanageCacheDisplaySettings *cache_display_settings,
+                                                  const ColorManagedDisplaySettings *display_settings)
+{
+       int display = IMB_colormanagement_display_get_named_index(display_settings->display_device);
+
+       cache_display_settings->display = display;
+}
+
+static void colormanage_settings_to_key(ColormanageCacheKey *key, ImBuf *ibuf,
+                                        const ColormanageCacheViewSettings *view_settings,
+                                        const ColormanageCacheDisplaySettings *display_settings)
+{
+       key->ibuf = ibuf;
+       key->view = view_settings->view;
+       key->display = display_settings->display;
+}
+
+static ImBuf *colormanage_cache_get_ibuf(ColormanageCacheKey *key, void **cache_handle)
 {
        ImBuf *cache_ibuf;
-       ColormanageCacheKey key;
 
        *cache_handle = NULL;
 
-       key.ibuf = ibuf;
-       key.view_transform = view_transform;
-       key.display = display;
-
-       cache_ibuf = IMB_moviecache_get(colormanage_cache, &key);
+       cache_ibuf = IMB_moviecache_get(colormanage_cache, key);
 
        *cache_handle = cache_ibuf;
 
        return cache_ibuf;
 }
 
-static unsigned char *colormanage_cache_get(ImBuf *ibuf, int view_transform, int display,
-                                            float exposure, float gamma, void **cache_handle)
+static unsigned char *colormanage_cache_get(ImBuf *ibuf, const ColormanageCacheViewSettings *view_settings,
+                                            const ColormanageCacheDisplaySettings *display_settings,
+                                            void **cache_handle)
 {
-       ImBuf *cache_ibuf = colormanage_cache_get_ibuf(ibuf, view_transform, display, cache_handle);
+       ColormanageCacheKey key;
+       ImBuf *cache_ibuf;
+       int view_flag = 1 << (view_settings->view - 1);
+
+       colormanage_settings_to_key(&key, ibuf, view_settings, display_settings);
+
+       /* check whether image was marked as dirty for requested transform */
+       if ((ibuf->display_buffer_flags[display_settings->display - 1] & view_flag) == 0) {
+               return NULL;
+       }
+
+       cache_ibuf = colormanage_cache_get_ibuf(&key, cache_handle);
 
        if (cache_ibuf) {
                ColormnaageCacheImBufData *cache_data;
@@ -235,7 +288,10 @@ static unsigned char *colormanage_cache_get(ImBuf *ibuf, int view_transform, int
                 * different from requested buffer should be re-generated
                 */
                cache_data = (ColormnaageCacheImBufData *) cache_ibuf->colormanage_cache_data;
-               if (cache_data->exposure != exposure || cache_data->gamma != gamma) {
+
+               if (cache_data->exposure != view_settings->exposure ||
+                       cache_data->gamma != view_settings->gamma)
+               {
                        IMB_freeImBuf(cache_ibuf);
 
                        return NULL;
@@ -247,16 +303,19 @@ static unsigned char *colormanage_cache_get(ImBuf *ibuf, int view_transform, int
        return NULL;
 }
 
-static void colormanage_cache_put(ImBuf *ibuf, int view_transform, int display, float exposure, float gamma,
+static void colormanage_cache_put(ImBuf *ibuf, const ColormanageCacheViewSettings *view_settings,
+                                  const ColormanageCacheDisplaySettings *display_settings,
                                   unsigned char *display_buffer, void **cache_handle)
 {
        ColormanageCacheKey key;
        ImBuf *cache_ibuf;
        ColormnaageCacheImBufData *cache_data;
+       int view_flag = 1 << (view_settings->view - 1);
 
-       key.ibuf = ibuf;
-       key.view_transform = view_transform;
-       key.display = display;
+       colormanage_settings_to_key(&key, ibuf, view_settings, display_settings);
+
+       /* mark display buffer as valid */
+       ibuf->display_buffer_flags[display_settings->display - 1] |= view_flag;
 
        /* buffer itself */
        cache_ibuf = IMB_allocImBuf(ibuf->x, ibuf->y, ibuf->planes, 0);
@@ -267,8 +326,8 @@ static void colormanage_cache_put(ImBuf *ibuf, int view_transform, int display,
 
        /* store data which is needed to check whether cached buffer could be used for color managed display settings */
        cache_data = MEM_callocN(sizeof(ColormnaageCacheImBufData), "color manage cache imbuf data");
-       cache_data->exposure = exposure;
-       cache_data->gamma = gamma;
+       cache_data->exposure = view_settings->exposure;
+       cache_data->gamma = view_settings->gamma;
 
        cache_ibuf->colormanage_cache_data = cache_data;
 
@@ -295,24 +354,33 @@ static void colormanage_cache_put(ImBuf *ibuf, int view_transform, int display,
  * used by partial buffer update functions which uses the same exposure / gamma
  * settings as cached buffer had
  */
-static unsigned char *colormanage_cache_get_validated(ImBuf *ibuf, int view_transform, int display, void **cache_handle)
+static unsigned char *colormanage_cache_get_validated(ImBuf *ibuf, const ColormanageCacheViewSettings *view_settings,
+                                                      const ColormanageCacheDisplaySettings *display_settings,
+                                                      void **cache_handle)
 {
-       ImBuf *cache_ibuf = colormanage_cache_get_ibuf(ibuf, view_transform, display, cache_handle);
+       ColormanageCacheKey key;
+       ImBuf *cache_ibuf;
+
+       colormanage_settings_to_key(&key, ibuf, view_settings, display_settings);
+
+       cache_ibuf = colormanage_cache_get_ibuf(&key, cache_handle);
 
        if (cache_ibuf) {
                if (cache_ibuf->x != ibuf->x || cache_ibuf->y != ibuf->y) {
+                       ColormanageCacheViewSettings new_view_settings = *view_settings;
                        ColormnaageCacheImBufData *cache_data;
                        unsigned char *display_buffer;
                        int buffer_size;
 
                        /* use the same settings as original cached buffer  */
                        cache_data = (ColormnaageCacheImBufData *) cache_ibuf->colormanage_cache_data;
+                       new_view_settings.exposure = cache_data->exposure;
+                       new_view_settings.gamma = cache_data->gamma;
 
                        buffer_size = ibuf->channels * ibuf->x * ibuf->y * sizeof(float);
                        display_buffer = MEM_callocN(buffer_size, "imbuf validated display buffer");
 
-                       colormanage_cache_put(ibuf, view_transform, display, cache_data->exposure, cache_data->gamma,
-                                             display_buffer, cache_handle);
+                       colormanage_cache_put(ibuf, &new_view_settings, display_settings, display_buffer, cache_handle);
 
                        IMB_freeImBuf(cache_ibuf);
 
@@ -700,12 +768,13 @@ static ConstProcessorRcPtr *create_display_buffer_processor(const char *view_tra
 
 static void display_buffer_apply_ocio(ImBuf *ibuf, unsigned char *display_buffer,
                                       const ColorManagedViewSettings *view_settings,
-                                      const char *display)
+                                      const ColorManagedDisplaySettings *display_settings)
 {
        ConstProcessorRcPtr *processor;
        const float gamma = view_settings->gamma;
        const float exposure = view_settings->exposure;
        const char *view_transform = view_settings->view_transform;
+       const char *display = display_settings->display_device;
        float *rect_float;
 
        rect_float = MEM_dupallocN(ibuf->rect_float);
@@ -750,7 +819,7 @@ void IMB_colormanage_cache_data_free(ImBuf *ibuf)
 }
 
 unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf, const ColorManagedViewSettings *view_settings,
-                                          const char *display, void **cache_handle)
+                                          const ColorManagedDisplaySettings *display_settings, void **cache_handle)
 {
        const char *view_transform = view_settings->view_transform;
 
@@ -780,25 +849,20 @@ unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf, const ColorManagedViewSet
        else {
                unsigned char *display_buffer;
                int buffer_size;
-               int view_transform_index = IMB_colormanagement_view_get_named_index(view_transform);
-               int display_index = IMB_colormanagement_display_get_named_index(display);
-               int view_transform_flag = 1 << (view_transform_index - 1);
+               ColormanageCacheViewSettings cache_view_settings;
+               ColormanageCacheDisplaySettings cache_display_settings;
 
-               float exposure = view_settings->exposure;
-               float gamma = view_settings->gamma;
+               colormanage_view_settings_to_cache(&cache_view_settings, view_settings);
+               colormanage_display_settings_to_cache(&cache_display_settings, display_settings);
 
                /* ensure color management bit fields exists */
                if (!ibuf->display_buffer_flags)
                        IMB_colormanage_flags_allocate(ibuf);
 
-               /* check whether display buffer isn't marked as dirty and if so try to get buffer from cache */
-               if (ibuf->display_buffer_flags[display_index - 1] & view_transform_flag) {
-                       display_buffer = colormanage_cache_get(ibuf, view_transform_index, display_index,
-                                                              exposure, gamma, cache_handle);
+               display_buffer = colormanage_cache_get(ibuf, &cache_view_settings, &cache_display_settings, cache_handle);
 
-                       if (display_buffer) {
-                               return display_buffer;
-                       }
+               if (display_buffer) {
+                       return display_buffer;
                }
 
                /* OCIO_TODO: in case when image is being resized it is possible
@@ -819,13 +883,10 @@ unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf, const ColorManagedViewSet
                        display_buffer_apply_tonemap(ibuf, display_buffer, IMB_ratio_preserving_odt_tonecurve);
                }
                else {
-                       display_buffer_apply_ocio(ibuf, display_buffer, view_settings, display);
+                       display_buffer_apply_ocio(ibuf, display_buffer, view_settings, display_settings);
                }
 
-               colormanage_cache_put(ibuf, view_transform_index, display_index, exposure, gamma,
-                                     display_buffer, cache_handle);
-
-               ibuf->display_buffer_flags[display_index - 1] |= view_transform_flag;
+               colormanage_cache_put(ibuf, &cache_view_settings, &cache_display_settings, display_buffer, cache_handle);
 
                return display_buffer;
        }
@@ -836,7 +897,7 @@ unsigned char *IMB_display_buffer_acquire(ImBuf *ibuf, const ColorManagedViewSet
 
        (void) view_settings;
        (void) view_transform;
-       (void) display;
+       (void) display_settings;
 
        if (!ibuf->rect) {
                IMB_rect_from_float(ibuf);
@@ -864,6 +925,25 @@ void IMB_display_buffer_invalidate(ImBuf *ibuf)
 }
 
 #ifdef WITH_OCIO
+static void colormanage_check_display_settings(ColorManagedDisplaySettings *display_settings,
+                                               const ColorManagedDisplay *default_display)
+{
+       if (display_settings->display_device[0] == '\0') {
+               BLI_strncpy(display_settings->display_device, default_display->name, sizeof(display_settings->display_device));
+       }
+       else {
+               ColorManagedDisplay *display = colormanage_display_get_named(display_settings->display_device);
+
+               if (!display) {
+                       printf("Blender color management: Window display \"%s\" not found, setting to default (\"%s\").\n",
+                               display_settings->display_device, default_display->name);
+
+                       BLI_strncpy(display_settings->display_device, default_display->name,
+                                   sizeof(display_settings->display_device));
+               }
+       }
+}
+
 static void colormanage_check_view_settings(ColorManagedViewSettings *view_settings, const char *editor,
                                             const ColorManagedView *default_view)
 {
@@ -919,19 +999,7 @@ void IMB_colormanagement_check_file_config(Main *bmain)
 
        if (wm) {
                for (win = wm->windows.first; win; win = win->next) {
-                       if (win->display_device[0] == '\0') {
-                               BLI_strncpy(win->display_device, default_display->name, sizeof(win->display_device));
-                       }
-                       else {
-                               ColorManagedDisplay *display = colormanage_display_get_named(win->display_device);
-
-                               if (!display) {
-                                       printf("Blender color management: Window display \"%s\" not found, setting to default (\"%s\").\n",
-                                                  win->display_device, default_display->name);
-
-                                       BLI_strncpy(win->display_device, default_display->name, sizeof(win->display_device));
-                               }
-                       }
+                       colormanage_check_display_settings(&win->display_settings, default_display);
 
                        colormanage_check_view_settings(&win->view_settings, "window", default_view);
                }
@@ -1068,6 +1136,17 @@ const char *IMB_colormanagement_display_get_indexed_name(int index)
        return NULL;
 }
 
+const char *IMB_colormanagement_display_get_default_name(void)
+{
+#ifdef WITH_OCIO
+       ColorManagedDisplay *display = colormanage_display_get_default();
+
+       return display->name;
+#else
+       return NULL;
+#endif
+}
+
 /*********************** View functions *************************/
 
 #ifdef WITH_OCIO
@@ -1264,18 +1343,25 @@ PartialBufferUpdateContext *IMB_partial_buffer_update_context_new(ImBuf *ibuf)
        }
 
        for (display = 0; display < global_tot_display; display++) {
+               ColormanageCacheDisplaySettings display_settings = {0};
                int display_index = display + 1; /* displays in configuration are 1-based */
                const char *display_name = IMB_colormanagement_display_get_indexed_name(display_index);
                int view_flags = ibuf->display_buffer_flags[display];
                int view = 0;
 
+               display_settings.display = display_index;
+
                while (view_flags != 0) {
                        if (view_flags % 2 == 1) {
+                               ColormanageCacheViewSettings view_settings = {0};
                                unsigned char *display_buffer;
                                void *cache_handle;
                                int view_index = view + 1; /* views in configuration are 1-based */
 
-                               display_buffer = colormanage_cache_get_validated(ibuf, view_index, display_index, &cache_handle);
+                               view_settings.view = view_index;
+
+                               display_buffer =
+                                       colormanage_cache_get_validated(ibuf, &view_settings, &display_settings, &cache_handle);
 
                                if (display_buffer) {
                                        PartialBufferUpdateItem *item;
index cc9c6bd9aec0aabc62e232d0b73a286d9b14aeb8..b0f51747e8d33f707e7802a80f4ee874f64ad3db 100644 (file)
@@ -169,5 +169,9 @@ enum {
        COLORMANAGE_VIEW_USE_GLOBAL = (1 << 0)    /* use global display settings instead of per-space setting */
 };
 
+typedef struct ColorManagedDisplaySettings {
+       char display_device[64];
+} ColorManagedDisplaySettings;
+
 #endif
 
index 65685a7a419e3ca4d879a5720be34873588c1f00..31f53966c69fc5cb4fa1fe715cbf649abd3bb846 100644 (file)
@@ -199,8 +199,8 @@ typedef struct wmWindow {
 
        /* color management */
 
-       char display_device[64];        /* color managed display device name */
-       ColorManagedViewSettings view_settings;  /* global view settings */
+       ColorManagedDisplaySettings display_settings;  /* display-specific settings */
+       ColorManagedViewSettings view_settings;        /* global view settings */
        int pad1;
 } wmWindow;
 
index 56e16a29981d3d078bc2c837c3d80d02d4abb1e2..32bcbd59b8431f836ae9be2d48d0a6d529921dbb 100644 (file)
@@ -344,6 +344,36 @@ static void rna_Scopes_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointer
        s->ok = 0;
 }
 
+static int rna_ColorManagedDisplaySettings_display_device_get(struct PointerRNA *ptr)
+{
+       ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
+
+       return IMB_colormanagement_display_get_named_index(display->display_device);
+}
+
+static void rna_ColorManagedDisplaySettings_display_device_set(struct PointerRNA *ptr, int value)
+{
+       ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
+       const char *name = IMB_colormanagement_display_get_indexed_name(value);
+
+       if (name) {
+               BLI_strncpy(display->display_device, name, sizeof(display->display_device));
+       }
+}
+
+static EnumPropertyItem *rna_ColorManagedDisplaySettings_display_device_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
+{
+       EnumPropertyItem *items = NULL;
+       int totitem = 0;
+
+       IMB_colormanagement_display_items_add(&items, &totitem);
+       RNA_enum_item_end(&items, &totitem);
+
+       *free = TRUE;
+
+       return items;
+}
+
 static int rna_ColorManagedViewSettings_view_transform_get(PointerRNA *ptr)
 {
        ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
@@ -366,10 +396,11 @@ static EnumPropertyItem* rna_ColorManagedViewSettings_view_transform_itemf(bCont
 {
        wmWindow *win = CTX_wm_window(C);
        EnumPropertyItem *items = NULL;
+       ColorManagedDisplaySettings *display_settings = &win->display_settings;
        int totitem = 0;
 
        RNA_enum_item_add(&items, &totitem, &view_transform_items[0]);
-       IMB_colormanagement_view_items_add(&items, &totitem, win->display_device);
+       IMB_colormanagement_view_items_add(&items, &totitem, display_settings->display_device);
        RNA_enum_item_end(&items, &totitem);
 
        *free = 1;
@@ -720,6 +751,24 @@ static void rna_def_colormanage(BlenderRNA *brna)
        StructRNA *srna;
        PropertyRNA *prop;
 
+       static EnumPropertyItem display_device_items[] = {
+               {0, "DEFAULT", 0, "Default", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       /* ** Display Settings  **  */
+       srna = RNA_def_struct(brna, "ColorManagedDisplaySettings", NULL);
+       RNA_def_struct_ui_text(srna, "ColorManagedDisplaySettings", "Color management specific to display device");
+
+       prop= RNA_def_property(srna, "display_device", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, display_device_items);
+       RNA_def_property_enum_funcs(prop, "rna_ColorManagedDisplaySettings_display_device_get",
+                                         "rna_ColorManagedDisplaySettings_display_device_set",
+                                         "rna_ColorManagedDisplaySettings_display_device_itemf");
+       RNA_def_property_ui_text(prop, "Display Device", "Display device name");
+       RNA_def_property_update(prop, NC_WINDOW, NULL);
+
+       /* ** View Settings  **  */
        srna = RNA_def_struct(brna, "ColorManagedViewSettings", NULL);
        RNA_def_struct_ui_text(srna, "ColorManagedViewSettings", "Color management settings used for displaying images on the display");
 
index dfb81d3e3ab640325535dc35de288b61b780e322..5b0a1209a7bea1dfa092364043e11bbf7582b2c8 100644 (file)
@@ -572,36 +572,6 @@ static void rna_Window_screen_update(bContext *C, PointerRNA *ptr)
        }
 }
 
-static int rna_Window_display_device_get(struct PointerRNA *ptr)
-{
-       wmWindow *win = (wmWindow *) ptr->data;
-
-       return IMB_colormanagement_display_get_named_index(win->display_device);
-}
-
-static void rna_Window_display_device_set(struct PointerRNA *ptr, int value)
-{
-       wmWindow *win = (wmWindow *) ptr->data;
-       const char *name = IMB_colormanagement_display_get_indexed_name(value);
-
-       if (name) {
-               BLI_strncpy(win->display_device, name, sizeof(win->display_device));
-       }
-}
-
-static EnumPropertyItem *rna_Window_display_device_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
-{
-       EnumPropertyItem *items = NULL;
-       int totitem = 0;
-
-       IMB_colormanagement_display_items_add(&items, &totitem);
-       RNA_enum_item_end(&items, &totitem);
-
-       *free = TRUE;
-
-       return items;
-}
-
 static PointerRNA rna_KeyMapItem_properties_get(PointerRNA *ptr)
 {
        wmKeyMapItem *kmi = ptr->data;
@@ -1609,11 +1579,6 @@ static void rna_def_window(BlenderRNA *brna)
        StructRNA *srna;
        PropertyRNA *prop;
 
-       static EnumPropertyItem display_device_items[] = {
-               {0, "DEFAULT", 0, "Default", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
        srna = RNA_def_struct(brna, "Window", NULL);
        RNA_def_struct_ui_text(srna, "Window", "Open window");
        RNA_def_struct_sdna(srna, "wmWindow");
@@ -1628,12 +1593,10 @@ static void rna_def_window(BlenderRNA *brna)
        RNA_def_property_update(prop, 0, "rna_Window_screen_update");
 
        /* Color Management Display */
-       prop= RNA_def_property(srna, "display_device", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_items(prop, display_device_items);
-       RNA_def_property_enum_funcs(prop, "rna_Window_display_device_get", "rna_Window_display_device_set",
-                                   "rna_Window_display_device_itemf");
-       RNA_def_property_ui_text(prop, "Display Device", "Display device name used for this window");
-       RNA_def_property_update(prop, NC_WINDOW, NULL);
+       prop = RNA_def_property(srna, "display_settings", PROP_POINTER, PROP_NONE);
+       RNA_def_property_pointer_sdna(prop, NULL, "display_settings");
+       RNA_def_property_struct_type(prop, "ColorManagedDisplaySettings");
+       RNA_def_property_ui_text(prop, "Display Settings", "Display device settings used by this window");
 
        prop = RNA_def_property(srna, "view_settings", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "view_settings");
index 2a50bb11bffb8007e90986fbcda8f8d3d722cd12..1da098e6bfbf7199763d4de74cf2719a41594252 100644 (file)
@@ -49,6 +49,7 @@
 #include "BLF_translation.h"
 
 #include "BKE_blender.h"
+#include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_library.h"
 #include "BKE_global.h"
@@ -244,7 +245,7 @@ wmWindow *wm_window_copy(bContext *C, wmWindow *winorig)
        win->drawmethod = -1;
        win->drawdata = NULL;
 
-       BLI_strncpy(win->display_device, winorig->display_device, sizeof(win->display_device));
+       BKE_color_managed_display_settings_copy(&win->display_settings, &winorig->display_settings);
 
        return win;
 }