Browse Source

cover and harden ResizeProcessor

af/octree-no-pixelmap
Anton Firszov 6 years ago
parent
commit
d7df00bc46
  1. 3
      src/ImageSharp/Configuration.cs
  2. 6
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs
  3. 1
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs
  4. 2
      tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs
  5. 33
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  6. 6
      tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImagesAttribute.cs

3
src/ImageSharp/Configuration.cs

@ -108,7 +108,8 @@ namespace SixLabors.ImageSharp
/// The default value is 1MB.
/// </summary>
/// <remarks>
/// Currently only used by Resize.
/// Currently only used by Resize. If the working buffer is expected to be discontiguous,
/// min(WorkingBufferSizeHintInBytes, BufferCapacityInBytes) should be used.
/// </remarks>
internal int WorkingBufferSizeHintInBytes { get; set; } = 1 * 1024 * 1024;

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

@ -74,10 +74,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
this.windowBandHeight = verticalKernelMap.MaxDiameter;
int workingBufferLimitHintInBytes = Math.Min(
configuration.WorkingBufferSizeHintInBytes,
configuration.MemoryAllocator.GetBufferCapacityInBytes());
int numberOfWindowBands = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(
this.windowBandHeight,
destWidth,
configuration.WorkingBufferSizeHintInBytes);
workingBufferLimitHintInBytes);
this.workerHeight = Math.Min(this.sourceRectangle.Height, numberOfWindowBands * this.windowBandHeight);

1
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs

@ -41,7 +41,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
string providerDump = BasicSerializer.Serialize(provider);
// RunTest(providerDump, enforceDiscontiguousBuffers ? "Disco" : string.Empty);
RemoteExecutor.Invoke(
RunTest,
providerDump,

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

@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
};
public static readonly TheoryData<IDither, string> OrderedDitherers
= new TheoryData<IDither,string>
= new TheoryData<IDither, string>
{
{ KnownDitherings.Bayer2x2, nameof(KnownDitherings.Bayer2x2) },
{ KnownDitherings.Bayer4x4, nameof(KnownDitherings.Bayer4x4) },

33
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -153,6 +153,39 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
}
}
[Theory]
[WithTestPatternImages(100, 100, PixelTypes.Rgba32, 100, 100)]
[WithTestPatternImages(200, 200, PixelTypes.Rgba32, 31, 73)]
[WithTestPatternImages(200, 200, PixelTypes.Rgba32, 73, 31)]
[WithTestPatternImages(200, 193, PixelTypes.Rgba32, 13, 17)]
[WithTestPatternImages(200, 193, PixelTypes.Rgba32, 79, 23)]
[WithTestPatternImages(200, 503, PixelTypes.Rgba32, 61, 33)]
public void WorksWithDiscoBuffers<TPixel>(
TestImageProvider<TPixel> provider,
int workingBufferLimitInRows,
int bufferCapacityInRows)
where TPixel : struct, IPixel<TPixel>
{
using Image<TPixel> expected = provider.GetImage();
int width = expected.Width;
Size destSize = expected.Size() / 4;
expected.Mutate(c => c.Resize(destSize, KnownResamplers.Bicubic, false));
// Replace configuration:
provider.Configuration = Configuration.CreateDefaultInstance();
// Note: when AllocatorCapacityInBytes < WorkingBufferSizeHintInBytes,
// ResizeProcessor is expected to use the minimum of the two values, when establishing the working buffer.
provider.LimitAllocatorBufferCapacity().InBytes(width * bufferCapacityInRows * SizeOfVector4);
provider.Configuration.WorkingBufferSizeHintInBytes = width * workingBufferLimitInRows * SizeOfVector4;
using Image<TPixel> actual = provider.GetImage();
actual.Mutate(c => c.Resize(destSize, KnownResamplers.Bicubic, false));
actual.DebugSave(provider, $"{workingBufferLimitInRows}-{bufferCapacityInRows}");
ImageComparer.Exact.VerifySimilarity(expected, actual);
}
[Theory]
[WithTestPatternImages(100, 100, DefaultPixelType)]
public void Resize_Compand<TPixel>(TestImageProvider<TPixel> provider)

6
tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImagesAttribute.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Tests
public class WithTestPatternImagesAttribute : ImageDataAttributeBase
{
/// <summary>
/// Triggers passing an <see cref="TestImageProvider{TPixel}"/> that produces a test pattern image of size width * height
/// Initializes a new instance of the <see cref="WithTestPatternImagesAttribute"/> class.
/// </summary>
/// <param name="width">The required width</param>
/// <param name="height">The required height</param>
@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests
}
/// <summary>
/// Triggers passing an <see cref="TestImageProvider{TPixel}"/> that produces a test pattern image of size width * height
/// Initializes a new instance of the <see cref="WithTestPatternImagesAttribute"/> class.
/// </summary>
/// <param name="memberData">The member data to apply to theories</param>
/// <param name="width">The required width</param>
@ -53,4 +53,4 @@ namespace SixLabors.ImageSharp.Tests
protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => new object[] { this.Width, this.Height };
}
}
}

Loading…
Cancel
Save