Browse Source

make alppha process pecentage consistent with blenders

af/merge-core
Scott Williams 9 years ago
parent
commit
cfe1f8ca4a
  1. 8
      src/ImageSharp/Processing/Effects/Alpha.cs
  2. 14
      src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs

8
src/ImageSharp/Processing/Effects/Alpha.cs

@ -21,9 +21,9 @@ namespace ImageSharp
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Alpha<TPixel>(this Image<TPixel> source, int percent)
public static Image<TPixel> Alpha<TPixel>(this Image<TPixel> source, float percent)
where TPixel : struct, IPixel<TPixel>
{
return Alpha(source, percent, source.Bounds);
@ -34,12 +34,12 @@ namespace ImageSharp
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param>
/// <param name="percent">The new opacity of the image. Must be between 0 and 1.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image<TPixel> Alpha<TPixel>(this Image<TPixel> source, int percent, Rectangle rectangle)
public static Image<TPixel> Alpha<TPixel>(this Image<TPixel> source, float percent, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new AlphaProcessor<TPixel>(percent), rectangle);

14
src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs

@ -21,26 +21,24 @@ namespace ImageSharp.Processing.Processors
/// <summary>
/// Initializes a new instance of the <see cref="AlphaProcessor{TPixel}"/> class.
/// </summary>
/// <param name="percent">The percentage to adjust the opacity of the image. Must be between 0 and 100.</param>
/// <param name="percent">The percentage to adjust the opacity of the image. Must be between 0 and 1.</param>
/// <exception cref="System.ArgumentException">
/// <paramref name="percent"/> is less than 0 or is greater than 100.
/// <paramref name="percent"/> is less than 0 or is greater than 1.
/// </exception>
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;
}
/// <summary>
/// Gets the alpha value.
/// </summary>
public int Value { get; }
public float Value { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TPixel> 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<TPixel> sourcePixels = source.Lock())
{

Loading…
Cancel
Save