1 /**************************************************************************\ 2 * 3 * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved. 4 * 5 * Module Name: 6 * 7 * GdiplusColor.h 8 * 9 * Abstract: 10 * 11 * Represents a GDI+ color. 12 * 13 \**************************************************************************/ 14 15 #ifndef _GDIPLUSCOLOR_H 16 #define _GDIPLUSCOLOR_H 17 18 //---------------------------------------------------------------------------- 19 // Color mode 20 //---------------------------------------------------------------------------- 21 22 enum ColorMode 23 { 24 ColorModeARGB32 = 0, 25 ColorModeARGB64 = 1 26 }; 27 28 //---------------------------------------------------------------------------- 29 // Color Channel flags 30 //---------------------------------------------------------------------------- 31 32 enum ColorChannelFlags 33 { 34 ColorChannelFlagsC = 0, 35 ColorChannelFlagsM, 36 ColorChannelFlagsY, 37 ColorChannelFlagsK, 38 ColorChannelFlagsLast 39 }; 40 41 //---------------------------------------------------------------------------- 42 // Color 43 //---------------------------------------------------------------------------- 44 45 class Color 46 { 47 public: 48 Color()49 Color() 50 { 51 Argb = (ARGB)Color::Black; 52 } 53 54 // Construct an opaque Color object with 55 // the specified R, G, B values. 56 Color(IN BYTE r,IN BYTE g,IN BYTE b)57 Color(IN BYTE r, 58 IN BYTE g, 59 IN BYTE b) 60 { 61 Argb = MakeARGB(255, r, g, b); 62 } 63 64 // Construct a Color object with 65 // the specified A, R, G, B values. 66 // 67 // NOTE: R, G, B color values are not premultiplied. 68 Color(IN BYTE a,IN BYTE r,IN BYTE g,IN BYTE b)69 Color(IN BYTE a, 70 IN BYTE r, 71 IN BYTE g, 72 IN BYTE b) 73 { 74 Argb = MakeARGB(a, r, g, b); 75 } 76 77 // Construct a Color object with 78 // the specified ARGB values. 79 // 80 // NOTE: R, G, B color components are not premultiplied. 81 Color(IN ARGB argb)82 Color(IN ARGB argb) 83 { 84 Argb = argb; 85 } 86 87 // Extract A, R, G, B components 88 GetAlpha()89 BYTE GetAlpha() const 90 { 91 return (BYTE) (Argb >> AlphaShift); 92 } 93 GetA()94 BYTE GetA() const 95 { 96 return GetAlpha(); 97 } 98 GetRed()99 BYTE GetRed() const 100 { 101 return (BYTE) (Argb >> RedShift); 102 } 103 GetR()104 BYTE GetR() const 105 { 106 return GetRed(); 107 } 108 GetGreen()109 BYTE GetGreen() const 110 { 111 return (BYTE) (Argb >> GreenShift); 112 } 113 GetG()114 BYTE GetG() const 115 { 116 return GetGreen(); 117 } 118 GetBlue()119 BYTE GetBlue() const 120 { 121 return (BYTE) (Argb >> BlueShift); 122 } 123 GetB()124 BYTE GetB() const 125 { 126 return GetBlue(); 127 } 128 129 // Retrieve ARGB values 130 GetValue()131 ARGB GetValue() const 132 { 133 return Argb; 134 } 135 SetValue(IN ARGB argb)136 VOID SetValue(IN ARGB argb) 137 { 138 Argb = argb; 139 } 140 SetFromCOLORREF(IN COLORREF rgb)141 VOID SetFromCOLORREF(IN COLORREF rgb) 142 { 143 Argb = MakeARGB(255, GetRValue(rgb), GetGValue(rgb), GetBValue(rgb)); 144 } 145 ToCOLORREF()146 COLORREF ToCOLORREF() const 147 { 148 return RGB(GetRed(), GetGreen(), GetBlue()); 149 } 150 151 public: 152 153 // Standard color constants 154 enum 155 { 156 Black = 0xff000000, 157 Silver = 0xffc0c0c0, 158 Gray = 0xff808080, 159 White = 0xffffffff, 160 Maroon = 0xff800000, 161 Red = 0xffff0000, 162 Purple = 0xff800080, 163 Fuchsia = 0xffff00ff, 164 Green = 0xff008000, 165 Lime = 0xff00ff00, 166 Olive = 0xff808000, 167 Yellow = 0xffffff00, 168 Navy = 0xff000080, 169 Blue = 0xff0000ff, 170 Teal = 0xff008080, 171 Aqua = 0xff00ffff 172 }; 173 174 // Shift count and bit mask for A, R, G, B components 175 enum 176 { 177 AlphaShift = 24, 178 RedShift = 16, 179 GreenShift = 8, 180 BlueShift = 0 181 }; 182 183 enum 184 { 185 AlphaMask = 0xff000000, 186 RedMask = 0x00ff0000, 187 GreenMask = 0x0000ff00, 188 BlueMask = 0x000000ff 189 }; 190 191 // Assemble A, R, G, B values into a 32-bit integer MakeARGB(IN BYTE a,IN BYTE r,IN BYTE g,IN BYTE b)192 static ARGB MakeARGB(IN BYTE a, 193 IN BYTE r, 194 IN BYTE g, 195 IN BYTE b) 196 { 197 return (((ARGB) (b) << BlueShift) | 198 ((ARGB) (g) << GreenShift) | 199 ((ARGB) (r) << RedShift) | 200 ((ARGB) (a) << AlphaShift)); 201 } 202 203 protected: 204 205 ARGB Argb; 206 }; 207 208 #endif 209 210