Fix T58014, T58650: issues with hex color and Filmic view transform.

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.
This commit is contained in:
Brecht Van Lommel 2018-12-13 18:28:41 +01:00
parent f527ce5b2f
commit a7b3d58066
Notes: blender-bot 2023-02-14 10:54:29 +01:00
Referenced by issue #58650, Issue copying HEX color code
Referenced by issue #58014, hex color entry wants to fight the user
5 changed files with 29 additions and 40 deletions

View 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) {

View 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);
}
}

View 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 */

View 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);
}

View 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(