Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / AntTweakBar / src / TwColors.h
1 //  ---------------------------------------------------------------------------
2 //
3 //  @file       TwColors.h
4 //  @brief      Color conversions
5 //  @author     Philippe Decaudin - http://www.antisphere.com
6 //  @license    This file is part of the AntTweakBar library.
7 //              For conditions of distribution and use, see License.txt
8 //
9 //  note:       Private header
10 //
11 //  ---------------------------------------------------------------------------
12
13
14 #if !defined ANT_TW_COLORS_INCLUDED
15 #define ANT_TW_COLORS_INCLUDED
16
17
18 //  ---------------------------------------------------------------------------
19
20
21 typedef unsigned int color32;
22
23
24 const color32 COLOR32_BLACK     = 0xff000000;   // Black 
25 const color32 COLOR32_WHITE     = 0xffffffff;   // White 
26 const color32 COLOR32_ZERO      = 0x00000000;   // Zero 
27 const color32 COLOR32_RED       = 0xffff0000;   // Red 
28 const color32 COLOR32_GREEN     = 0xff00ff00;   // Green 
29 const color32 COLOR32_BLUE      = 0xff0000ff;   // Blue 
30    
31
32 template <typename _T> inline const _T& TClamp(const _T& _X, const _T& _Limit1, const _T& _Limit2)
33 {
34     if( _Limit1<_Limit2 )
35         return (_X<=_Limit1) ? _Limit1 : ( (_X>=_Limit2) ? _Limit2 : _X );
36     else
37         return (_X<=_Limit2) ? _Limit2 : ( (_X>=_Limit1) ? _Limit1 : _X );
38 }
39
40 inline color32 Color32FromARGBi(int _A, int _R, int _G, int _B)
41 {
42     return (((color32)TClamp(_A, 0, 255))<<24) | (((color32)TClamp(_R, 0, 255))<<16) | (((color32)TClamp(_G, 0, 255))<<8) | ((color32)TClamp(_B, 0, 255));
43 }
44
45 inline color32 Color32FromARGBf(float _A, float _R, float _G, float _B)
46 {
47     return (((color32)TClamp(_A*256.0f, 0.0f, 255.0f))<<24) | (((color32)TClamp(_R*256.0f, 0.0f, 255.0f))<<16) | (((color32)TClamp(_G*256.0f, 0.0f, 255.0f))<<8) | ((color32)TClamp(_B*256.0f, 0.0f, 255.0f));
48 }
49
50 inline void Color32ToARGBi(color32 _Color, int *_A, int *_R, int *_G, int *_B)
51 {
52     if(_A) *_A = (_Color>>24)&0xff;
53     if(_R) *_R = (_Color>>16)&0xff;
54     if(_G) *_G = (_Color>>8)&0xff;
55     if(_B) *_B = _Color&0xff;
56 }
57
58 inline void Color32ToARGBf(color32 _Color, float *_A, float *_R, float *_G, float *_B)
59 {
60     if(_A) *_A = (1.0f/255.0f)*float((_Color>>24)&0xff);
61     if(_R) *_R = (1.0f/255.0f)*float((_Color>>16)&0xff);
62     if(_G) *_G = (1.0f/255.0f)*float((_Color>>8)&0xff);
63     if(_B) *_B = (1.0f/255.0f)*float(_Color&0xff);
64 }
65
66 void ColorRGBToHLSf(float _R, float _G, float _B, float *_Hue, float *_Light, float *_Saturation);
67
68 void ColorRGBToHLSi(int _R, int _G, int _B, int *_Hue, int *_Light, int *_Saturation);
69
70 void ColorHLSToRGBf(float _Hue, float _Light, float _Saturation, float *_R, float *_G, float *_B);
71
72 void ColorHLSToRGBi(int _Hue, int _Light, int _Saturation, int *_R, int *_G, int *_B);
73
74 color32 ColorBlend(color32 _Color1, color32 _Color2, float _S);
75
76
77 //  ---------------------------------------------------------------------------
78
79
80 #endif // !defined ANT_TW_COLORS_INCLUDED