[Bf-blender-cvs] [e2089e1] master: NDOF: fix for negative colors and flickering hue when picking with HSVCUBE
Campbell Barton
noreply at git.blender.org
Wed Feb 12 11:08:52 CET 2014
Commit: e2089e1406b50446c0c0accde28650e048b09c54
Author: Campbell Barton
Date: Wed Feb 12 16:55:48 2014 +1100
https://developer.blender.org/rBe2089e1406b50446c0c0accde28650e048b09c54
NDOF: fix for negative colors and flickering hue when picking with HSVCUBE
===================================================================
M source/blender/blenlib/BLI_math_color.h
M source/blender/blenlib/intern/math_color.c
M source/blender/editors/interface/interface_handlers.c
===================================================================
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 7167aad..3892c98 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 b558227..51980ad 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 c6b0782..4665752 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)
More information about the Bf-blender-cvs
mailing list