From cfe1f8ca4a2743750807c486cfd13a8dae0aa3c7 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Mon, 1 May 2017 14:19:31 +0100 Subject: [PATCH] make alppha process pecentage consistent with blenders --- src/ImageSharp/Processing/Effects/Alpha.cs | 8 ++++---- .../Processors/Effects/AlphaProcessor.cs | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/Processing/Effects/Alpha.cs b/src/ImageSharp/Processing/Effects/Alpha.cs index a54bde675..a2f721cfa 100644 --- a/src/ImageSharp/Processing/Effects/Alpha.cs +++ b/src/ImageSharp/Processing/Effects/Alpha.cs @@ -21,9 +21,9 @@ namespace ImageSharp /// /// The pixel format. /// The image this method extends. - /// The new opacity of the image. Must be between 0 and 100. + /// The new opacity of the image. Must be between 0 and 1. /// The . - public static Image Alpha(this Image source, int percent) + public static Image Alpha(this Image source, float percent) where TPixel : struct, IPixel { return Alpha(source, percent, source.Bounds); @@ -34,12 +34,12 @@ namespace ImageSharp /// /// The pixel format. /// The image this method extends. - /// The new opacity of the image. Must be between 0 and 100. + /// The new opacity of the image. Must be between 0 and 1. /// /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Alpha(this Image source, int percent, Rectangle rectangle) + public static Image Alpha(this Image source, float percent, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new AlphaProcessor(percent), rectangle); diff --git a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs index a60106546..5e7310e32 100644 --- a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs @@ -21,26 +21,24 @@ namespace ImageSharp.Processing.Processors /// /// Initializes a new instance of the class. /// - /// The percentage to adjust the opacity of the image. Must be between 0 and 100. + /// The percentage to adjust the opacity of the image. Must be between 0 and 1. /// - /// is less than 0 or is greater than 100. + /// is less than 0 or is greater than 1. /// - public AlphaProcessor(int percent) + public AlphaProcessor(float percent) { - Guard.MustBeBetweenOrEqualTo(percent, 0, 100, nameof(percent)); + Guard.MustBeBetweenOrEqualTo(percent, 0, 1, nameof(percent)); this.Value = percent; } /// /// Gets the alpha value. /// - public int Value { get; } + public float Value { get; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - float alpha = this.Value / 100F; - int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X; @@ -63,7 +61,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - Vector4 alphaVector = new Vector4(1, 1, 1, alpha); + Vector4 alphaVector = new Vector4(1, 1, 1, this.Value); using (PixelAccessor sourcePixels = source.Lock()) {