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.

377 lines
13 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * Image Attributes
  8. *
  9. * Abstract:
  10. *
  11. * GDI+ Image Attributes used with Graphics.DrawImage
  12. *
  13. * There are 5 possible sets of color adjustments:
  14. * ColorAdjustDefault,
  15. * ColorAdjustBitmap,
  16. * ColorAdjustBrush,
  17. * ColorAdjustPen,
  18. * ColorAdjustText,
  19. *
  20. * Bitmaps, Brushes, Pens, and Text will all use any color adjustments
  21. * that have been set into the default ImageAttributes until their own
  22. * color adjustments have been set. So as soon as any "Set" method is
  23. * called for Bitmaps, Brushes, Pens, or Text, then they start from
  24. * scratch with only the color adjustments that have been set for them.
  25. * Calling Reset removes any individual color adjustments for a type
  26. * and makes it revert back to using all the default color adjustments
  27. * (if any). The SetToIdentity method is a way to force a type to
  28. * have no color adjustments at all, regardless of what previous adjustments
  29. * have been set for the defaults or for that type.
  30. *
  31. \********************************************************************F******/
  32. #ifndef _GDIPLUSIMAGEATTRIBUTES_H
  33. #define _GDIPLUSIMAGEATTRIBUTES_H
  34. class GpImageAttributes;
  35. class ImageAttributes : public GdiplusBase
  36. {
  37. friend class Graphics;
  38. friend class TextureBrush;
  39. public:
  40. ImageAttributes()
  41. {
  42. nativeImageAttr = NULL;
  43. lastResult = DllExports::GdipCreateImageAttributes(&nativeImageAttr);
  44. }
  45. ~ImageAttributes()
  46. {
  47. DllExports::GdipDisposeImageAttributes(nativeImageAttr);
  48. }
  49. ImageAttributes* Clone() const
  50. {
  51. GpImageAttributes* clone;
  52. SetStatus(DllExports::GdipCloneImageAttributes(
  53. nativeImageAttr,
  54. &clone));
  55. return new ImageAttributes(clone, lastResult);
  56. }
  57. Status
  58. SetToIdentity(
  59. IN ColorAdjustType type = ColorAdjustTypeDefault
  60. )
  61. {
  62. return SetStatus(DllExports::GdipSetImageAttributesToIdentity(
  63. nativeImageAttr,
  64. type));
  65. }
  66. Status
  67. Reset(
  68. IN ColorAdjustType type = ColorAdjustTypeDefault
  69. )
  70. {
  71. return SetStatus(DllExports::GdipResetImageAttributes(
  72. nativeImageAttr,
  73. type));
  74. }
  75. Status
  76. SetColorMatrix(
  77. IN const ColorMatrix *colorMatrix,
  78. IN ColorMatrixFlags mode = ColorMatrixFlagsDefault,
  79. IN ColorAdjustType type = ColorAdjustTypeDefault
  80. )
  81. {
  82. return SetStatus(DllExports::GdipSetImageAttributesColorMatrix(
  83. nativeImageAttr,
  84. type,
  85. TRUE,
  86. colorMatrix,
  87. NULL,
  88. mode));
  89. }
  90. Status ClearColorMatrix(
  91. IN ColorAdjustType type = ColorAdjustTypeDefault
  92. )
  93. {
  94. return SetStatus(DllExports::GdipSetImageAttributesColorMatrix(
  95. nativeImageAttr,
  96. type,
  97. FALSE,
  98. NULL,
  99. NULL,
  100. ColorMatrixFlagsDefault));
  101. }
  102. Status
  103. SetColorMatrices(
  104. IN const ColorMatrix *colorMatrix,
  105. IN const ColorMatrix *grayMatrix,
  106. IN ColorMatrixFlags mode = ColorMatrixFlagsDefault,
  107. IN ColorAdjustType type = ColorAdjustTypeDefault
  108. )
  109. {
  110. return SetStatus(DllExports::GdipSetImageAttributesColorMatrix(
  111. nativeImageAttr,
  112. type,
  113. TRUE,
  114. colorMatrix,
  115. grayMatrix,
  116. mode));
  117. }
  118. Status ClearColorMatrices(
  119. IN ColorAdjustType type = ColorAdjustTypeDefault
  120. )
  121. {
  122. return SetStatus(DllExports::GdipSetImageAttributesColorMatrix(
  123. nativeImageAttr,
  124. type,
  125. FALSE,
  126. NULL,
  127. NULL,
  128. ColorMatrixFlagsDefault));
  129. }
  130. Status SetThreshold(
  131. IN REAL threshold,
  132. IN ColorAdjustType type = ColorAdjustTypeDefault
  133. )
  134. {
  135. return SetStatus(DllExports::GdipSetImageAttributesThreshold(
  136. nativeImageAttr,
  137. type,
  138. TRUE,
  139. threshold));
  140. }
  141. Status ClearThreshold(
  142. IN ColorAdjustType type = ColorAdjustTypeDefault
  143. )
  144. {
  145. return SetStatus(DllExports::GdipSetImageAttributesThreshold(
  146. nativeImageAttr,
  147. type,
  148. FALSE,
  149. 0.0));
  150. }
  151. Status SetGamma(
  152. IN REAL gamma,
  153. IN ColorAdjustType type = ColorAdjustTypeDefault
  154. )
  155. {
  156. return SetStatus(DllExports::GdipSetImageAttributesGamma(
  157. nativeImageAttr,
  158. type,
  159. TRUE,
  160. gamma));
  161. }
  162. Status ClearGamma(
  163. IN ColorAdjustType type = ColorAdjustTypeDefault
  164. )
  165. {
  166. return SetStatus(DllExports::GdipSetImageAttributesGamma(
  167. nativeImageAttr,
  168. type,
  169. FALSE,
  170. 0.0));
  171. }
  172. Status SetNoOp(
  173. IN ColorAdjustType type = ColorAdjustTypeDefault
  174. )
  175. {
  176. return SetStatus(DllExports::GdipSetImageAttributesNoOp(
  177. nativeImageAttr,
  178. type,
  179. TRUE));
  180. }
  181. Status ClearNoOp(
  182. IN ColorAdjustType type = ColorAdjustTypeDefault
  183. )
  184. {
  185. return SetStatus(DllExports::GdipSetImageAttributesNoOp(
  186. nativeImageAttr,
  187. type,
  188. FALSE));
  189. }
  190. Status SetColorKey(
  191. IN const Color& colorLow,
  192. IN const Color& colorHigh,
  193. IN ColorAdjustType type = ColorAdjustTypeDefault
  194. )
  195. {
  196. return SetStatus(DllExports::GdipSetImageAttributesColorKeys(
  197. nativeImageAttr,
  198. type,
  199. TRUE,
  200. colorLow.GetValue(),
  201. colorHigh.GetValue()));
  202. }
  203. Status ClearColorKey(
  204. IN ColorAdjustType type = ColorAdjustTypeDefault
  205. )
  206. {
  207. return SetStatus(DllExports::GdipSetImageAttributesColorKeys(
  208. nativeImageAttr,
  209. type,
  210. FALSE,
  211. NULL,
  212. NULL));
  213. }
  214. Status SetOutputChannel(
  215. IN ColorChannelFlags channelFlags,
  216. IN ColorAdjustType type = ColorAdjustTypeDefault
  217. )
  218. {
  219. return SetStatus(DllExports::GdipSetImageAttributesOutputChannel(
  220. nativeImageAttr,
  221. type,
  222. TRUE,
  223. channelFlags));
  224. }
  225. Status ClearOutputChannel(
  226. IN ColorAdjustType type = ColorAdjustTypeDefault
  227. )
  228. {
  229. return SetStatus(DllExports::GdipSetImageAttributesOutputChannel(
  230. nativeImageAttr,
  231. type,
  232. FALSE,
  233. ColorChannelFlagsLast));
  234. }
  235. Status SetOutputChannelColorProfile(
  236. IN const WCHAR *colorProfileFilename,
  237. IN ColorAdjustType type = ColorAdjustTypeDefault
  238. )
  239. {
  240. return SetStatus(DllExports::GdipSetImageAttributesOutputChannelColorProfile(
  241. nativeImageAttr,
  242. type,
  243. TRUE,
  244. colorProfileFilename));
  245. }
  246. Status ClearOutputChannelColorProfile(
  247. IN ColorAdjustType type = ColorAdjustTypeDefault
  248. )
  249. {
  250. return SetStatus(DllExports::GdipSetImageAttributesOutputChannelColorProfile(
  251. nativeImageAttr,
  252. type,
  253. FALSE,
  254. NULL));
  255. }
  256. Status SetRemapTable(
  257. IN UINT mapSize,
  258. IN const ColorMap *map,
  259. IN ColorAdjustType type = ColorAdjustTypeDefault
  260. )
  261. {
  262. return SetStatus(DllExports::GdipSetImageAttributesRemapTable(
  263. nativeImageAttr,
  264. type,
  265. TRUE,
  266. mapSize,
  267. map));
  268. }
  269. Status ClearRemapTable(
  270. IN ColorAdjustType type = ColorAdjustTypeDefault
  271. )
  272. {
  273. return SetStatus(DllExports::GdipSetImageAttributesRemapTable(
  274. nativeImageAttr,
  275. type,
  276. FALSE,
  277. 0,
  278. NULL));
  279. }
  280. Status SetBrushRemapTable(IN UINT mapSize,
  281. IN const ColorMap *map)
  282. {
  283. return this->SetRemapTable(mapSize, map, ColorAdjustTypeBrush);
  284. }
  285. Status ClearBrushRemapTable()
  286. {
  287. return this->ClearRemapTable(ColorAdjustTypeBrush);
  288. }
  289. Status SetWrapMode(IN WrapMode wrap,
  290. IN const Color& color = Color(),
  291. IN BOOL clamp = FALSE)
  292. {
  293. ARGB argb = color.GetValue();
  294. return SetStatus(DllExports::GdipSetImageAttributesWrapMode(
  295. nativeImageAttr, wrap, argb, clamp));
  296. }
  297. // The flags of the palette are ignored.
  298. Status GetAdjustedPalette(IN OUT ColorPalette* colorPalette,
  299. IN ColorAdjustType colorAdjustType) const
  300. {
  301. return SetStatus(DllExports::GdipGetImageAttributesAdjustedPalette(
  302. nativeImageAttr, colorPalette, colorAdjustType));
  303. }
  304. Status GetLastStatus() const
  305. {
  306. Status lastStatus = lastResult;
  307. lastResult = Ok;
  308. return lastStatus;
  309. }
  310. private:
  311. ImageAttributes(const ImageAttributes &);
  312. ImageAttributes& operator=(const ImageAttributes &);
  313. protected:
  314. ImageAttributes(GpImageAttributes* imageAttr, Status status)
  315. {
  316. SetNativeImageAttr(imageAttr);
  317. lastResult = status;
  318. }
  319. VOID SetNativeImageAttr(GpImageAttributes* nativeImageAttr)
  320. {
  321. this->nativeImageAttr = nativeImageAttr;
  322. }
  323. Status SetStatus(Status status) const
  324. {
  325. if (status != Ok)
  326. return (lastResult = status);
  327. else
  328. return status;
  329. }
  330. protected:
  331. GpImageAttributes* nativeImageAttr;
  332. mutable Status lastResult;
  333. };
  334. #endif