Fix T67099: entering color picker hex value #FF results in 1.000001

This commit is contained in:
Brecht Van Lommel
2019-07-17 14:11:50 +02:00
parent f17e2f8dac
commit b69c33aeba
@@ -63,6 +63,21 @@ enum ePickerType {
/** \name Color Conversion
* \{ */
static void ui_color_picker_rgb_round(float rgb[3])
{
/* Handle small rounding errors in color space conversions. Doing these for
* all color space conversions would be expensive, but for the color picker
* we can do the extra work. */
for (int i = 0; i < 3; i++) {
if (fabsf(rgb[i]) < 1e-6f) {
rgb[i] = 0.0f;
}
else if (fabsf(1.0f - rgb[i]) < 1e-6f) {
rgb[i] = 1.0f;
}
}
}
void ui_rgb_to_color_picker_compat_v(const float rgb[3], float r_cp[3])
{
switch (U.color_picker_type) {
@@ -131,6 +146,7 @@ void ui_scene_linear_to_color_picker_space(uiBut *but, float rgb[3])
* space for intuitive color picking. */
if (!ui_but_is_color_gamma(but)) {
IMB_colormanagement_scene_linear_to_color_picking_v3(rgb);
ui_color_picker_rgb_round(rgb);
}
}
@@ -138,6 +154,7 @@ void ui_color_picker_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);
ui_color_picker_rgb_round(rgb);
}
}
@@ -201,6 +218,7 @@ static void ui_update_color_picker_buts_rgb(uiBut *from_but,
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);
ui_color_picker_rgb_round(rgb_hex);
}
rgb_float_to_uchar(rgb_hex_uchar, rgb_hex);
@@ -287,6 +305,7 @@ static void ui_colorpicker_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexc
/* Hex code is assumed to be in sRGB space (coming from other applications, web, etc) */
if (!ui_but_is_color_gamma(but)) {
IMB_colormanagement_srgb_to_scene_linear_v3(rgb);
ui_color_picker_rgb_round(rgb);
}
ui_update_color_picker_buts_rgb(but, but->block, cpicker, rgb);
@@ -765,6 +784,7 @@ static void ui_block_colorpicker(uiBlock *block, uiBut *from_but, float rgba[4],
if (!ui_but_is_color_gamma(from_but)) {
IMB_colormanagement_scene_linear_to_srgb_v3(rgb_hex);
ui_color_picker_rgb_round(rgb_hex);
}
rgb_float_to_uchar(rgb_hex_uchar, rgb_hex);