From 324cb09452f01a26bac33896c04282b048b08331 Mon Sep 17 00:00:00 2001 From: Vicente Penades Date: Tue, 21 Aug 2018 15:56:49 +0200 Subject: [PATCH] refactored DrawImageProcessor methods --- .../Processors/Drawing/DrawImageProcessor.cs | 67 +++++++++---------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs index a114daa84..760086183 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs @@ -40,6 +40,29 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing public DrawImageProcessor(Image image, GraphicsOptions options) : this(image, Point.Empty, options) { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image to blend with the currently processing image. + /// The opacity of the image to blend. Must be between 0 and 1. + /// The blending mode to use when drawing the image. + public DrawImageProcessor(Image image, float opacity, PixelColorBlendingMode colorBlendingMode) + : this(image, Point.Empty, opacity, colorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image to blend with the currently processing image. + /// The opacity of the image to blend. Must be between 0 and 1. + /// The Color blending mode to use when drawing the image. + /// The Alpha blending mode to use when drawing the image. + public DrawImageProcessor(Image image, float opacity, PixelColorBlendingMode colorBlendingMode, PixelAlphaCompositionMode alphaCompositionMode) + : this(image, Point.Empty, opacity, colorBlendingMode, alphaCompositionMode) + { } /// @@ -49,7 +72,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing /// The location to draw the blended image. /// The opacity of the image to blend. Must be between 0 and 1. public DrawImageProcessor(Image image, Point location, float opacity) - : this(image, location, opacity, GraphicsOptions.Default.ColorBlendingMode) + : this(image, location, opacity, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode) { } @@ -65,46 +88,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing public DrawImageProcessor(Image image, Point location, GraphicsOptions options) : this(image, location, options.BlendPercentage, options.ColorBlendingMode, options.AlphaCompositionMode) { - } - - /// - /// Initializes a new instance of the class. - /// - /// The image to blend with the currently processing image. - /// The opacity of the image to blend. Must be between 0 and 1. - /// The blending mode to use when drawing the image. - public DrawImageProcessor(Image image, float opacity, PixelColorBlendingMode blenderMode) - : this(image, Point.Empty, opacity, blenderMode) - { } - /// - /// Initializes a new instance of the class. - /// - /// The image to blend with the currently processing image. - /// The opacity of the image to blend. Must be between 0 and 1. - /// The Color blending mode to use when drawing the image. - /// The Alpha blending mode to use when drawing the image. - public DrawImageProcessor(Image image, float opacity, PixelColorBlendingMode blenderMode, PixelAlphaCompositionMode alphaMode) - : this(image, Point.Empty, opacity, blenderMode, alphaMode) - { - } - /// /// Initializes a new instance of the class. /// /// The image to blend with the currently processing image. /// The location to draw the blended image. /// The opacity of the image to blend. Must be between 0 and 1. - /// The blending mode to use when drawing the image. - public DrawImageProcessor(Image image, Point location, float opacity, PixelColorBlendingMode blenderMode) + /// The blending mode to use when drawing the image. + public DrawImageProcessor(Image image, Point location, float opacity, PixelColorBlendingMode colorBlendingMode) + : this(image, location, opacity, colorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode) { - Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); - - this.Image = image; - this.Opacity = opacity; - this.Blender = PixelOperations.Instance.GetPixelBlender(blenderMode, PixelAlphaCompositionMode.SrcOver); - this.Location = location; } /// @@ -113,15 +108,15 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing /// The image to blend with the currently processing image. /// The location to draw the blended image. /// The opacity of the image to blend. Must be between 0 and 1. - /// The blending mode to use when drawing the image. - /// The Alpha blending mode to use when drawing the image. - public DrawImageProcessor(Image image, Point location, float opacity, PixelColorBlendingMode blenderMode, PixelAlphaCompositionMode alphaMode) + /// The blending mode to use when drawing the image. + /// The Alpha blending mode to use when drawing the image. + public DrawImageProcessor(Image image, Point location, float opacity, PixelColorBlendingMode colorBlendingMode, PixelAlphaCompositionMode alphaCompositionMode) { Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); this.Image = image; this.Opacity = opacity; - this.Blender = PixelOperations.Instance.GetPixelBlender(blenderMode, alphaMode); + this.Blender = PixelOperations.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode); this.Location = location; }