Browse Source

utilize CalculateResizeWorkerHeightInWindowBands()

which has been renamed from CalculateResizeWorkerWindowCount()
pull/888/head
Anton Firszov 7 years ago
parent
commit
40aea16633
  1. 14
      src/ImageSharp/Configuration.cs
  2. 6
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeHelper.cs
  3. 15
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs
  4. 1
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs
  5. 7
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

14
src/ImageSharp/Configuration.cs

@ -128,9 +128,9 @@ namespace SixLabors.ImageSharp
}
/// <summary>
/// Creates a shallow copy of the <see cref="Configuration"/>
/// Creates a shallow copy of the <see cref="Configuration"/>.
/// </summary>
/// <returns>A new configuration instance</returns>
/// <returns>A new configuration instance.</returns>
public Configuration Clone()
{
return new Configuration
@ -147,12 +147,12 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Creates the default instance with the following <see cref="IConfigurationModule"/>s preregistered:
/// <para><see cref="PngConfigurationModule"/></para>
/// <para><see cref="JpegConfigurationModule"/></para>
/// <para><see cref="GifConfigurationModule"/></para>
/// <para><see cref="BmpConfigurationModule"/></para>
/// <see cref="PngConfigurationModule"/>
/// <see cref="JpegConfigurationModule"/>
/// <see cref="GifConfigurationModule"/>
/// <see cref="BmpConfigurationModule"/>.
/// </summary>
/// <returns>The default configuration of <see cref="Configuration"/></returns>
/// <returns>The default configuration of <see cref="Configuration"/>.</returns>
internal static Configuration CreateDefaultInstance()
{
return new Configuration(

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

@ -15,13 +15,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// </summary>
internal static class ResizeHelper
{
public static unsafe int CalculateResizeWorkerWindowCount(
int windowDiameter,
public static unsafe int CalculateResizeWorkerHeightInWindowBands(
int windowBandDiameter,
int width,
int sizeLimitHintInBytes)
{
int sizeLimitHint = sizeLimitHintInBytes / sizeof(Vector4);
int sizeOfOneWindow = windowDiameter * width;
int sizeOfOneWindow = windowBandDiameter * width;
return Math.Max(2, sizeLimitHint / sizeOfOneWindow);
}

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

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private readonly Rectangle destWorkingRect;
private readonly int diameter;
private readonly int windowBandDiameter;
private readonly int windowHeight;
@ -65,9 +65,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
this.destWorkingRect = destWorkingRect;
this.startX = startX;
this.diameter = verticalKernelMap.MaxDiameter;
this.windowBandDiameter = verticalKernelMap.MaxDiameter;
this.windowHeight = Math.Min(this.sourceRectangle.Height, 2 * this.diameter);
int numberOfWindowBands = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(
this.windowBandDiameter,
destWidth,
configuration.WorkingBufferSizeHintInBytes);
this.windowHeight = Math.Min(this.sourceRectangle.Height, numberOfWindowBands * this.windowBandDiameter);
this.buffer = configuration.MemoryAllocator.Allocate2D<Vector4>(
this.windowHeight,
@ -143,8 +148,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public void Slide()
{
this.CurrentMinY = this.CurrentMinY + this.diameter;
this.CurrentMaxY = Math.Min(this.CurrentMaxY + this.diameter, this.sourceRectangle.Height);
this.CurrentMinY = this.CurrentMinY + this.windowBandDiameter;
this.CurrentMaxY = Math.Min(this.CurrentMaxY + this.windowBandDiameter, this.sourceRectangle.Height);
this.CalculateFirstPassValues(this.CurrentMinY, this.CurrentMaxY);
}

1
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs

@ -36,6 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ nameof(KnownResamplers.Bicubic), 40, 50 },
{ nameof(KnownResamplers.Bicubic), 500, 200 },
{ nameof(KnownResamplers.Bicubic), 200, 500 },
{ nameof(KnownResamplers.Bicubic), 3032, 400 },
{ nameof(KnownResamplers.Bicubic), 10, 25 },

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

@ -44,13 +44,16 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
[InlineData(17, 63, 5*17*63*16, 5)]
[InlineData(17, 63, 5*17*63*16+1, 5)]
[InlineData(17, 63, 6*17*63*16-1, 5)]
public void CalculateResizeWorkerWindowCount(
[InlineData(33, 400, 1*1024*1024, 4)]
[InlineData(33, 400, 8*1024*1024, 39)]
[InlineData(50, 300, 1*1024*1024, 4)]
public void CalculateResizeWorkerHeightInWindowBands(
int windowDiameter,
int width,
int sizeLimitHintInBytes,
int expectedCount)
{
int actualCount = ResizeHelper.CalculateResizeWorkerWindowCount(windowDiameter, width, sizeLimitHintInBytes);
int actualCount = ResizeHelper.CalculateResizeWorkerHeightInWindowBands(windowDiameter, width, sizeLimitHintInBytes);
Assert.Equal(expectedCount, actualCount);
}

Loading…
Cancel
Save