Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-07-17 15:11:50 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-07-17 17:30:42 +0300
commitb69c33aeba679665dc95c90fcced078b576dc527 (patch)
tree17ab8d82704244528c1ff4e691fb1545c179dc0c /source/blender
parentf17e2f8dac3a392823ed7dbbcdea3f88bff20f75 (diff)
Fix T67099: entering color picker hex value #FF results in 1.000001
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/interface/interface_region_color_picker.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_region_color_picker.c b/source/blender/editors/interface/interface_region_color_picker.c
index 5c231f5e51a..917c35f0135 100644
--- a/source/blender/editors/interface/interface_region_color_picker.c
+++ b/source/blender/editors/interface/interface_region_color_picker.c
@@ -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);