Browse Source

format, docs, cleanup

af/merge-core
Anton Firszov 7 years ago
parent
commit
570fd5e1ea
  1. 4
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs
  2. 10
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.MosaicKernelMap.cs
  3. 37
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs
  4. 4
      tests/ImageSharp.Tests/Processing/Processors/Transforms/KernelMapTests.cs

4
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernel.cs

@ -72,6 +72,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
return result;
}
/// <summary>
/// Copy the contents of <see cref="ResizeKernel"/> altering <see cref="Left"/>
/// to the value <paramref name="left"/>.
/// </summary>
internal ResizeKernel AlterLeftValue(int left)
{
return new ResizeKernel(left, this.bufferPtr, this.Length);

10
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.MosaicKernelMap.cs

@ -24,8 +24,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
public MosaicKernelMap(
MemoryAllocator memoryAllocator,
IResampler sampler,
int sourceSize,
int destinationSize,
int sourceLength,
int destinationLength,
float ratio,
float scale,
int radius,
@ -34,8 +34,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
: base(
memoryAllocator,
sampler,
sourceSize,
destinationSize,
sourceLength,
destinationLength,
(cornerInterval * 2) + period,
ratio,
scale,
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
}
// Copy the mosaics:
int bottomStartDest = this.DestinationSize - this.cornerInterval;
int bottomStartDest = this.DestinationLength - this.cornerInterval;
for (int i = startOfFirstRepeatedMosaic; i < bottomStartDest; i++)
{
float center = ((i + .5F) * this.ratio) - .5F;

37
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs

@ -13,13 +13,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
{
/// <summary>
/// Provides <see cref="ResizeKernel"/> values from an optimized,
/// contigous memory region.
/// contiguous memory region.
/// </summary>
internal partial class ResizeKernelMap : IDisposable
{
private readonly IResampler sampler;
private readonly int sourceSize;
private readonly int sourceLength;
private readonly float ratio;
@ -36,8 +36,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private ResizeKernelMap(
MemoryAllocator memoryAllocator,
IResampler sampler,
int sourceSize,
int destinationSize,
int sourceLength,
int destinationLength,
int bufferHeight,
float ratio,
float scale,
@ -47,18 +47,24 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
this.ratio = ratio;
this.scale = scale;
this.radius = radius;
this.sourceSize = sourceSize;
this.DestinationSize = destinationSize;
this.sourceLength = sourceLength;
this.DestinationLength = destinationLength;
int maxWidth = (radius * 2) + 1;
this.data = memoryAllocator.Allocate2D<float>(maxWidth, bufferHeight, AllocationOptions.Clean);
this.pinHandle = this.data.Memory.Pin();
this.kernels = new ResizeKernel[destinationSize];
this.kernels = new ResizeKernel[destinationLength];
}
public int DestinationSize { get; }
/// <summary>
/// Gets the length of the destination row/column
/// </summary>
public int DestinationLength { get; }
/// <summary>
/// Gets a string of information to help debugging
/// </summary>
internal virtual string Info =>
$"radius:{this.radius}|sourceSize:{this.sourceSize}|destinationSize:{this.DestinationSize}|ratio:{this.ratio}|scale:{this.scale}";
$"radius:{this.radius}|sourceSize:{this.sourceLength}|destinationSize:{this.DestinationLength}|ratio:{this.ratio}|scale:{this.scale}";
/// <summary>
/// Disposes <see cref="ResizeKernelMap"/> instance releasing it's backing buffer.
@ -104,7 +110,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
int cornerInterval = (int)MathF.Ceiling(firstNonNegativeLeftVal);
// corner case for cornerInteval:
if (firstNonNegativeLeftVal == cornerInterval)
if (firstNonNegativeLeftVal == cornerInterval)
{
cornerInterval++;
}
@ -139,13 +145,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
protected virtual void Initialize()
{
for (int i = 0; i < this.DestinationSize; i++)
for (int i = 0; i < this.DestinationLength; i++)
{
ResizeKernel kernel = this.BuildKernel(i, i);
this.kernels[i] = kernel;
}
}
/// <summary>
/// Builds a <see cref="ResizeKernel"/> for the row <paramref name="destRowIndex"/> (in <see cref="kernels"/>)
/// referencing the data at row <paramref name="dataRowIndex"/> within <see cref="data"/>,
/// so the data reusable by other data rows.
/// </summary>
private ResizeKernel BuildKernel(int destRowIndex, int dataRowIndex)
{
float center = ((destRowIndex + .5F) * this.ratio) - .5F;
@ -158,9 +169,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
}
int right = (int)MathF.Floor(center + this.radius);
if (right > this.sourceSize - 1)
if (right > this.sourceLength - 1)
{
right = this.sourceSize - 1;
right = this.sourceLength - 1;
}
float sum = 0;

4
tests/ImageSharp.Tests/Processing/Processors/Transforms/KernelMapTests.cs

@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
this.Output.WriteLine($"Actual KernelMap:\n{PrintKernelMap(kernelMap)}\n");
#endif
for (int i = 0; i < kernelMap.DestinationSize; i++)
for (int i = 0; i < kernelMap.DestinationLength; i++)
{
ResizeKernel kernel = kernelMap.GetKernel(i);
@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
}
private static string PrintKernelMap(ResizeKernelMap kernelMap) =>
PrintKernelMap(kernelMap, km => km.DestinationSize, (km, i) => km.GetKernel(i));
PrintKernelMap(kernelMap, km => km.DestinationLength, (km, i) => km.GetKernel(i));
private static string PrintKernelMap(ReferenceKernelMap kernelMap) =>
PrintKernelMap(kernelMap, km => km.DestinationSize, (km, i) => km.GetKernel(i));

Loading…
Cancel
Save