diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-02-12 09:55:48 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-02-12 14:05:24 +0400 |
commit | e2089e1406b50446c0c0accde28650e048b09c54 (patch) | |
tree | 144a1026369ffef6c827e28fa065f4771061e337 /source/blender/blenlib/intern/math_color.c | |
parent | 7bc577e9f7ec8d3c20eabce1832be7ed463100c6 (diff) |
NDOF: fix for negative colors and flickering hue when picking with HSVCUBE
Diffstat (limited to 'source/blender/blenlib/intern/math_color.c')
-rw-r--r-- | source/blender/blenlib/intern/math_color.c | 10 |
1 files changed, 10 insertions, 0 deletions
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) |