Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
4.3 KiB

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