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; 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) internal ResizeKernel AlterLeftValue(int left)
{ {
return new ResizeKernel(left, this.bufferPtr, this.Length); 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( public MosaicKernelMap(
MemoryAllocator memoryAllocator, MemoryAllocator memoryAllocator,
IResampler sampler, IResampler sampler,
int sourceSize, int sourceLength,
int destinationSize, int destinationLength,
float ratio, float ratio,
float scale, float scale,
int radius, int radius,
@ -34,8 +34,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
: base( : base(
memoryAllocator, memoryAllocator,
sampler, sampler,
sourceSize, sourceLength,
destinationSize, destinationLength,
(cornerInterval * 2) + period, (cornerInterval * 2) + period,
ratio, ratio,
scale, scale,
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
} }
// Copy the mosaics: // Copy the mosaics:
int bottomStartDest = this.DestinationSize - this.cornerInterval; int bottomStartDest = this.DestinationLength - this.cornerInterval;
for (int i = startOfFirstRepeatedMosaic; i < bottomStartDest; i++) for (int i = startOfFirstRepeatedMosaic; i < bottomStartDest; i++)
{ {
float center = ((i + .5F) * this.ratio) - .5F; 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> /// <summary>
/// Provides <see cref="ResizeKernel"/> values from an optimized, /// Provides <see cref="ResizeKernel"/> values from an optimized,
/// contigous memory region. /// contiguous memory region.
/// </summary> /// </summary>
internal partial class ResizeKernelMap : IDisposable internal partial class ResizeKernelMap : IDisposable
{ {
private readonly IResampler sampler; private readonly IResampler sampler;
private readonly int sourceSize; private readonly int sourceLength;
private readonly float ratio; private readonly float ratio;
@ -36,8 +36,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private ResizeKernelMap( private ResizeKernelMap(
MemoryAllocator memoryAllocator, MemoryAllocator memoryAllocator,
IResampler sampler, IResampler sampler,
int sourceSize, int sourceLength,
int destinationSize, int destinationLength,
int bufferHeight, int bufferHeight,
float ratio, float ratio,
float scale, float scale,
@ -47,18 +47,24 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
this.ratio = ratio; this.ratio = ratio;
this.scale = scale; this.scale = scale;
this.radius = radius; this.radius = radius;
this.sourceSize = sourceSize; this.sourceLength = sourceLength;
this.DestinationSize = destinationSize; this.DestinationLength = destinationLength;
int maxWidth = (radius * 2) + 1; int maxWidth = (radius * 2) + 1;
this.data = memoryAllocator.Allocate2D<float>(maxWidth, bufferHeight, AllocationOptions.Clean); this.data = memoryAllocator.Allocate2D<float>(maxWidth, bufferHeight, AllocationOptions.Clean);
this.pinHandle = this.data.Memory.Pin(); 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 => 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> /// <summary>
/// Disposes <see cref="ResizeKernelMap"/> instance releasing it's backing buffer. /// 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); int cornerInterval = (int)MathF.Ceiling(firstNonNegativeLeftVal);
// corner case for cornerInteval: // corner case for cornerInteval:
if (firstNonNegativeLeftVal == cornerInterval) if (firstNonNegativeLeftVal == cornerInterval)
{ {
cornerInterval++; cornerInterval++;
} }
@ -139,13 +145,18 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
protected virtual void Initialize() 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); ResizeKernel kernel = this.BuildKernel(i, i);
this.kernels[i] = kernel; 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) private ResizeKernel BuildKernel(int destRowIndex, int dataRowIndex)
{ {
float center = ((destRowIndex + .5F) * this.ratio) - .5F; 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); 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; 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"); this.Output.WriteLine($"Actual KernelMap:\n{PrintKernelMap(kernelMap)}\n");
#endif #endif
for (int i = 0; i < kernelMap.DestinationSize; i++) for (int i = 0; i < kernelMap.DestinationLength; i++)
{ {
ResizeKernel kernel = kernelMap.GetKernel(i); ResizeKernel kernel = kernelMap.GetKernel(i);
@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
} }
private static string PrintKernelMap(ResizeKernelMap kernelMap) => 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) => private static string PrintKernelMap(ReferenceKernelMap kernelMap) =>
PrintKernelMap(kernelMap, km => km.DestinationSize, (km, i) => km.GetKernel(i)); PrintKernelMap(kernelMap, km => km.DestinationSize, (km, i) => km.GetKernel(i));

Loading…
Cancel
Save