1 // ---------------------------------------------------------------------------
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
9 // note: Private header
11 // ---------------------------------------------------------------------------
14 #if !defined ANT_TW_COLORS_INCLUDED
15 #define ANT_TW_COLORS_INCLUDED
18 // ---------------------------------------------------------------------------
21 typedef unsigned int color32;
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
32 template <typename _T> inline const _T& TClamp(const _T& _X, const _T& _Limit1, const _T& _Limit2)
35 return (_X<=_Limit1) ? _Limit1 : ( (_X>=_Limit2) ? _Limit2 : _X );
37 return (_X<=_Limit2) ? _Limit2 : ( (_X>=_Limit1) ? _Limit1 : _X );
40 inline color32 Color32FromARGBi(int _A, int _R, int _G, int _B)
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));
45 inline color32 Color32FromARGBf(float _A, float _R, float _G, float _B)
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));
50 inline void Color32ToARGBi(color32 _Color, int *_A, int *_R, int *_G, int *_B)
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;
58 inline void Color32ToARGBf(color32 _Color, float *_A, float *_R, float *_G, float *_B)
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);
66 void ColorRGBToHLSf(float _R, float _G, float _B, float *_Hue, float *_Light, float *_Saturation);
68 void ColorRGBToHLSi(int _R, int _G, int _B, int *_Hue, int *_Light, int *_Saturation);
70 void ColorHLSToRGBf(float _Hue, float _Light, float _Saturation, float *_R, float *_G, float *_B);
72 void ColorHLSToRGBi(int _Hue, int _Light, int _Saturation, int *_R, int *_G, int *_B);
74 color32 ColorBlend(color32 _Color1, color32 _Color2, float _S);
77 // ---------------------------------------------------------------------------
80 #endif // !defined ANT_TW_COLORS_INCLUDED