gdiplusimageattributes.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * gdiplusimageattributes.h
  3. *
  4. * GDI+ ImageAttributes class
  5. *
  6. * This file is part of the w32api package.
  7. *
  8. * Contributors:
  9. * Created by Markus Koenig <markus@stber-koenig.de>
  10. *
  11. * THIS SOFTWARE IS NOT COPYRIGHTED
  12. *
  13. * This source code is offered for use in the public domain. You may
  14. * use, modify or distribute it freely.
  15. *
  16. * This code is distributed in the hope that it will be useful but
  17. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18. * DISCLAIMED. This includes but is not limited to warranties of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. */
  22. #ifndef __GDIPLUS_IMAGEATTRIBUTES_H
  23. #define __GDIPLUS_IMAGEATTRIBUTES_H
  24. #if __GNUC__ >=3
  25. #pragma GCC system_header
  26. #endif
  27. #ifndef __cplusplus
  28. #error "A C++ compiler is required to include gdiplusimageattributes.h."
  29. #endif
  30. class ImageAttributes: public GdiplusBase
  31. {
  32. friend class Graphics;
  33. friend class TextureBrush;
  34. public:
  35. ImageAttributes(): nativeImageAttributes(NULL), lastStatus(Ok)
  36. {
  37. lastStatus = DllExports::GdipCreateImageAttributes(
  38. &nativeImageAttributes);
  39. }
  40. ~ImageAttributes()
  41. {
  42. DllExports::GdipDisposeImageAttributes(nativeImageAttributes);
  43. }
  44. ImageAttributes* Clone() const
  45. {
  46. GpImageAttributes *cloneImageAttributes = NULL;
  47. Status status = updateStatus(DllExports::GdipCloneImageAttributes(
  48. nativeImageAttributes, &cloneImageAttributes));
  49. if (status == Ok) {
  50. ImageAttributes *result = new ImageAttributes(
  51. cloneImageAttributes, lastStatus);
  52. if (!result) {
  53. DllExports::GdipDisposeImageAttributes(cloneImageAttributes);
  54. lastStatus = OutOfMemory;
  55. }
  56. return result;
  57. } else {
  58. return NULL;
  59. }
  60. }
  61. Status ClearBrushRemapTable()
  62. {
  63. return updateStatus(DllExports::GdipSetImageAttributesRemapTable(
  64. nativeImageAttributes, ColorAdjustTypeBrush,
  65. FALSE, 0, NULL));
  66. }
  67. Status ClearColorKey(ColorAdjustType type = ColorAdjustTypeDefault)
  68. {
  69. return updateStatus(DllExports::GdipSetImageAttributesColorKeys(
  70. nativeImageAttributes, type, FALSE, 0, 0));
  71. }
  72. Status ClearColorMatrices(ColorAdjustType type = ColorAdjustTypeDefault)
  73. {
  74. return updateStatus(DllExports::GdipSetImageAttributesColorMatrix(
  75. nativeImageAttributes, type, FALSE,
  76. NULL, NULL, ColorMatrixFlagsDefault));
  77. }
  78. Status ClearColorMatrix(ColorAdjustType type = ColorAdjustTypeDefault)
  79. {
  80. return updateStatus(DllExports::GdipSetImageAttributesColorMatrix(
  81. nativeImageAttributes, type, FALSE,
  82. NULL, NULL, ColorMatrixFlagsDefault));
  83. }
  84. Status ClearGamma(ColorAdjustType type = ColorAdjustTypeDefault)
  85. {
  86. return updateStatus(DllExports::GdipSetImageAttributesGamma(
  87. nativeImageAttributes, type, FALSE, 1.0f));
  88. }
  89. Status ClearNoOp(ColorAdjustType type = ColorAdjustTypeDefault)
  90. {
  91. return updateStatus(DllExports::GdipSetImageAttributesNoOp(
  92. nativeImageAttributes, type, FALSE));
  93. }
  94. Status ClearOutputChannel(ColorAdjustType type = ColorAdjustTypeDefault)
  95. {
  96. return updateStatus(DllExports::GdipSetImageAttributesOutputChannel(
  97. nativeImageAttributes, type, FALSE,
  98. ColorChannelFlagsC));
  99. }
  100. Status ClearOutputChannelColorProfile(
  101. ColorAdjustType type = ColorAdjustTypeDefault)
  102. {
  103. return updateStatus(DllExports::GdipSetImageAttributesOutputChannelColorProfile(
  104. nativeImageAttributes, type, FALSE, NULL));
  105. }
  106. Status ClearRemapTable(ColorAdjustType type = ColorAdjustTypeDefault)
  107. {
  108. return updateStatus(DllExports::GdipSetImageAttributesRemapTable(
  109. nativeImageAttributes, type, FALSE, 0, NULL));
  110. }
  111. Status ClearThreshold(ColorAdjustType type = ColorAdjustTypeDefault)
  112. {
  113. return updateStatus(DllExports::GdipSetImageAttributesThreshold(
  114. nativeImageAttributes, type, FALSE, 0.0));
  115. }
  116. Status GetAdjustedPalette(ColorPalette *colorPalette,
  117. ColorAdjustType type) const
  118. {
  119. return updateStatus(DllExports::GdipGetImageAttributesAdjustedPalette(
  120. nativeImageAttributes, colorPalette, type));
  121. }
  122. Status GetLastStatus() const
  123. {
  124. Status result = lastStatus;
  125. lastStatus = Ok;
  126. return result;
  127. }
  128. Status Reset(ColorAdjustType type = ColorAdjustTypeDefault)
  129. {
  130. return updateStatus(DllExports::GdipResetImageAttributes(
  131. nativeImageAttributes, type));
  132. }
  133. Status SetBrushRemapTable(UINT mapSize, ColorMap *map)
  134. {
  135. return updateStatus(DllExports::GdipSetImageAttributesRemapTable(
  136. nativeImageAttributes, ColorAdjustTypeBrush,
  137. TRUE, mapSize, map));
  138. }
  139. Status SetColorKey(const Color& colorLow, const Color& colorHigh,
  140. ColorAdjustType type = ColorAdjustTypeDefault)
  141. {
  142. return updateStatus(DllExports::GdipSetImageAttributesColorKeys(
  143. nativeImageAttributes, type, TRUE,
  144. colorLow.GetValue(), colorHigh.GetValue()));
  145. }
  146. Status SetColorMatrices(const ColorMatrix *colorMatrix,
  147. const ColorMatrix *grayMatrix,
  148. ColorMatrixFlags mode = ColorMatrixFlagsDefault,
  149. ColorAdjustType type = ColorAdjustTypeDefault)
  150. {
  151. return updateStatus(DllExports::GdipSetImageAttributesColorMatrix(
  152. nativeImageAttributes, type, TRUE,
  153. colorMatrix, grayMatrix, mode));
  154. }
  155. Status SetColorMatrix(const ColorMatrix *colorMatrix,
  156. ColorMatrixFlags mode = ColorMatrixFlagsDefault,
  157. ColorAdjustType type = ColorAdjustTypeDefault)
  158. {
  159. return updateStatus(DllExports::GdipSetImageAttributesColorMatrix(
  160. nativeImageAttributes, type, TRUE,
  161. colorMatrix, NULL, mode));
  162. }
  163. Status SetGamma(REAL gamma,
  164. ColorAdjustType type = ColorAdjustTypeDefault)
  165. {
  166. return updateStatus(DllExports::GdipSetImageAttributesGamma(
  167. nativeImageAttributes, type, TRUE, gamma));
  168. }
  169. Status SetNoOp(ColorAdjustType type = ColorAdjustTypeDefault)
  170. {
  171. return updateStatus(DllExports::GdipSetImageAttributesNoOp(
  172. nativeImageAttributes, type, TRUE));
  173. }
  174. Status SetOutputChannel(ColorChannelFlags channelFlags,
  175. ColorAdjustType type = ColorAdjustTypeDefault)
  176. {
  177. return updateStatus(DllExports::GdipSetImageAttributesOutputChannel(
  178. nativeImageAttributes, type, TRUE,
  179. channelFlags));
  180. }
  181. Status SetOutputChannelColorProfile(const WCHAR *colorProfileFilename,
  182. ColorAdjustType type = ColorAdjustTypeDefault)
  183. {
  184. return updateStatus(DllExports::GdipSetImageAttributesOutputChannelColorProfile(
  185. nativeImageAttributes, type, TRUE,
  186. colorProfileFilename));
  187. }
  188. Status SetRemapTable(UINT mapSize, const ColorMap *map,
  189. ColorAdjustType type = ColorAdjustTypeDefault)
  190. {
  191. return updateStatus(DllExports::GdipSetImageAttributesRemapTable(
  192. nativeImageAttributes, type, TRUE,
  193. mapSize, map));
  194. }
  195. Status SetThreshold(REAL threshold,
  196. ColorAdjustType type = ColorAdjustTypeDefault)
  197. {
  198. return updateStatus(DllExports::GdipSetImageAttributesThreshold(
  199. nativeImageAttributes, type, TRUE, threshold));
  200. }
  201. Status SetToIdentity(ColorAdjustType type = ColorAdjustTypeDefault)
  202. {
  203. return updateStatus(DllExports::GdipSetImageAttributesToIdentity(
  204. nativeImageAttributes, type));
  205. }
  206. Status SetWrapMode(WrapMode wrap, const Color& color = Color(),
  207. BOOL clamp = FALSE)
  208. {
  209. return updateStatus(DllExports::GdipSetImageAttributesWrapMode(
  210. nativeImageAttributes, wrap,
  211. color.GetValue(), clamp));
  212. }
  213. private:
  214. ImageAttributes(GpImageAttributes *imageAttributes, Status status):
  215. nativeImageAttributes(imageAttributes), lastStatus(status) {}
  216. ImageAttributes(const ImageAttributes&);
  217. ImageAttributes& operator=(const ImageAttributes&);
  218. Status updateStatus(Status newStatus) const
  219. {
  220. if (newStatus != Ok) lastStatus = newStatus;
  221. return newStatus;
  222. }
  223. GpImageAttributes *nativeImageAttributes;
  224. mutable Status lastStatus;
  225. };
  226. #endif /* __GDIPLUS_IMAGEATTRIBUTES_H */