GdiPlusimageAttributes.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:13k
源码类别:

模拟服务器

开发平台:

C/C++

  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.     
  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.     
  248.     Status ClearOutputChannelColorProfile(
  249.         IN ColorAdjustType type = ColorAdjustTypeDefault
  250.         )
  251.     {
  252.         return SetStatus(DllExports::GdipSetImageAttributesOutputChannelColorProfile(
  253.                                             nativeImageAttr,
  254.                                             type,
  255.                                             FALSE,
  256.                                             NULL));
  257.     }
  258.     
  259.     Status SetRemapTable(
  260.         IN UINT mapSize, 
  261.         IN const ColorMap *map,
  262.         IN ColorAdjustType type = ColorAdjustTypeDefault
  263.         )
  264.     {
  265.         return SetStatus(DllExports::GdipSetImageAttributesRemapTable(
  266.                                             nativeImageAttr,
  267.                                             type,
  268.                                             TRUE,
  269.                                             mapSize,
  270.                                             map));
  271.     }
  272.     Status ClearRemapTable(
  273.         IN ColorAdjustType type = ColorAdjustTypeDefault
  274.         )
  275.     {
  276.         return SetStatus(DllExports::GdipSetImageAttributesRemapTable(
  277.                                             nativeImageAttr,
  278.                                             type,
  279.                                             FALSE,
  280.                                             0,
  281.                                             NULL));
  282.     }
  283.     Status SetBrushRemapTable(IN UINT mapSize, 
  284.                               IN const ColorMap *map)
  285.     {
  286.         return this->SetRemapTable(mapSize, map, ColorAdjustTypeBrush);
  287.     }
  288.     Status ClearBrushRemapTable()
  289.     {
  290.         return this->ClearRemapTable(ColorAdjustTypeBrush);
  291.     }
  292.     Status SetWrapMode(IN WrapMode wrap, 
  293.                        IN const Color& color = Color(), 
  294.                        IN BOOL clamp = FALSE) 
  295.     {
  296.         ARGB argb = color.GetValue();
  297.         return SetStatus(DllExports::GdipSetImageAttributesWrapMode(
  298.                            nativeImageAttr, wrap, argb, clamp));
  299.     }
  300.     // The flags of the palette are ignored.
  301.     Status GetAdjustedPalette(IN OUT ColorPalette* colorPalette,
  302.                               IN ColorAdjustType colorAdjustType) const 
  303.     {
  304.         return SetStatus(DllExports::GdipGetImageAttributesAdjustedPalette(
  305.                            nativeImageAttr, colorPalette, colorAdjustType));
  306.     }
  307.     Status GetLastStatus() const
  308.     {
  309.         Status lastStatus = lastResult;
  310.         lastResult = Ok;
  311.     
  312.         return lastStatus;
  313.     }
  314.     
  315. private:
  316.     ImageAttributes(const ImageAttributes &);
  317.     ImageAttributes& operator=(const ImageAttributes &);
  318. protected:
  319.     ImageAttributes(GpImageAttributes* imageAttr, Status status)
  320.     {
  321.         SetNativeImageAttr(imageAttr);
  322.         lastResult = status;
  323.     }
  324.     VOID SetNativeImageAttr(GpImageAttributes* nativeImageAttr)
  325.     {
  326.         this->nativeImageAttr = nativeImageAttr;
  327.     }
  328.     
  329.     Status SetStatus(Status status) const
  330.     {
  331.         if (status != Ok)
  332.             return (lastResult = status);
  333.         else 
  334.             return status;
  335.     }
  336. protected:
  337.     GpImageAttributes* nativeImageAttr;
  338.     mutable Status lastResult;
  339. };
  340. #endif