Fix T58014, T58650: issues with hex color and Filmic view transform.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 13 Dec 2018 17:28:41 +0000 (18:28 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 13 Dec 2018 18:25:47 +0000 (19:25 +0100)
Hex color values are now always in sRGB space, as would be expected by
most other applications. Previously they were in display space and using
the view transform.

source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_ops.c
source/blender/editors/interface/interface_region_color_picker.c

index 2a4dfc210b0ffbc98422efa952798812f521d46a..c63ffc87b8e2143d2e9dbe6bb4e3397e48f3952d 100644 (file)
@@ -3289,13 +3289,6 @@ void ui_block_cm_to_display_space_v3(uiBlock *block, float pixel[3])
        IMB_colormanagement_scene_linear_to_display_v3(pixel, display);
 }
 
-void ui_block_cm_to_scene_linear_v3(uiBlock *block, float pixel[3])
-{
-       struct ColorManagedDisplay *display = ui_block_cm_display_get(block);
-
-       IMB_colormanagement_display_to_scene_linear_v3(pixel, display);
-}
-
 static uiBut *ui_but_alloc(const eButType type)
 {
        switch (type) {
index 3949c1e2d5006ba155c7c7a48d848231cdea5ebc..9dc1f1e4e24323a0c51d1214e0ba465a2b1deca5 100644 (file)
@@ -64,6 +64,8 @@
 #include "BKE_unit.h"
 #include "BKE_paint.h"
 
+#include "IMB_colormanagement.h"
+
 #include "ED_screen.h"
 #include "ED_undo.h"
 
@@ -5313,7 +5315,7 @@ static int ui_do_but_COLOR(
 
                                                if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
                                                        RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
-                                                       ui_block_cm_to_scene_linear_v3(but->block, target);
+                                                       IMB_colormanagement_srgb_to_scene_linear_v3(target);
                                                }
                                                else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
                                                        RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target);
@@ -5326,7 +5328,7 @@ static int ui_do_but_COLOR(
                                                }
                                                else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
                                                        RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color);
-                                                       ui_block_cm_to_display_space_v3(but->block, color);
+                                                       IMB_colormanagement_scene_linear_to_srgb_v3(color);
                                                        BKE_brush_color_set(scene, brush, color);
                                                }
                                        }
index 0ab92a633ad9aff625a7b37556c4462dba3f224e..24fb68dba0c966d7585b450ef44c27c5ce21d258 100644 (file)
@@ -514,7 +514,6 @@ extern void ui_block_bounds_calc(uiBlock *block);
 
 extern struct ColorManagedDisplay *ui_block_cm_display_get(uiBlock *block);
 void ui_block_cm_to_display_space_v3(uiBlock *block, float pixel[3]);
-void ui_block_cm_to_scene_linear_v3(uiBlock *block, float pixel[3]);
 
 /* interface_regions.c */
 
index cc609216e9a43fab0e01b85b1ddd01985b3eab32..b4b59cae75bb62be22223db9df73693b34331455 100644 (file)
@@ -53,6 +53,8 @@
 #include "BKE_screen.h"
 #include "BKE_text.h" /* for UI_OT_reports_to_text */
 
+#include "IMB_colormanagement.h"
+
 #include "DEG_depsgraph.h"
 
 #include "RNA_access.h"
@@ -1507,13 +1509,13 @@ static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(
 
                if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
                        if (!gamma)
-                               ui_block_cm_to_display_space_v3(but->block, color);
+                               IMB_colormanagement_scene_linear_to_srgb_v3(color);
                        RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color);
                        RNA_property_update(C, &but->rnapoin, but->rnaprop);
                }
                else if (RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
                        if (gamma)
-                               ui_block_cm_to_scene_linear_v3(but->block, color);
+                               IMB_colormanagement_srgb_to_scene_linear_v3(color);
                        RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color);
                        RNA_property_update(C, &but->rnapoin, but->rnaprop);
                }
