nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef COLOR_H 00024 #define COLOR_H 00025 00026 #include "SystemTypes.h" 00027 00028 namespace nux 00029 { 00030 00031 #define NUX_COLOR_RGB(r, g, b) 00032 00033 #define NUX_COLOR_ARGB(a,r,g,b) ((Color)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) 00034 00035 // DirectX D3DFormat 00036 // All formats are listed from left to right, most significant bit (MSB) to least significant bit (LSB). For example, 00037 // D3DFORMAT_ARGB is ordered from the MSB channel A (alpha), to the LSB channel B (blue). When traversing surface data, 00038 // the data is stored in memory from LSB to MSB, which means that the channel order in memory is from LSB (blue) to MSB (alpha). 00039 // 00040 // The default value for formats that contain undefined channels (G16R16, A8, and so on) is 1. The only exception is the 00041 // A8 format, which is initialized to 000 for the three color channels. 00042 // 00043 // The order of the bits is from the most significant byte first, so D3DFMT_A8L8 indicates that the high byte of this 2-byte 00044 // format is alpha. D3DFMT_D16 indicates a 16-bit integer value and an application-lockable surface. 00045 // 00046 // Pixel formats have been chosen to enable the expression of hardware-vendor-defined extension formats, as well as to include 00047 // the well-established four-character code (FOURCC) method. The set of formats understood by the Microsoft Direct3D runtime 00048 // is defined by D3DFORMAT. 00049 // 00050 // 00051 00052 00053 //Format of RGBA colors is 00054 //7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 00055 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00056 //| alpha | red | green | blue | 00057 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00058 //MSB 31 0 LSB 00059 00060 00061 #define NUX_RGBA_GET_ALPHA(rgba) ((rgba) >> 24) 00062 #define NUX_RGBA_GET_RED(rgba) (((rgba) >> 16) & 0xff) 00063 #define NUX_RGBA_GET_GREEN(rgba) (((rgba) >> 8) & 0xff) 00064 #define NUX_RGBA_GET_BLUE(rgba) ((rgba) & 0xff) 00065 #define NUX_RGBA(r, g, b, a) ((a << 24) | (r << 16) | (g << 8) | b) 00066 #define NUX_RGB(r, g, b) ((r << 16) | (g << 8) | b) 00067 00068 00069 00070 00071 //Format of RGB colors is 00072 //7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 00073 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00074 //| ignored | red | green | blue | 00075 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00076 00077 //Format of BGR colors is 00078 //7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 00079 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00080 //| ignored | blue | green | red | 00081 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00082 00083 //Format of RGBA colors is 00084 //7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 00085 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00086 //| red | green | blue | alpha | 00087 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00088 00089 //Format of BGRA colors is 00090 //7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 00091 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00092 //| blue | green | red | alpha | 00093 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00094 00095 00096 enum eColorModel {CM_RGB, CM_HSV, CM_HLS, CM_YUV}; 00097 enum eColorChannel {CC_RED, CC_GREEN, CC_BLUE, CC_HUE, CC_SATURATION, CC_LIGHT , CC_VALUE}; 00098 00099 class Color 00100 { 00101 public: 00102 enum Format 00103 { 00104 COLORFORMAT_FLOAT = 0, 00105 COLORFORMAT_HEX, 00106 COLORFORMAT_INT, 00107 }; 00108 00109 Color(); 00110 ~Color(); 00111 Color (const Color &); 00112 explicit Color (unsigned int c); 00113 Color (float r, float g, float b); 00114 Color (float r, float g, float b, float a); 00115 Color *Clone() const; 00116 00117 Color &operator = (const Color &); 00118 bool operator == (const Color &) const; 00119 bool operator != (const Color &) const; 00120 00121 void SetRGB (float r, float g, float b); 00122 void SetRGBA (float r, float g, float b, float a); 00123 00124 void ClampVal(); 00125 void Saturate(); 00126 void Complement(); 00127 Color Luminance(); 00128 Color OneMinusLuminance(); 00129 00130 float GetRed() const; 00131 float GetGreen() const; 00132 float GetBlue() const; 00133 float GetAlpha() const; 00134 float R() const; 00135 float G() const; 00136 float B() const; 00137 float A() const; 00138 void SetRed (float r); 00139 void SetGreen (float g); 00140 void SetBlue (float b); 00141 void SetAlpha (float a); 00142 00143 00144 static Color RandomColor(); 00145 static unsigned int RandomColorINT(); 00146 00147 friend Color operator + (Color color0, Color color1); 00148 friend Color operator - (Color color0, Color color1); 00149 friend Color operator + (float, Color color); 00150 friend Color operator + (Color color, float); 00151 friend Color operator - (float, Color color); 00152 friend Color operator - (Color color, float); 00153 friend Color operator * (float, Color color); 00154 friend Color operator * (Color color, float); 00155 00156 00157 private: 00158 float _red; 00159 float _green; 00160 float _blue; 00161 float _alpha; 00162 00163 public: 00164 00165 // These are now deprecated. Use colors defined in the name space nux::Colors instead. See Colors.h. 00166 00167 //X11 color names from:http://en.wikipedia.org/wiki/Web_colors 00168 00169 //Red colors 00170 static const Color IndianRed ;// CD 5C 5C 205 92 92 00171 static const Color LightCoral ;// F0 80 80 240 128 128 00172 static const Color Salmon ;// FA 80 72 250 128 114 00173 static const Color DarkSalmon ;// E9 96 7A 233 150 122 00174 static const Color LightSalmon ;// FF A0 7A 255 160 122 00175 static const Color Crimson ;// DC 14 3C 220 20 60 00176 static const Color Red ;// FF 00 00 255 0 0 00177 static const Color FireBrick ;// B2 22 22 178 34 34 00178 static const Color DarkRed ;// 8B 00 00 139 0 0 00179 00180 //Pink colors 00181 static const Color Pink ;// FF C0 CB 255 192 203 00182 static const Color LightPink ;// FF B6 C1 255 182 193 00183 static const Color HotPink ;// FF 69 B4 255 105 180 00184 static const Color DeepPink ;// FF 14 93 255 20 147 00185 static const Color MediumVioletRed ;// C7 15 85 199 21 133 00186 static const Color PaleVioletRed ;// DB 70 93 219 112 147 00187 00188 //Orange colors ;// 00189 //static const Color LightSalmon ;// FF A0 7A 255 160 122 00190 static const Color Coral ;// FF 7F 50 255 127 80 00191 static const Color Tomato ;// FF 63 47 255 99 71 00192 static const Color OrangeRed ;// FF 45 00 255 69 0 00193 static const Color DarkOrange ;// FF 8C 00 255 140 0 00194 static const Color Orange ;// FF A5 00 255 165 0 00195 00196 //Yellow colors ;// 00197 static const Color Gold ;// FF D7 00 255 215 0 00198 static const Color Yellow ;// FF FF 00 255 255 0 00199 static const Color LightYellow ;// FF FF E0 255 255 224 00200 static const Color LemonChiffon ;// FF FA CD 255 250 205 00201 static const Color LightGoldenrodYellow;// FA FA D2 250 250 210 00202 static const Color PapayaWhip ;// FF EF D5 255 239 213 00203 static const Color Moccasin ;// FF E4 B5 255 228 181 00204 static const Color PeachPuff ;// FF DA B9 255 218 185 00205 static const Color PaleGoldenrod ;// EE E8 AA 238 232 170 00206 static const Color Khaki ;// F0 E6 8C 240 230 140 00207 static const Color DarkKhaki ;// BD B7 6B 189 183 107 00208 00209 //Purple colors 00210 static const Color Lavender ;// E6 E6 FA 230 230 250 00211 static const Color Thistle ;// D8 BF D8 216 191 216 00212 static const Color Plum ;// DD A0 DD 221 160 221 00213 static const Color Violet ;// EE 82 EE 238 130 238 00214 static const Color Orchid ;// DA 70 D6 218 112 214 00215 static const Color Fuchsia ;// FF 00 FF 255 0 255 00216 static const Color Magenta ;// FF 00 FF 255 0 255 00217 static const Color MediumOrchid ;// BA 55 D3 186 85 211 00218 static const Color MediumPurple ;// 93 70 DB 147 112 219 00219 static const Color BlueViolet ;// 8A 2B E2 138 43 226 00220 static const Color DarkViolet ;// 94 00 D3 148 0 211 00221 static const Color DarkOrchid ;// 99 32 CC 153 50 204 00222 static const Color DarkMagenta ;// 8B 00 8B 139 0 139 00223 static const Color Purple ;// 80 00 80 128 0 128 00224 static const Color Indigo ;// 4B 00 82 75 0 130 00225 static const Color SlateBlue ;// 6A 5A CD 106 90 205 00226 static const Color DarkSlateBlue ;// 48 3D 8B 72 61 139 00227 00228 //Green colors 00229 static const Color GreenYellow ;// AD FF 2F 173 255 47 00230 static const Color Chartreuse ;// 7F FF 00 127 255 0 00231 static const Color LawnGreen ;// 7C FC 00 124 252 0 00232 static const Color Lime ;// 00 FF 00 0 255 0 00233 static const Color LimeGreen ;// 32 CD 32 50 205 50 00234 static const Color PaleGreen ;// 98 FB 98 152 251 152 00235 static const Color LightGreen ;// 90 EE 90 144 238 144 00236 static const Color MediumSpringGreen ;// 00 FA 9A 0 250 154 00237 static const Color SpringGreen ;// 00 FF 7F 0 255 127 00238 static const Color MediumSeaGreen ;// 3C B3 71 60 179 113 00239 static const Color SeaGreen ;// 2E 8B 57 46 139 87 00240 static const Color ForestGreen ;// 22 8B 22 34 139 34 00241 static const Color Green ;// 00 80 00 0 128 0 00242 static const Color DarkGreen ;// 00 64 00 0 100 0 00243 static const Color YellowGreen ;// 9A CD 32 154 205 50 00244 static const Color OliveDrab ;// 6B 8E 23 107 142 35 00245 static const Color Olive ;// 80 80 00 128 128 0 00246 static const Color DarkOliveGreen ;// 55 6B 2F 85 107 47 00247 static const Color MediumAquamarine ;// 66 CD AA 102 205 170 00248 static const Color DarkSeaGreen ;// 8F BC 8F 143 188 143 00249 static const Color LightSeaGreen ;// 20 B2 AA 32 178 170 00250 static const Color DarkCyan ;// 00 8B 8B 0 139 139 00251 static const Color Teal ;// 00 80 80 0 128 128 00252 00253 //Blue colors ;// 00254 static const Color Aqua ;// 00 FF FF 0 255 255 00255 static const Color Cyan ;// 00 FF FF 0 255 255 00256 static const Color LightCyan ;// E0 FF FF 224 255 255 00257 static const Color PaleTurquoise ;// AF EE EE 175 238 238 00258 static const Color Aquamarine ;// 7F FF D4 127 255 212 00259 static const Color Turquoise ;// 40 E0 D0 64 224 208 00260 static const Color MediumTurquoise ;// 48 D1 CC 72 209 204 00261 static const Color DarkTurquoise ;// 00 CE D1 0 206 209 00262 static const Color CadetBlue ;// 5F 9E A0 95 158 160 00263 static const Color SteelBlue ;// 46 82 B4 70 130 180 00264 static const Color LightSteelBlue ;// B0 C4 DE 176 196 222 00265 static const Color PowderBlue ;// B0 E0 E6 176 224 230 00266 static const Color LightBlue ;// AD D8 E6 173 216 230 00267 static const Color SkyBlue ;// 87 CE EB 135 206 235 00268 static const Color LightSkyBlue ;// 87 CE FA 135 206 250 00269 static const Color DeepSkyBlue ;// 00 BF FF 0 191 255 00270 static const Color DodgerBlue ;// 1E 90 FF 30 144 255 00271 static const Color CornflowerBlue ;// 64 95 ED 100 149 237 00272 static const Color MediumSlateBlue ;// 7B 68 EE 123 104 238 00273 static const Color RoyalBlue ;// 41 69 E1 65 105 225 00274 static const Color Blue ;// 00 00 FF 0 0 255 00275 static const Color MediumBlue ;// 00 00 CD 0 0 205 00276 static const Color DarkBlue ;// 00 00 8B 0 0 139 00277 static const Color Navy ;// 00 00 80 0 0 128 00278 static const Color MidnightBlue ;// 19 19 70 25 25 112 00279 00280 //Brown colors ;// 00281 static const Color Cornsilk ;// FF F8 DC 255 248 220 00282 static const Color BlanchedAlmond ;// FF EB CD 255 235 205 00283 static const Color Bisque ;// FF E4 C4 255 228 196 00284 static const Color NavajoWhite ;// FF DE AD 255 222 173 00285 static const Color Wheat ;// F5 DE B3 245 222 179 00286 static const Color BurlyWood ;// DE B8 87 222 184 135 00287 static const Color Tan ;// D2 B4 8C 210 180 140 00288 static const Color RosyBrown ;// BC 8F 8F 188 143 143 00289 static const Color SandyBrown ;// F4 A4 60 244 164 96 00290 static const Color Goldenrod ;// DA A5 20 218 165 32 00291 static const Color DarkGoldenrod ;// B8 86 0B 184 134 11 00292 static const Color Peru ;// CD 85 3F 205 133 63 00293 static const Color Chocolate ;// D2 69 1E 210 105 30 00294 static const Color SaddleBrown ;// 8B 45 13 139 69 19 00295 static const Color Sienna ;// A0 52 2D 160 82 45 00296 static const Color Brown ;// A5 2A 2A 165 42 42 00297 static const Color Maroon ;// 80 00 00 128 0 0 00298 00299 //White colors ;// 00300 static const Color White ;// FF FF FF 255 255 255 00301 static const Color Snow ;// FF FA FA 255 250 250 00302 static const Color Honeydew ;// F0 FF F0 240 255 240 00303 static const Color MintCream ;// F5 FF FA 245 255 250 00304 static const Color Azure ;// F0 FF FF 240 255 255 00305 static const Color AliceBlue ;// F0 F8 FF 240 248 255 00306 static const Color GhostWhite ;// F8 F8 FF 248 248 255 00307 static const Color WhiteSmoke ;// F5 F5 F5 245 245 245 00308 static const Color Seashell ;// FF F5 EE 255 245 238 00309 static const Color Beige ;// F5 F5 DC 245 245 220 00310 static const Color OldLace ;// FD F5 E6 253 245 230 00311 static const Color FloralWhite ;// FF FA F0 255 250 240 00312 static const Color Ivory ;// FF FF F0 255 255 240 00313 static const Color AntiqueWhite ;// FA EB D7 250 235 215 00314 static const Color Linen ;// FA F0 E6 250 240 230 00315 static const Color LavenderBlush ;// FF F0 F5 255 240 245 00316 static const Color MistyRose ;// FF E4 E1 255 228 225 00317 00318 //Grey colors ;// 00319 static const Color Gainsboro ;// DC DC DC 220 220 220 00320 static const Color LightGrey ;// D3 D3 D3 211 211 211 00321 static const Color Silver ;// C0 C0 C0 192 192 192 00322 static const Color DarkGray ;// A9 A9 A9 169 169 169 00323 static const Color Gray ;// 80 80 80 128 128 128 00324 static const Color DimGray ;// 69 69 69 105 105 105 00325 static const Color LightSlateGray ;// 77 88 99 119 136 153 00326 static const Color SlateGray ;// 70 80 90 112 128 144 00327 static const Color DarkSlateGray ;// 2F 4F 4F 47 79 79 00328 static const Color Black ;// 00 00 00 0 0 0 00329 00330 // More Colors 00331 static const Color Aubergine ;// 2B 0B 30 43 11 48 00332 00333 static Color Dummy; 00334 }; 00335 00336 void RGBtoHSV ( float r, float g, float b, float &h, float &s, float &v ); 00337 void HSVtoRGB ( float &r, float &g, float &b, float h, float s, float v ); 00338 void HLStoRGB (float &r, float &g, float &b, float hue, float light, float satur); 00339 void RGBtoHLS (float rr, float gg, float bb, float &hue, float &light, float &satur); 00340 00341 } 00342 00343 #endif // COLOR_H 00344 00345 /* 00346 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnopen/html/msdn_gl5.asp 00347 00348 OpenGL V: Translating Windows DIBs 00349 February 8, 1995 00350 00351 Abstract 00352 00353 OpenGL (TM) is a portable language for rendering three-dimensional (3-D) graphics. OpenGL does not understand Microsoft? Windows? device-independent bitmaps (DIBs); instead, it has its own format for representing images. This article explains how to translate a Windows DIB into a format usable with OpenGL. Some knowledge of the Windows DIB format and the Microsoft Foundation Class Library (MFC) is expected. The EasyDIB sample application and GLlib dynamic-link library (DLL) demonstrate the ideas presented in this article. 00354 00355 */ 00356 00357 00358