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:
authorCampbell Barton <ideasman42@gmail.com>2014-02-12 09:55:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-02-12 14:05:24 +0400
commite2089e1406b50446c0c0accde28650e048b09c54 (patch)
tree144a1026369ffef6c827e28fa065f4771061e337
parent7bc577e9f7ec8d3c20eabce1832be7ed463100c6 (diff)
NDOF: fix for negative colors and flickering hue when picking with HSVCUBE
-rw-r--r--source/blender/blenlib/BLI_math_color.h1
-rw-r--r--source/blender/blenlib/intern/math_color.c10
-rw-r--r--source/blender/editors/interface/interface_handlers.c4
3 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 7167aad9551..3892c98e140 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -123,6 +123,7 @@ MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float c
int constrain_rgb(float *r, float *g, float *b);
void minmax_rgb(short c[3]);
+void hsv_clamp_v(float hsv[3], float v_max);
void rgb_float_set_hue_float_offset(float *rgb, float hue_offset);
void rgb_byte_set_hue_float_offset(unsigned char *rgb, float hue_offset);
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index b558227fa94..51980ad36cb 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -347,6 +347,16 @@ void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3])
rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], &r_hsv[0], &r_hsv[1], &r_hsv[2]);
}
+/* clamp hsv to usable values */
+void hsv_clamp_v(float hsv[3], float v_max)
+{
+ if (UNLIKELY(hsv[0] < 0.0f || hsv[0] > 1.0f)) {
+ hsv[0] = hsv[0] - floorf(hsv[0]);
+ }
+ CLAMP(hsv[1], 0.0f, 1.0f);
+ CLAMP(hsv[2], 0.0f, v_max);
+}
+
/*http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html */
void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace)
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index c6b0782309e..4665752b7b3 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4380,6 +4380,7 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data,
const enum eSnapType snap, const bool shift)
{
float *hsv = ui_block_hsv_get(but->block);
+ const float hsv_v_max = max_ff(hsv[2], but->softmax);
float rgb[3];
float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt;
bool use_display_colorspace = ui_hsvcube_use_display_colorspace(but);
@@ -4432,6 +4433,9 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data,
}
}
+ /* ndof specific: the changes above aren't clamping */
+ hsv_clamp_v(hsv, hsv_v_max);
+
hsv_to_rgb_v(hsv, rgb);
if (use_display_colorspace)