index 7c2afaf1a928c76553977dfdd7de378db903b1de..082459925e0e2a981437b5ff786cee9be6bb4a45 100644 (file)
@@ -188,26 +188,23 @@ static void ui_update_color_picker_buts_rgb(
                        UI_but_flag_disable(bt, UI_BUT_UNDO);
                }
                else if (STREQ(bt->str, "Hex: ")) {
-                       float rgb_gamma[3];
-                       unsigned char rgb_gamma_uchar[3];
+                       float rgb_hex[3];
+                       unsigned char rgb_hex_uchar[3];
                        double intpart;
                        char col[16];
 
                        /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */
-
-                       copy_v3_v3(rgb_gamma, rgb);
-
-                       if (!block->is_color_gamma_picker) {
-                               /* make a display version, for Hex code */
-                               ui_block_cm_to_display_space_v3(block, rgb_gamma);
+                       copy_v3_v3(rgb_hex, rgb);
+                       if (from_but && !ui_but_is_color_gamma(from_but)) {
+                               IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex);
                        }
 
-                       if (rgb_gamma[0] > 1.0f) rgb_gamma[0] = modf(rgb_gamma[0], &intpart);
-                       if (rgb_gamma[1] > 1.0f) rgb_gamma[1] = modf(rgb_gamma[1], &intpart);
-                       if (rgb_gamma[2] > 1.0f) rgb_gamma[2] = modf(rgb_gamma[2], &intpart);
+                       if (rgb_hex[0] > 1.0f) rgb_hex[0] = modf(rgb_hex[0], &intpart);
+                       if (rgb_hex[1] > 1.0f) rgb_hex[1] = modf(rgb_hex[1], &intpart);
+                       if (rgb_hex[2] > 1.0f) rgb_hex[2] = modf(rgb_hex[2], &intpart);
 
-                       rgb_float_to_uchar(rgb_gamma_uchar, rgb_gamma);
-                       BLI_snprintf(col, sizeof(col), "%02X%02X%02X", UNPACK3_EX((uint), rgb_gamma_uchar, ));
+                       rgb_float_to_uchar(rgb_hex_uchar, rgb_hex);
+                       BLI_snprintf(col, sizeof(col), "%02X%02X%02X", UNPACK3_EX((uint), rgb_hex_uchar, ));
 
                        strcpy(bt->poin, col);
                }
@@ -287,9 +284,8 @@ static void ui_colorpicker_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexc
        hex_to_rgb(hexcol, rgb, rgb + 1, rgb + 2);
 
        /* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */
-       if (!but->block->is_color_gamma_picker) {
-               /* so we need to linearise it for Blender */
-               ui_block_cm_to_scene_linear_v3(but->block, rgb);
+       if (!ui_but_is_color_gamma(but)) {
+               IMB_colormanagement_srgb_to_scene_linear_v3(rgb);
        }
 
        ui_update_color_picker_buts_rgb(NULL, but->block, cpicker, rgb);
@@ -546,21 +542,18 @@ static void ui_block_colorpicker(
                rgba[3] = 1.0f;
        }
 
-       /* Hex color is in display space. This should actually be sRGB without any view
-        * transform, as most other applications would expect this. */
-       float rgb_gamma[3];
-       unsigned char rgb_gamma_uchar[3];
+       /* Hex color is in sRGB space. */
+       float rgb_hex[3];
+       unsigned char rgb_hex_uchar[3];
 
-       if (block->is_color_gamma_picker) {
-               copy_v3_v3(rgb_gamma, rgba);
-       }
-       else {
-               copy_v3_v3(rgb_gamma, rgba);
-               ui_block_cm_to_display_space_v3(block, rgb_gamma);
+       copy_v3_v3(rgb_hex, rgba);
+
+       if (!ui_but_is_color_gamma(from_but)) {
+               IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex);
        }
 
-       rgb_float_to_uchar(rgb_gamma_uchar, rgb_gamma);
-       BLI_snprintf(hexcol, sizeof(hexcol), "%02X%02X%02X", UNPACK3_EX((uint), rgb_gamma_uchar, ));
+       rgb_float_to_uchar(rgb_hex_uchar, rgb_hex);
+       BLI_snprintf(hexcol, sizeof(hexcol), "%02X%02X%02X", UNPACK3_EX((uint), rgb_hex_uchar, ));
 
        yco = -3.0f * UI_UNIT_Y;
        bt = uiDefBut(