Browse Source

test common processors for disco buffers

af/octree-no-pixelmap
Anton Firszov 6 years ago
parent
commit
0e91efeb09
  1. 2
      src/ImageSharp/ImageFrame{TPixel}.cs
  2. 3
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs
  3. 8
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs
  4. 11
      tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
  5. 21
      tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs
  6. 10
      tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs
  7. 8
      tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs
  8. 13
      tests/ImageSharp.Tests/Processing/Processors/Transforms/AffineTransformTests.cs
  9. 36
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

2
src/ImageSharp/ImageFrame{TPixel}.cs

@ -186,7 +186,7 @@ namespace SixLabors.ImageSharp
throw new ArgumentException("ImageFrame<TPixel>.CopyTo(): target must be of the same size!", nameof(target));
}
this.GetPixelSpan().CopyTo(target.GetSingleSpan());
this.PixelBuffer.MemoryGroup.CopyTo(target.MemoryGroup);
}
/// <summary>

3
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs

@ -74,6 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
this.windowBandHeight = verticalKernelMap.MaxDiameter;
// We need to make sure the working buffer is contiguous:
int workingBufferLimitHintInBytes = Math.Min(
configuration.WorkingBufferSizeHintInBytes,
configuration.MemoryAllocator.GetBufferCapacityInBytes());
@ -117,6 +118,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public void FillDestinationPixels(RowInterval rowInterval, Buffer2D<TPixel> destination)
{
Span<Vector4> tempColSpan = this.tempColumnBuffer.GetSpan();
// When creating transposedFirstPassBuffer, we made sure it's contiguous:
Span<Vector4> transposedFirstPassBufferSpan = this.transposedFirstPassBuffer.GetSingleSpan();
for (int y = rowInterval.Min; y < rowInterval.Max; y++)

8
tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs

@ -196,5 +196,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
.Invoke(RunTest, BasicSerializer.Serialize(provider), BasicSerializer.Serialize(value))
.Dispose();
}
[Theory]
[WithTestPatternImages(100, 300, PixelTypes.Bgr24)]
public void WorksWithDiscoBuffers<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.RunBufferCapacityLimitProcessorTest(41, c => c.BokehBlur());
}
}
}

11
tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs

@ -103,5 +103,16 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
[Theory]
[WithFile(Tests.TestImages.Png.Bike, nameof(DetectEdgesFilters), PixelTypes.Rgba32)]
public void WorksWithDiscoBuffers<TPixel>(TestImageProvider<TPixel> provider, EdgeDetectionOperators detector)
where TPixel : struct, IPixel<TPixel>
{
provider.RunBufferCapacityLimitProcessorTest(
41,
c => c.DetectEdges(detector),
detector);
}
}
}

21
tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs

@ -152,5 +152,26 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
comparer: ValidatorComparer,
appendPixelTypeToFileName: false);
}
[Theory]
[WithFile(TestImages.Png.Bike, PixelTypes.Rgba32, nameof(OrderedDither.Ordered3x3))]
[WithFile(TestImages.Png.Bike, PixelTypes.Rgba32, nameof(ErrorDither.FloydSteinberg))]
public void CommonDitherers_WorkWithDiscoBuffers<TPixel>(
TestImageProvider<TPixel> provider,
string name)
where TPixel : struct, IPixel<TPixel>
{
IDither dither = TestUtils.GetDither(name);
if (SkipAllDitherTests)
{
return;
}
provider.RunBufferCapacityLimitProcessorTest(
41,
c => c.Dither(dither),
name,
ImageComparer.TolerantPercentage(0.001f));
}
}
}

10
tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs

@ -37,6 +37,16 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
provider.RunRectangleConstrainedValidatingProcessorTest((x, b) => x.Filter(m, b), comparer: ValidatorComparer);
}
[Theory]
[WithTestPatternImages(70, 120, PixelTypes.Rgba32)]
public void FilterProcessor_WorksWithDiscoBuffers<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
ColorMatrix m = CreateCombinedTestFilterMatrix();
provider.RunBufferCapacityLimitProcessorTest(37, c => c.Filter(m));
}
private static ColorMatrix CreateCombinedTestFilterMatrix()
{
ColorMatrix brightness = KnownFilterMatrices.CreateBrightnessFilter(0.9F);

8
tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs

@ -54,6 +54,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays
provider.RunRectangleConstrainedValidatingProcessorTest(this.Apply);
}
[Theory]
[WithTestPatternImages(70, 120, PixelTypes.Rgba32)]
public void WorksWithDiscoBuffers<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.RunBufferCapacityLimitProcessorTest(37, c => this.Apply(c, Color.DarkRed));
}
protected abstract void Apply(IImageProcessingContext ctx, Color color);
protected abstract void Apply(IImageProcessingContext ctx, float radiusX, float radiusY);

13
tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs → tests/ImageSharp.Tests/Processing/Processors/Transforms/AffineTransformTests.cs

@ -213,6 +213,19 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
}
}
[Theory]
[WithTestPatternImages(100, 100, PixelTypes.Rgba32, 21)]
public void WorksWithDiscoBuffers<TPixel>(TestImageProvider<TPixel> provider, int bufferCapacityInPixelRows)
where TPixel : struct, IPixel<TPixel>
{
AffineTransformBuilder builder = new AffineTransformBuilder()
.AppendRotationDegrees(50)
.AppendScale(new SizeF(.6F, .6F));
provider.RunBufferCapacityLimitProcessorTest(
bufferCapacityInPixelRows,
c => c.Transform(builder));
}
private static IResampler GetResampler(string name)
{
PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name);

36
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -6,10 +6,12 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Dithering;
using SixLabors.ImageSharp.Processing.Processors.Transforms;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
@ -150,6 +152,28 @@ namespace SixLabors.ImageSharp.Tests
where TPixel : struct, IPixel<TPixel> =>
GetColorByName(colorName).ToPixel<TPixel>();
internal static void RunBufferCapacityLimitProcessorTest<TPixel>(
this TestImageProvider<TPixel> provider,
int bufferCapacityInPixelRows,
Action<IImageProcessingContext> process,
object testOutputDetails = null,
ImageComparer comparer = null)
where TPixel : struct, IPixel<TPixel>
{
comparer??= ImageComparer.Exact;
using Image<TPixel> expected = provider.GetImage();
int width = expected.Width;
expected.Mutate(process);
var allocator = ArrayPoolMemoryAllocator.CreateDefault();
provider.Configuration.MemoryAllocator = allocator;
allocator.BufferCapacityInBytes = bufferCapacityInPixelRows * width * Unsafe.SizeOf<TPixel>();
using Image<TPixel> actual = provider.GetImage();
actual.Mutate(process);
comparer.VerifySimilarity(expected, actual);
}
/// <summary>
/// Utility for testing image processor extension methods:
/// 1. Run a processor defined by 'process'
@ -342,6 +366,18 @@ namespace SixLabors.ImageSharp.Tests
return (IResampler)property.GetValue(null);
}
public static IDither GetDither(string name)
{
PropertyInfo property = typeof(KnownDitherings).GetTypeInfo().GetProperty(name);
if (property is null)
{
throw new Exception($"No dither named '{name}");
}
return (IDither)property.GetValue(null);
}
public static string[] GetAllResamplerNames(bool includeNearestNeighbour = true)
{
return typeof(KnownResamplers).GetProperties(BindingFlags.Public | BindingFlags.Static)

Loading…
Cancel
Save