Cleanup: renaming and code deduplication for color space clarity in picker

Ref T68926
This commit is contained in:
Brecht Van Lommel 2020-12-17 19:39:39 +01:00
parent f193b1afb3
commit b10d8e330e
Notes: blender-bot 2023-02-14 07:53:51 +01:00
Referenced by issue #68926, Color Management Improvements
4 changed files with 129 additions and 123 deletions

View File

@ -5861,7 +5861,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co
if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->ctrl) {
ColorPicker *cpicker = but->custom_data;
float hsv_static[3] = {0.0f};
float *hsv = cpicker ? cpicker->color_data : hsv_static;
float *hsv = cpicker ? cpicker->hsv_perceptual : hsv_static;
float col[3];
ui_but_v3_get(but, col);
@ -6089,7 +6089,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
{
const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float *hsv = cpicker->hsv_perceptual;
float rgb[3];
float x, y;
float mx_fl, my_fl;
@ -6107,7 +6107,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
#endif
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_scene_linear_to_perceptual_space(but, rgb);
ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsv);
@ -6120,7 +6120,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
/* calculate original hsv again */
copy_v3_v3(rgb, data->origvec);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_scene_linear_to_perceptual_space(but, rgb);
copy_v3_v3(hsvo, hsv);
@ -6183,7 +6183,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
}
ui_color_picker_to_rgb_HSVCUBE_v(hsv_but, hsv, rgb);
ui_color_picker_to_scene_linear_space(but, rgb);
ui_perceptual_to_scene_linear_space(but, rgb);
/* clamp because with color conversion we can exceed range T34295. */
if (hsv_but->gradient_type == UI_GRAD_V_ALT) {
@ -6206,13 +6206,13 @@ static void ui_ndofedit_but_HSVCUBE(uiButHSVCube *hsv_but,
const bool shift)
{
ColorPicker *cpicker = hsv_but->but.custom_data;
float *hsv = cpicker->color_data;
float *hsv = cpicker->hsv_perceptual;
const float hsv_v_max = max_ff(hsv[2], hsv_but->but.softmax);
float rgb[3];
const float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt;
ui_but_v3_get(&hsv_but->but, rgb);
ui_scene_linear_to_color_picker_space(&hsv_but->but, rgb);
ui_scene_linear_to_perceptual_space(&hsv_but->but, rgb);
ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsv);
switch (hsv_but->gradient_type) {
@ -6261,7 +6261,7 @@ static void ui_ndofedit_but_HSVCUBE(uiButHSVCube *hsv_but,
hsv_clamp_v(hsv, hsv_v_max);
ui_color_picker_to_rgb_HSVCUBE_v(hsv_but, hsv, rgb);
ui_color_picker_to_scene_linear_space(&hsv_but->but, rgb);
ui_perceptual_to_scene_linear_space(&hsv_but->but, rgb);
copy_v3_v3(data->vec, rgb);
ui_but_v3_set(&hsv_but->but, data->vec);
@ -6318,7 +6318,7 @@ static int ui_do_but_HSVCUBE(
float rgb[3], def_hsv[3];
float def[4];
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float *hsv = cpicker->hsv_perceptual;
RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
ui_rgb_to_color_picker_HSVCUBE_v(hsv_but, def, def_hsv);
@ -6374,7 +6374,7 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but,
{
const bool changed = true;
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float *hsv = cpicker->hsv_perceptual;
float mx_fl, my_fl;
ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
@ -6400,8 +6400,8 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but,
float rgb[3];
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_rgb_to_color_picker_compat_v(rgb, hsv);
ui_scene_linear_to_perceptual_space(but, rgb);
ui_color_picker_rgb_to_hsv_compat(rgb, hsv);
/* exception, when using color wheel in 'locked' value state:
* allow choosing a hue for black values, by giving a tiny increment */
@ -6428,8 +6428,8 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but,
/* calculate original hsv again */
copy_v3_v3(hsvo, hsv);
copy_v3_v3(rgbo, data->origvec);
ui_scene_linear_to_color_picker_space(but, rgbo);
ui_rgb_to_color_picker_compat_v(rgbo, hsvo);
ui_scene_linear_to_perceptual_space(but, rgbo);
ui_color_picker_rgb_to_hsv_compat(rgbo, hsvo);
/* and original position */
ui_hsvcircle_pos_from_vals(cpicker, &rect, hsvo, &xpos, &ypos);
@ -6448,7 +6448,7 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but,
ui_color_snap_hue(snap, &hsv[0]);
}
ui_color_picker_to_rgb_v(hsv, rgb);
ui_color_picker_hsv_to_rgb(hsv, rgb);
if ((cpicker->use_luminosity_lock)) {
if (!is_zero_v3(rgb)) {
@ -6456,7 +6456,7 @@ static bool ui_numedit_but_HSVCIRCLE(uiBut *but,
}
}
ui_color_picker_to_scene_linear_space(but, rgb);
ui_perceptual_to_scene_linear_space(but, rgb);
ui_but_v3_set(but, rgb);
data->draglastx = mx;
@ -6473,14 +6473,14 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but,
const bool shift)
{
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float *hsv = cpicker->hsv_perceptual;
float rgb[3];
float phi, r /*, sqr */ /* UNUSED */, v[2];
const float sensitivity = (shift ? 0.06f : 0.3f) * ndof->dt;
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_rgb_to_color_picker_compat_v(rgb, hsv);
ui_scene_linear_to_perceptual_space(but, rgb);
ui_color_picker_rgb_to_hsv_compat(rgb, hsv);
/* Convert current color on hue/sat disc to circular coordinates phi, r */
phi = fmodf(hsv[0] + 0.25f, 1.0f) * -2.0f * (float)M_PI;
@ -6530,7 +6530,7 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but,
hsv_clamp_v(hsv, FLT_MAX);
ui_color_picker_to_rgb_v(hsv, data->vec);
ui_color_picker_hsv_to_rgb(hsv, data->vec);
if (cpicker->use_luminosity_lock) {
if (!is_zero_v3(data->vec)) {
@ -6538,7 +6538,7 @@ static void ui_ndofedit_but_HSVCIRCLE(uiBut *but,
}
}
ui_color_picker_to_scene_linear_space(but, data->vec);
ui_perceptual_to_scene_linear_space(but, data->vec);
ui_but_v3_set(but, data->vec);
}
#endif /* WITH_INPUT_NDOF */
@ -6547,7 +6547,7 @@ static int ui_do_but_HSVCIRCLE(
bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
{
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float *hsv = cpicker->hsv_perceptual;
int mx = event->x;
int my = event->y;
ui_window_to_block(data->region, block, &mx, &my);
@ -6594,10 +6594,10 @@ static int ui_do_but_HSVCIRCLE(
def = MEM_callocN(sizeof(float) * len, "reset_defaults - float");
RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
ui_color_picker_to_rgb_v(def, def_hsv);
ui_color_picker_hsv_to_rgb(def, def_hsv);
ui_but_v3_get(but, rgb);
ui_rgb_to_color_picker_compat_v(rgb, hsv);
ui_color_picker_rgb_to_hsv_compat(rgb, hsv);
def_hsv[0] = hsv[0];
def_hsv[2] = hsv[2];

View File

@ -382,15 +382,15 @@ typedef struct ColorPicker {
/** Color in HSV or HSL, in color picking color space. Used for HSV cube,
* circle and slider widgets. The color picking space is perceptually
* linear for intuitive editing. */
float color_data[3];
float hsv_perceptual[3];
/** Initial color data (to detect changes). */
float color_data_init[3];
float hsv_perceptual_init[3];
bool is_init;
/** HSV or HSL color in scene linear color space value used for number
* buttons. This is scene linear so that there is a clear correspondence
* to the scene linear RGB values. */
float hsv[3];
float hsv_scene_linear[3];
/** Cubic saturation for the color wheel. */
bool use_color_cubic;
@ -743,15 +743,14 @@ struct uiPopupBlockHandle {
/* exposed as public API in UI_interface.h */
/* interface_region_color_picker.c */
void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3]);
void ui_rgb_to_color_picker_v(const float rgb[3], float r_cp[3]);
void ui_color_picker_to_rgb_v(const float r_cp[3], float rgb[3]);
void ui_color_picker_to_rgb(float r_cp0, float r_cp1, float r_cp2, float *r, float *g, float *b);
void ui_color_picker_rgb_to_hsv_compat(const float rgb[3], float r_cp[3]);
void ui_color_picker_rgb_to_hsv(const float rgb[3], float r_cp[3]);
void ui_color_picker_hsv_to_rgb(const float r_cp[3], float rgb[3]);
bool ui_but_is_color_gamma(uiBut *but);
void ui_scene_linear_to_color_picker_space(uiBut *but, float rgb[3]);
void ui_color_picker_to_scene_linear_space(uiBut *but, float rgb[3]);
void ui_scene_linear_to_perceptual_space(uiBut *but, float rgb[3]);
void ui_perceptual_to_scene_linear_space(uiBut *but, float rgb[3]);
uiBlock *ui_block_func_COLOR(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but);
ColorPicker *ui_block_colorpicker_create(struct uiBlock *block);

View File

@ -77,8 +77,10 @@ static void ui_color_picker_rgb_round(float rgb[3])
}
}
void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3])
void ui_color_picker_rgb_to_hsv_compat(const float rgb[3], float r_cp[3])
{
/* Convert RGB to HSV, remaining as compatible as possible with the existing
* r_hsv value (for example when value goes to zero, preserve the hue). */
switch (U.color_picker_type) {
case USER_CP_CIRCLE_HSL:
rgb_to_hsl_compat_v(rgb, r_cp);
@ -89,7 +91,7 @@ void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3])
}
}
void ui_rgb_to_color_picker_v(const float rgb[3], float r_cp[3])
void ui_color_picker_rgb_to_hsv(const float rgb[3], float r_cp[3])
{
switch (U.color_picker_type) {
case USER_CP_CIRCLE_HSL:
@ -101,7 +103,7 @@ void ui_rgb_to_color_picker_v(const float rgb[3], float r_cp[3])
}
}
void ui_color_picker_to_rgb_v(const float r_cp[3], float rgb[3])
void ui_color_picker_hsv_to_rgb(const float r_cp[3], float rgb[3])
{
switch (U.color_picker_type) {
case USER_CP_CIRCLE_HSL:
@ -113,18 +115,6 @@ void ui_color_picker_to_rgb_v(const float r_cp[3], float rgb[3])
}
}
void ui_color_picker_to_rgb(float r_cp0, float r_cp1, float r_cp2, float *r, float *g, float *b)
{
switch (U.color_picker_type) {
case USER_CP_CIRCLE_HSL:
hsl_to_rgb(r_cp0, r_cp1, r_cp2, r, g, b);
break;
default:
hsv_to_rgb(r_cp0, r_cp1, r_cp2, r, g, b);
break;
}
}
/* Returns true if the button is for a color with gamma baked in,
* or if it's a color picker for such a button. */
bool ui_but_is_color_gamma(uiBut *but)
@ -138,7 +128,7 @@ bool ui_but_is_color_gamma(uiBut *but)
return but->block->is_color_gamma_picker;
}
void ui_scene_linear_to_color_picker_space(uiBut *but, float rgb[3])
void ui_scene_linear_to_perceptual_space(uiBut *but, float rgb[3])
{
/* Map to color picking space for HSV values and HSV cube/circle,
* assuming it is more perceptually linear than the scene linear
@ -149,7 +139,7 @@ void ui_scene_linear_to_color_picker_space(uiBut *but, float rgb[3])
}
}
void ui_color_picker_to_scene_linear_space(uiBut *but, float rgb[3])
void ui_perceptual_to_scene_linear_space(uiBut *but, float rgb[3])
{
if (!ui_but_is_color_gamma(but)) {
IMB_colormanagement_color_picking_to_scene_linear_v3(rgb);
@ -163,16 +153,46 @@ void ui_color_picker_to_scene_linear_space(uiBut *but, float rgb[3])
/** \name Color Picker
* \{ */
static void ui_color_picker_update_hsv(ColorPicker *cpicker,
uiBut *from_but,
const float rgb_scene_linear[3])
{
/* Convert from RGB to HSV in scene linear space color for number editing. */
if (cpicker->is_init == false) {
ui_color_picker_rgb_to_hsv(rgb_scene_linear, cpicker->hsv_scene_linear);
}
else {
ui_color_picker_rgb_to_hsv_compat(rgb_scene_linear, cpicker->hsv_scene_linear);
}
/* Convert from RGB to HSV in perceptually linear space for picker widgets. */
float rgb_perceptual[3];
copy_v3_v3(rgb_perceptual, rgb_scene_linear);
if (from_but) {
ui_scene_linear_to_perceptual_space(from_but, rgb_perceptual);
}
if (cpicker->is_init == false) {
ui_color_picker_rgb_to_hsv(rgb_perceptual, cpicker->hsv_perceptual);
copy_v3_v3(cpicker->hsv_perceptual_init, cpicker->hsv_perceptual);
}
else {
ui_color_picker_rgb_to_hsv_compat(rgb_perceptual, cpicker->hsv_perceptual);
}
cpicker->is_init = true;
}
/* for picker, while editing hsv */
void ui_but_hsv_set(uiBut *but)
{
float col[3];
float rgb_perceptual[3];
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float *hsv_perceptual = cpicker->hsv_perceptual;
ui_color_picker_to_rgb_v(hsv, col);
ui_color_picker_hsv_to_rgb(hsv_perceptual, rgb_perceptual);
ui_but_v3_set(but, col);
ui_but_v3_set(but, rgb_perceptual);
}
/* Updates all buttons who share the same color picker as the one passed
@ -180,18 +200,9 @@ void ui_but_hsv_set(uiBut *but)
static void ui_update_color_picker_buts_rgb(uiBut *from_but,
uiBlock *block,
ColorPicker *cpicker,
const float rgb[3])
const float rgb_scene_linear[3])
{
/* Convert from RGB to HSV in scene linear space color for numeric editing. */
ui_rgb_to_color_picker_compat_v(rgb, cpicker->hsv);
/* Convert from RGB to HSV in perceptually linear space for picker widgets. */
float tmp[3];
copy_v3_v3(tmp, rgb);
if (from_but) {
ui_scene_linear_to_color_picker_space(from_but, tmp);
}
ui_rgb_to_color_picker_compat_v(tmp, cpicker->color_data);
ui_color_picker_update_hsv(cpicker, from_but, rgb_scene_linear);
/* this updates button strings,
* is hackish... but button pointers are on stack of caller function */
@ -201,7 +212,7 @@ static void ui_update_color_picker_buts_rgb(uiBut *from_but,
}
if (bt->rnaprop) {
ui_but_v3_set(bt, rgb);
ui_but_v3_set(bt, rgb_scene_linear);
/* original button that created the color picker already does undo
* push, so disable it on RNA buttons in the color picker block */
@ -214,7 +225,7 @@ static void ui_update_color_picker_buts_rgb(uiBut *from_but,
/* Hex code is assumed to be in sRGB space
* (coming from other applications, web, etc) */
copy_v3_v3(rgb_hex, rgb);
copy_v3_v3(rgb_hex, rgb_scene_linear);
if (from_but && !ui_but_is_color_gamma(from_but)) {
IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex);
ui_color_picker_rgb_round(rgb_hex);
@ -227,25 +238,25 @@ static void ui_update_color_picker_buts_rgb(uiBut *from_but,
}
else if (bt->str[1] == ' ') {
if (bt->str[0] == 'R') {
ui_but_value_set(bt, rgb[0]);
ui_but_value_set(bt, rgb_scene_linear[0]);
}
else if (bt->str[0] == 'G') {
ui_but_value_set(bt, rgb[1]);
ui_but_value_set(bt, rgb_scene_linear[1]);
}
else if (bt->str[0] == 'B') {
ui_but_value_set(bt, rgb[2]);
ui_but_value_set(bt, rgb_scene_linear[2]);
}
else if (bt->str[0] == 'H') {
ui_but_value_set(bt, cpicker->hsv[0]);
ui_but_value_set(bt, cpicker->hsv_scene_linear[0]);
}
else if (bt->str[0] == 'S') {
ui_but_value_set(bt, cpicker->hsv[1]);
ui_but_value_set(bt, cpicker->hsv_scene_linear[1]);
}
else if (bt->str[0] == 'V') {
ui_but_value_set(bt, cpicker->hsv[2]);
ui_but_value_set(bt, cpicker->hsv_scene_linear[2]);
}
else if (bt->str[0] == 'L') {
ui_but_value_set(bt, cpicker->hsv[2]);
ui_but_value_set(bt, cpicker->hsv_scene_linear[2]);
}
}
@ -259,11 +270,11 @@ static void ui_colorpicker_rgba_update_cb(bContext *UNUSED(C), void *bt1, void *
uiPopupBlockHandle *popup = but->block->handle;
PropertyRNA *prop = but->rnaprop;
PointerRNA ptr = but->rnapoin;
float rgb[4];
float rgb_scene_linear[4];
if (prop) {
RNA_property_float_get_array(&ptr, prop, rgb);
ui_update_color_picker_buts_rgb(but, but->block, but->custom_data, rgb);
RNA_property_float_get_array(&ptr, prop, rgb_scene_linear);
ui_update_color_picker_buts_rgb(but, but->block, but->custom_data, rgb_scene_linear);
}
if (popup) {
@ -275,11 +286,11 @@ static void ui_colorpicker_hsv_update_cb(bContext *UNUSED(C), void *bt1, void *U
{
uiBut *but = (uiBut *)bt1;
uiPopupBlockHandle *popup = but->block->handle;
float rgb[3];
float rgb_scene_linear[3];
ColorPicker *cpicker = but->custom_data;
ui_color_picker_to_rgb_v(cpicker->hsv, rgb);
ui_update_color_picker_buts_rgb(but, but->block, cpicker, rgb);
ui_color_picker_hsv_to_rgb(cpicker->hsv_scene_linear, rgb_scene_linear);
ui_update_color_picker_buts_rgb(but, but->block, cpicker, rgb_scene_linear);
if (popup) {
popup->menuretval = UI_RETURN_UPDATE;
@ -317,7 +328,7 @@ static void ui_popup_close_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg))
if (popup) {
ColorPicker *cpicker = but->custom_data;
BLI_assert(cpicker->is_init);
popup->menuretval = (equals_v3v3(cpicker->color_data, cpicker->color_data_init) ?
popup->menuretval = (equals_v3v3(cpicker->hsv_perceptual, cpicker->hsv_perceptual_init) ?
UI_RETURN_CANCEL :
UI_RETURN_OK);
}
@ -483,7 +494,10 @@ static void ui_colorpicker_square(uiBlock *block,
}
/* a HS circle, V slider, rgb/hsv/hex sliders */
static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4], bool show_picker)
static void ui_block_colorpicker(uiBlock *block,
uiBut *from_but,
float rgba_scene_linear[4],
bool show_picker)
{
/* ePickerType */
static char colormode = 1;
@ -500,21 +514,13 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4],
butwidth = width - 1.5f * UI_UNIT_X;
/* sneaky way to check for alpha */
rgba[3] = FLT_MAX;
rgba_scene_linear[3] = FLT_MAX;
RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
RNA_property_float_get_array(ptr, prop, rgba);
RNA_property_float_get_array(ptr, prop, rgba_scene_linear);
float rgb_perceptual[3];
copy_v3_v3(rgb_perceptual, rgba);
ui_rgb_to_color_picker_v(rgba, cpicker->hsv);
ui_scene_linear_to_color_picker_space(from_but, rgb_perceptual);
ui_rgb_to_color_picker_v(rgb_perceptual, cpicker->color_data);
if (cpicker->is_init == false) {
copy_v3_v3(cpicker->color_data_init, cpicker->color_data);
cpicker->is_init = true;
}
ui_color_picker_update_hsv(cpicker, from_but, rgba_scene_linear);
/* when the softmax isn't defined in the RNA,
* using very large numbers causes sRGB/linear round trip to fail. */
@ -689,7 +695,7 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4],
yco,
butwidth,
UI_UNIT_Y,
cpicker->hsv,
cpicker->hsv_scene_linear,
0.0,
1.0,
10,
@ -706,7 +712,7 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4],
yco -= UI_UNIT_Y,
butwidth,
UI_UNIT_Y,
cpicker->hsv + 1,
cpicker->hsv_scene_linear + 1,
0.0,
1.0,
10,
@ -724,7 +730,7 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4],
yco -= UI_UNIT_Y,
butwidth,
UI_UNIT_Y,
cpicker->hsv + 2,
cpicker->hsv_scene_linear + 2,
0.0,
1.0,
10,
@ -740,7 +746,7 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4],
yco -= UI_UNIT_Y,
butwidth,
UI_UNIT_Y,
cpicker->hsv + 2,
cpicker->hsv_scene_linear + 2,
0.0,
softmax,
10,
@ -755,7 +761,7 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4],
UI_block_align_end(block);
if (rgba[3] != FLT_MAX) {
if (rgba_scene_linear[3] != FLT_MAX) {
bt = uiDefButR_prop(block,
UI_BTYPE_NUM_SLIDER,
0,
@ -776,14 +782,14 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4],
bt->custom_data = cpicker;
}
else {
rgba[3] = 1.0f;
rgba_scene_linear[3] = 1.0f;
}
/* Hex color is in sRGB space. */
float rgb_hex[3];
uchar rgb_hex_uchar[3];
copy_v3_v3(rgb_hex, rgba);
copy_v3_v3(rgb_hex, rgba_scene_linear);
if (!ui_but_is_color_gamma(from_but)) {
IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex);
@ -846,21 +852,22 @@ static int ui_colorpicker_small_wheel_cb(const bContext *UNUSED(C),
LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
if (but->type == UI_BTYPE_HSVCUBE && but->active == NULL) {
uiPopupBlockHandle *popup = block->handle;
float rgb[3];
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float *hsv_perceptual = cpicker->hsv_perceptual;
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_rgb_to_color_picker_compat_v(rgb, hsv);
float rgb_perceptual[3];
ui_but_v3_get(but, rgb_perceptual);
ui_scene_linear_to_perceptual_space(but, rgb_perceptual);
ui_color_picker_rgb_to_hsv_compat(rgb_perceptual, hsv_perceptual);
hsv[2] = clamp_f(hsv[2] + add, 0.0f, 1.0f);
hsv_perceptual[2] = clamp_f(hsv_perceptual[2] + add, 0.0f, 1.0f);
ui_color_picker_to_rgb_v(hsv, rgb);
ui_color_picker_to_scene_linear_space(but, rgb);
ui_but_v3_set(but, rgb);
float rgb_scene_linear[3];
ui_color_picker_hsv_to_rgb(hsv_perceptual, rgb_scene_linear);
ui_perceptual_to_scene_linear_space(but, rgb_scene_linear);
ui_but_v3_set(but, rgb_scene_linear);
ui_update_color_picker_buts_rgb(but, block, cpicker, rgb);
ui_update_color_picker_buts_rgb(but, block, cpicker, rgb_scene_linear);
if (popup) {
popup->menuretval = UI_RETURN_UPDATE;
}

View File

@ -2906,12 +2906,12 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const
const bool is_color_gamma = ui_but_is_color_gamma(but);
/* Initialize for compatibility. */
copy_v3_v3(hsv, cpicker->color_data);
copy_v3_v3(hsv, cpicker->hsv_perceptual);
/* Compute current hue. */
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_rgb_to_color_picker_compat_v(rgb, hsv);
ui_scene_linear_to_perceptual_space(but, rgb);
ui_color_picker_rgb_to_hsv_compat(rgb, hsv);
CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */
@ -2928,8 +2928,8 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const
}
const float hsv_center[3] = {0.0f, 0.0f, hsv[2]};
ui_color_picker_to_rgb_v(hsv_center, rgb_center);
ui_color_picker_to_scene_linear_space(but, rgb_center);
ui_color_picker_hsv_to_rgb(hsv_center, rgb_center);
ui_perceptual_to_scene_linear_space(but, rgb_center);
if (!is_color_gamma) {
ui_block_cm_to_display_space_v3(but->block, rgb_center);
@ -2956,8 +2956,8 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const
rect, centx + co * radius, centy + si * radius, hsv_ang, hsv_ang + 1);
hsv_ang[2] = hsv[2];
ui_color_picker_to_rgb_v(hsv_ang, rgb_ang);
ui_color_picker_to_scene_linear_space(but, rgb_ang);
ui_color_picker_hsv_to_rgb(hsv_ang, rgb_ang);
ui_perceptual_to_scene_linear_space(but, rgb_ang);
if (!is_color_gamma) {
ui_block_cm_to_display_space_v3(but->block, rgb_ang);
@ -2987,10 +2987,10 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const
GPU_line_smooth(false);
/* cursor */
copy_v3_v3(hsv, cpicker->color_data);
copy_v3_v3(hsv, cpicker->hsv_perceptual);
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_rgb_to_color_picker_compat_v(rgb, hsv);
ui_scene_linear_to_perceptual_space(but, rgb);
ui_color_picker_rgb_to_hsv_compat(rgb, hsv);
float xpos, ypos;
ui_hsvcircle_pos_from_vals(cpicker, rect, hsv, &xpos, &ypos);
@ -3212,14 +3212,14 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
float rgb[3];
float x = 0.0f, y = 0.0f;
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float *hsv = cpicker->hsv_perceptual;
float hsv_n[3];
/* Initialize for compatibility. */
copy_v3_v3(hsv_n, hsv);
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_scene_linear_to_perceptual_space(but, rgb);
rgb_to_hsv_compat_v(rgb, hsv_n);
ui_draw_gradient(rect, hsv_n, hsv_but->gradient_type, 1.0f);
@ -3251,7 +3251,7 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
float rgb[3], hsv[3], v;
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
ui_scene_linear_to_perceptual_space(but, rgb);
if (hsv_but->gradient_type == UI_GRAD_L_ALT) {
rgb_to_hsl_v(rgb, hsv);