Browse Source

Optimize Alpha

af/merge-core
James Jackson-South 9 years ago
parent
commit
2423c680bb
  1. 32
      src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs
  2. 4
      tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs

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

@ -61,26 +61,22 @@ namespace ImageSharp.Processing.Processors
startY = 0; startY = 0;
} }
Vector4 alphaVector = new Vector4(1, 1, 1, this.Value); var alphaVector = new Vector4(1, 1, 1, this.Value);
using (PixelAccessor<TPixel> sourcePixels = source.Lock()) Parallel.For(
{ minY,
Parallel.For( maxY,
minY, this.ParallelOptions,
maxY, y =>
this.ParallelOptions, {
y => Span<TPixel> row = source.GetRowSpan(y - startY);
for (int x = minX; x < maxX; x++)
{ {
int offsetY = y - startY; ref TPixel pixel = ref row[x - startX];
for (int x = minX; x < maxX; x++) pixel.PackFromVector4(pixel.ToVector4() * alphaVector);
{ }
int offsetX = x - startX; });
TPixel packed = default(TPixel);
packed.PackFromVector4(sourcePixels[offsetX, offsetY].ToVector4() * alphaVector);
sourcePixels[offsetX, offsetY] = packed;
}
});
}
} }
} }
} }

4
tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs

@ -22,7 +22,7 @@ namespace ImageSharp.Tests
[Theory] [Theory]
[MemberData(nameof(AlphaValues))] [MemberData(nameof(AlphaValues))]
public void ImageShouldApplyAlphaFilter(int value) public void ImageShouldApplyAlphaFilter(float value)
{ {
string path = this.CreateOutputDirectory("Alpha"); string path = this.CreateOutputDirectory("Alpha");
@ -39,7 +39,7 @@ namespace ImageSharp.Tests
[Theory] [Theory]
[MemberData(nameof(AlphaValues))] [MemberData(nameof(AlphaValues))]
public void ImageShouldApplyAlphaFilterInBox(int value) public void ImageShouldApplyAlphaFilterInBox(float value)
{ {
string path = this.CreateOutputDirectory("Alpha"); string path = this.CreateOutputDirectory("Alpha");

Loading…
Cancel
Save