Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

398 wiersze
14 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * Image Attributes
  8. *
  9. * Abstract:
  10. *
  11. * Class for color adjustment object passed to Graphics.DrawImage
  12. *
  13. \**************************************************************************/
  14. #ifndef _GDIPLUSIMAGEATTRIBUTES_H
  15. #define _GDIPLUSIMAGEATTRIBUTES_H
  16. class GpImageAttributes;
  17. // There are 5 possible sets of color adjustments:
  18. // ColorAdjustDefault,
  19. // ColorAdjustBitmap,
  20. // ColorAdjustBrush,
  21. // ColorAdjustPen,
  22. // ColorAdjustText,
  23. // Bitmaps, Brushes, Pens, and Text will all use any color adjustments
  24. // that have been set into the default ImageAttributes until their own
  25. // color adjustments have been set. So as soon as any "Set" method is
  26. // called for Bitmaps, Brushes, Pens, or Text, then they start from
  27. // scratch with only the color adjustments that have been set for them.
  28. // Calling Reset removes any individual color adjustments for a type
  29. // and makes it revert back to using all the default color adjustments
  30. // (if any). The SetToIdentity method is a way to force a type to
  31. // have no color adjustments at all, regardless of what previous adjustments
  32. // have been set for the defaults or for that type.
  33. class ImageAttributes : public GdiplusBase
  34. {
  35. friend class Graphics;
  36. friend class TextureBrush;
  37. public:
  38. ImageAttributes()
  39. {
  40. nativeImageAttr = NULL;
  41. lastResult = DllExports::GdipCreateImageAttributes(&nativeImageAttr);
  42. }
  43. ~ImageAttributes()
  44. {
  45. DllExports::GdipDisposeImageAttributes(nativeImageAttr);
  46. }
  47. ImageAttributes* Clone() const
  48. {
  49. GpImageAttributes* clone;
  50. SetStatus(DllExports::GdipCloneImageAttributes(
  51. nativeImageAttr,
  52. &clone));
  53. return new ImageAttributes(clone, lastResult);
  54. }
  55. // Set to identity, regardless of what the default color adjustment is.
  56. Status
  57. SetToIdentity(
  58. IN ColorAdjustType type = ColorAdjustTypeDefault
  59. )
  60. {
  61. return SetStatus(DllExports::GdipSetImageAttributesToIdentity(
  62. nativeImageAttr,
  63. type));
  64. }
  65. // Remove any individual color adjustments, and go back to using the default
  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. #ifndef DCR_USE_NEW_145139
  298. Status SetICMMode(IN BOOL on)
  299. {
  300. on;
  301. // This is not implemented.
  302. // The supported method for doing ICM conversion from the embedded
  303. // ICC profile is to use the Bitmap constructor from a file or stream
  304. // and specify TRUE for the useIcm parameter. This will cause the
  305. // image to be ICM converted when it's loaded from the file/stream
  306. // if the profile exists.
  307. return SetStatus(NotImplemented);
  308. // DllExports::GdipSetImageAttributesICMMode(nativeImageAttr, on)
  309. }
  310. #endif
  311. // The flags of the palette are ignored.
  312. Status GetAdjustedPalette(IN OUT ColorPalette* colorPalette,
  313. IN ColorAdjustType colorAdjustType) const
  314. {
  315. return SetStatus(DllExports::GdipGetImageAttributesAdjustedPalette(
  316. nativeImageAttr, colorPalette, colorAdjustType));
  317. }
  318. Status GetLastStatus() const
  319. {
  320. Status lastStatus = lastResult;
  321. lastResult = Ok;
  322. return lastStatus;
  323. }
  324. #ifdef DCR_USE_NEW_250932
  325. private:
  326. ImageAttributes(const ImageAttributes &);
  327. ImageAttributes& operator=(const ImageAttributes &);
  328. #endif
  329. protected:
  330. ImageAttributes(GpImageAttributes* imageAttr, Status status)
  331. {
  332. SetNativeImageAttr(imageAttr);
  333. lastResult = status;
  334. }
  335. VOID SetNativeImageAttr(GpImageAttributes* nativeImageAttr)
  336. {
  337. this->nativeImageAttr = nativeImageAttr;
  338. }
  339. Status SetStatus(Status status) const
  340. {
  341. if (status != Ok)
  342. return (lastResult = status);
  343. else
  344. return status;
  345. }
  346. protected:
  347. GpImageAttributes* nativeImageAttr;
  348. mutable Status lastResult;
  349. };
  350. #endif