Browse Source

ParallelHelper -> ProjectiveTransformProcessor, better RotateTests

af/merge-core
Anton Firszov 8 years ago
parent
commit
7d415fbc27
  1. 44
      src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs
  2. 23
      tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs
  3. 2
      tests/Images/External

44
src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor.cs

@ -10,6 +10,7 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.ParallelUtils;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Memory; using SixLabors.Memory;
using SixLabors.Primitives; using SixLabors.Primitives;
@ -75,11 +76,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
if (this.Sampler is NearestNeighborResampler) if (this.Sampler is NearestNeighborResampler)
{ {
ParallelFor.WithConfiguration( ParallelHelper.IterateRows(
0, targetBounds,
height,
configuration, configuration,
y => rows =>
{
for (int y = rows.Min; y < rows.Max; y++)
{ {
Span<TPixel> destRow = destination.GetPixelRowSpan(y); Span<TPixel> destRow = destination.GetPixelRowSpan(y);
@ -96,6 +98,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
destRow[x] = source[px, py]; destRow[x] = source[px, py];
} }
} }
}
}); });
return; return;
@ -121,11 +124,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
using (Buffer2D<float> yBuffer = memoryAllocator.Allocate2D<float>(yLength, height)) using (Buffer2D<float> yBuffer = memoryAllocator.Allocate2D<float>(yLength, height))
using (Buffer2D<float> xBuffer = memoryAllocator.Allocate2D<float>(xLength, height)) using (Buffer2D<float> xBuffer = memoryAllocator.Allocate2D<float>(xLength, height))
{ {
ParallelFor.WithConfiguration( ParallelHelper.IterateRows(
0, targetBounds,
height,
configuration, configuration,
y => rows =>
{
for (int y = rows.Min; y < rows.Max; y++)
{ {
ref TPixel destRowRef = ref MemoryMarshal.GetReference(destination.GetPixelRowSpan(y)); ref TPixel destRowRef = ref MemoryMarshal.GetReference(destination.GetPixelRowSpan(y));
ref float ySpanRef = ref MemoryMarshal.GetReference(yBuffer.GetRowSpan(y)); ref float ySpanRef = ref MemoryMarshal.GetReference(yBuffer.GetRowSpan(y));
@ -175,8 +179,27 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
// I've optimized where I can but am always open to suggestions. // I've optimized where I can but am always open to suggestions.
if (yScale > 1 && xScale > 1) if (yScale > 1 && xScale > 1)
{ {
CalculateWeightsDown(top, bottom, minY, maxY, point.Y, sampler, yScale, ref ySpanRef, yLength); CalculateWeightsDown(
CalculateWeightsDown(left, right, minX, maxX, point.X, sampler, xScale, ref xSpanRef, xLength); top,
bottom,
minY,
maxY,
point.Y,
sampler,
yScale,
ref ySpanRef,
yLength);
CalculateWeightsDown(
left,
right,
minX,
maxX,
point.X,
sampler,
xScale,
ref xSpanRef,
xLength);
} }
else else
{ {
@ -206,6 +229,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
// Reverse the premultiplication // Reverse the premultiplication
dest.PackFromVector4(sum.UnPremultiply()); dest.PackFromVector4(sum.UnPremultiply());
} }
}
}); });
} }
} }

23
tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs

@ -7,7 +7,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
public class RotateTests : FileTestBase [GroupOutput("Transforms")]
public class RotateTests
{ {
public static readonly TheoryData<float> RotateAngles public static readonly TheoryData<float> RotateAngles
= new TheoryData<float> = new TheoryData<float>
@ -25,29 +26,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
}; };
[Theory] [Theory]
[WithTestPatternImages(nameof(RotateAngles), 100, 50, DefaultPixelType)] [WithTestPatternImages(nameof(RotateAngles), 100, 50, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(RotateAngles), 50, 100, DefaultPixelType)] [WithTestPatternImages(nameof(RotateAngles), 50, 100, PixelTypes.Rgba32)]
public void Rotate_WithAngle<TPixel>(TestImageProvider<TPixel> provider, float value) public void Rotate_WithAngle<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) provider.RunValidatingProcessorTest(ctx => ctx.Rotate(value), value, appendPixelTypeToFileName: false);
{
image.Mutate(x => x.Rotate(value));
image.DebugSave(provider, value);
}
} }
[Theory] [Theory]
[WithTestPatternImages(nameof(RotateEnumValues), 100, 50, DefaultPixelType)] [WithTestPatternImages(nameof(RotateEnumValues), 100, 50, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(RotateEnumValues), 50, 100, DefaultPixelType)] [WithTestPatternImages(nameof(RotateEnumValues), 50, 100, PixelTypes.Rgba32)]
public void Rotate_WithRotateTypeEnum<TPixel>(TestImageProvider<TPixel> provider, RotateMode value) public void Rotate_WithRotateTypeEnum<TPixel>(TestImageProvider<TPixel> provider, RotateMode value)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) provider.RunValidatingProcessorTest(ctx => ctx.Rotate(value), value, appendPixelTypeToFileName: false);
{
image.Mutate(x => x.Rotate(value));
image.DebugSave(provider, value);
}
} }
} }
} }

2
tests/Images/External

@ -1 +1 @@
Subproject commit c1e14c0e431066c57585f255d3feb8d3a1860d50 Subproject commit 7f4d2d64c6b820ca2b6827e6a8540a1013305ccf
Loading…
Cancel
Save