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.

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