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.

GdiplusColor.h 4.2 KiB

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