GdiPlusimageAttributes.h
上传用户:jinlangri
上传日期:2022-07-17
资源大小:10774k
文件大小:13k
源码类别:

GDI/图象编程

开发平台:

Visual C++

  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.     
  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.     #ifndef DCR_USE_NEW_145139
  301.     Status SetICMMode(IN BOOL on)
  302.     {
  303.         on;
  304.         // This is not implemented.
  305.         // The supported method for doing ICM conversion from the embedded 
  306.         // ICC profile is to use the Bitmap constructor from a file or stream
  307.         // and specify TRUE for the useIcm parameter. This will cause the 
  308.         // image to be ICM converted when it's loaded from the file/stream
  309.         // if the profile exists.
  310.         return SetStatus(NotImplemented);
  311. //          DllExports::GdipSetImageAttributesICMMode(nativeImageAttr, on)
  312.     }
  313.     #endif
  314.     // The flags of the palette are ignored.
  315.     Status GetAdjustedPalette(IN OUT ColorPalette* colorPalette,
  316.                               IN ColorAdjustType colorAdjustType) const 
  317.     {
  318.         return SetStatus(DllExports::GdipGetImageAttributesAdjustedPalette(
  319.                            nativeImageAttr, colorPalette, colorAdjustType));
  320.     }
  321.     Status GetLastStatus() const
  322.     {
  323.         Status lastStatus = lastResult;
  324.         lastResult = Ok;
  325.     
  326.         return lastStatus;
  327.     }
  328.     
  329. #ifdef DCR_USE_NEW_250932
  330. private:
  331.     ImageAttributes(const ImageAttributes &);
  332.     ImageAttributes& operator=(const ImageAttributes &);
  333. #endif
  334. protected:
  335.     ImageAttributes(GpImageAttributes* imageAttr, Status status)
  336.     {
  337.         SetNativeImageAttr(imageAttr);
  338.         lastResult = status;
  339.     }
  340.     VOID SetNativeImageAttr(GpImageAttributes* nativeImageAttr)
  341.     {
  342.         this->nativeImageAttr = nativeImageAttr;
  343.     }
  344.     
  345.     Status SetStatus(Status status) const
  346.     {
  347.         if (status != Ok)
  348.             return (lastResult = status);
  349.         else 
  350.             return status;
  351.     }
  352. protected:
  353.     GpImageAttributes* nativeImageAttr;
  354.     mutable Status lastResult;
  355. };
  356. #endif