GdiPlusimageAttributes.h 12 KB

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