diff options
author | Richard Nelson <richard@lindenlab.com> | 2007-04-05 00:59:55 +0000 |
---|---|---|
committer | Richard Nelson <richard@lindenlab.com> | 2007-04-05 00:59:55 +0000 |
commit | 2ce0fc5f185f22be79b9be5406b76c97ed91ee01 (patch) | |
tree | d70ea9faf02e4e1e7aeb14aa524644c23c703d55 /indra/llmath | |
parent | fd5608a3e79397d4ebc8819dc9de75863f6fb9b3 (diff) |
svn merge -r 59234:60086 svn+ssh://svn/svn/linden/branches/live_lsl_help2 -> release
Diffstat (limited to 'indra/llmath')
-rw-r--r-- | indra/llmath/v3color.cpp | 49 | ||||
-rw-r--r-- | indra/llmath/v3color.h | 2 | ||||
-rw-r--r-- | indra/llmath/v4color.cpp | 49 | ||||
-rw-r--r-- | indra/llmath/v4color.h | 2 |
4 files changed, 102 insertions, 0 deletions
diff --git a/indra/llmath/v3color.cpp b/indra/llmath/v3color.cpp index 2dbc368d98..d85006fa9c 100644 --- a/indra/llmath/v3color.cpp +++ b/indra/llmath/v3color.cpp @@ -42,3 +42,52 @@ std::ostream& operator<<(std::ostream& s, const LLColor3 &a) s << "{ " << a.mV[VX] << ", " << a.mV[VY] << ", " << a.mV[VZ] << " }"; return s; } + +void LLColor3::calcHSL(F32* hue, F32* saturation, F32* luminance) const +{ + F32 var_R = mV[VRED]; + F32 var_G = mV[VGREEN]; + F32 var_B = mV[VBLUE]; + + F32 var_Min = ( var_R < ( var_G < var_B ? var_G : var_B ) ? var_R : ( var_G < var_B ? var_G : var_B ) ); + F32 var_Max = ( var_R > ( var_G > var_B ? var_G : var_B ) ? var_R : ( var_G > var_B ? var_G : var_B ) ); + + F32 del_Max = var_Max - var_Min; + + F32 L = ( var_Max + var_Min ) / 2.0f; + F32 H = 0.0f; + F32 S = 0.0f; + + if ( del_Max == 0.0f ) + { + H = 0.0f; + S = 0.0f; + } + else + { + if ( L < 0.5 ) + S = del_Max / ( var_Max + var_Min ); + else + S = del_Max / ( 2.0f - var_Max - var_Min ); + + F32 del_R = ( ( ( var_Max - var_R ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; + F32 del_G = ( ( ( var_Max - var_G ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; + F32 del_B = ( ( ( var_Max - var_B ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; + + if ( var_R >= var_Max ) + H = del_B - del_G; + else + if ( var_G >= var_Max ) + H = ( 1.0f / 3.0f ) + del_R - del_B; + else + if ( var_B >= var_Max ) + H = ( 2.0f / 3.0f ) + del_G - del_R; + + if ( H < 0.0f ) H += 1.0f; + if ( H > 1.0f ) H -= 1.0f; + } + + if (hue) *hue = H; + if (saturation) *saturation = S; + if (luminance) *luminance = L; +}
\ No newline at end of file diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index 956cca614d..779fda436e 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -52,6 +52,8 @@ public: mV[1] = (F32) sd[1].asReal();; mV[2] = (F32) sd[2].asReal();; } + + void calcHSL(F32* hue, F32* saturation, F32* luminance) const; const LLColor3& setToBlack(); // Clears LLColor3 to (0, 0, 0) const LLColor3& setToWhite(); // Zero LLColor3 to (0, 0, 0) diff --git a/indra/llmath/v4color.cpp b/indra/llmath/v4color.cpp index 83870941df..4e2287eee2 100644 --- a/indra/llmath/v4color.cpp +++ b/indra/llmath/v4color.cpp @@ -205,6 +205,55 @@ LLColor4 vec3to4(const LLColor3 &vec) return temp; } +void LLColor4::calcHSL(F32* hue, F32* saturation, F32* luminance) const +{ + F32 var_R = mV[VRED]; + F32 var_G = mV[VGREEN]; + F32 var_B = mV[VBLUE]; + + F32 var_Min = ( var_R < ( var_G < var_B ? var_G : var_B ) ? var_R : ( var_G < var_B ? var_G : var_B ) ); + F32 var_Max = ( var_R > ( var_G > var_B ? var_G : var_B ) ? var_R : ( var_G > var_B ? var_G : var_B ) ); + + F32 del_Max = var_Max - var_Min; + + F32 L = ( var_Max + var_Min ) / 2.0f; + F32 H = 0.0f; + F32 S = 0.0f; + + if ( del_Max == 0.0f ) + { + H = 0.0f; + S = 0.0f; + } + else + { + if ( L < 0.5 ) + S = del_Max / ( var_Max + var_Min ); + else + S = del_Max / ( 2.0f - var_Max - var_Min ); + + F32 del_R = ( ( ( var_Max - var_R ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; + F32 del_G = ( ( ( var_Max - var_G ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; + F32 del_B = ( ( ( var_Max - var_B ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max; + + if ( var_R >= var_Max ) + H = del_B - del_G; + else + if ( var_G >= var_Max ) + H = ( 1.0f / 3.0f ) + del_R - del_B; + else + if ( var_B >= var_Max ) + H = ( 2.0f / 3.0f ) + del_G - del_R; + + if ( H < 0.0f ) H += 1.0f; + if ( H > 1.0f ) H -= 1.0f; + } + + if (hue) *hue = H; + if (saturation) *saturation = S; + if (luminance) *luminance = L; +} + // static BOOL LLColor4::parseColor(const char* buf, LLColor4* color) { diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h index 8fe5846e26..ef9c5d4769 100644 --- a/indra/llmath/v4color.h +++ b/indra/llmath/v4color.h @@ -54,6 +54,8 @@ class LLColor4 mV[3] = (F32) sd[3].asReal(); } + void calcHSL(F32* hue, F32* saturation, F32* luminance) const; + const LLColor4& setToBlack(); // zero LLColor4 to (0, 0, 0, 1) const LLColor4& setToWhite(); // zero LLColor4 to (0, 0, 0, 1) |