Browse Source

KernelMap refactor WIP

af/merge-core
Anton Firszov 8 years ago
parent
commit
ba589d3121
  1. 3
      src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
  2. 3
      src/ImageSharp/ImageSharp.csproj
  3. 34
      src/ImageSharp/Processing/Processors/Transforms/KernelMap.cs
  4. 3
      tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
  5. 3
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  6. 42
      tests/ImageSharp.Tests/Processing/Processors/Transforms/KernelMapTests.cs

3
src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

@ -5,7 +5,8 @@
<VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix>
<VersionPrefix Condition="$(packageversion) == ''">0.0.1</VersionPrefix>
<Authors>SixLabors and contributors</Authors>
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>
<!--<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>-->
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>7.3</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

3
src/ImageSharp/ImageSharp.csproj

@ -5,7 +5,8 @@
<VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix>
<VersionPrefix Condition="$(packageversion) == ''">0.0.1</VersionPrefix>
<Authors>Six Labors and contributors</Authors>
<TargetFrameworks>netstandard1.3;netstandard2.0;netcoreapp2.1;net472</TargetFrameworks>
<!--<TargetFrameworks>netstandard1.3;netstandard2.0;netcoreapp2.1;net472</TargetFrameworks>-->
<TargetFramework>netcoreapp2.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>SixLabors.ImageSharp</AssemblyName>

34
src/ImageSharp/Processing/Processors/Transforms/KernelMap.cs

@ -19,16 +19,23 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
private readonly ResizeKernel[] kernels;
/// <summary>
/// Initializes a new instance of the <see cref="KernelMap"/> class.
/// </summary>
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/> to use for allocations.</param>
/// <param name="destinationSize">The size of the destination window</param>
/// <param name="kernelRadius">The radius of the kernel</param>
private KernelMap(MemoryAllocator memoryAllocator, int destinationSize, float kernelRadius)
private int period;
private int radius;
private int periodicRegionMin;
private int periodicRegionMax;
private KernelMap(MemoryAllocator memoryAllocator, int destinationSize, int radius, int period)
{
this.DestinationSize = destinationSize;
int width = (int)Math.Ceiling(kernelRadius * 2);
this.period = period;
this.radius = radius;
this.periodicRegionMin = period + radius;
this.periodicRegionMax = destinationSize - radius;
int width = radius * 2;
this.data = memoryAllocator.Allocate2D<float>(width, destinationSize, AllocationOptions.Clean);
this.kernels = new ResizeKernel[destinationSize];
}
@ -71,8 +78,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
scale = 1F;
}
float radius = MathF.Ceiling(scale * sampler.Radius);
var result = new KernelMap(memoryAllocator, destinationSize, radius);
int period = ImageMaths.LeastCommonMultiple(sourceSize, destinationSize) / sourceSize;
int radius = (int)MathF.Ceiling(scale * sampler.Radius);
var result = new KernelMap(memoryAllocator, destinationSize, radius, period);
for (int i = 0; i < destinationSize; i++)
{
@ -122,6 +131,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
return result;
}
private int ReduceIndex(int destIndex)
{
return destIndex;
}
/// <summary>
/// Slices a weights value at the given positions.
/// </summary>

3
tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<!--<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>-->
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<RootNamespace>SixLabors.ImageSharp.Benchmarks</RootNamespace>

3
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net462;net472;netcoreapp2.1</TargetFrameworks>
<!--<TargetFrameworks>net462;net472;netcoreapp2.1</TargetFrameworks>-->
<TargetFramework>netcoreapp2.1</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<DebugType Condition="$(codecov) != ''">full</DebugType>

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

@ -20,17 +20,39 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
this.Output = output;
}
/// <summary>
/// resamplerName, srcSize, destSize
/// </summary>
public static readonly TheoryData<string, int, int> KernelMapData = new TheoryData<string, int, int>
{
{ nameof(KnownResamplers.Bicubic), 15, 10 },
{ nameof(KnownResamplers.Bicubic), 10, 15 },
{ nameof(KnownResamplers.Bicubic), 20, 20 },
{ nameof(KnownResamplers.Bicubic), 50, 40 },
{ nameof(KnownResamplers.Bicubic), 40, 50 },
{ nameof(KnownResamplers.Bicubic), 500, 200 },
{ nameof(KnownResamplers.Bicubic), 200, 500 },
{ nameof(KnownResamplers.Lanczos3), 16, 12 },
{ nameof(KnownResamplers.Lanczos3), 12, 16 },
{ nameof(KnownResamplers.Lanczos3), 12, 9 },
{ nameof(KnownResamplers.Lanczos3), 9, 12 },
{ nameof(KnownResamplers.Lanczos3), 6, 8 },
{ nameof(KnownResamplers.Lanczos3), 8, 6 },
// TODO: What's wrong here:
// { nameof(KnownResamplers.Lanczos3), 20, 12 },
{nameof(KnownResamplers.Lanczos8), 500, 200 },
{nameof(KnownResamplers.Lanczos8), 100, 10 },
{nameof(KnownResamplers.Lanczos8), 100, 80 },
{nameof(KnownResamplers.Lanczos8), 10, 100 },
};
[Theory]
[InlineData(500, 200, nameof(KnownResamplers.Bicubic))]
[InlineData(50, 40, nameof(KnownResamplers.Bicubic))]
[InlineData(40, 30, nameof(KnownResamplers.Bicubic))]
[InlineData(15, 10, nameof(KnownResamplers.Bicubic))]
[InlineData(500, 200, nameof(KnownResamplers.Lanczos8))]
[InlineData(100, 80, nameof(KnownResamplers.Lanczos8))]
[InlineData(100, 10, nameof(KnownResamplers.Lanczos8))]
[InlineData(10, 100, nameof(KnownResamplers.Lanczos8))]
public void KernelMapContentIsCorrect(int srcSize, int destSize, string resamplerName)
[MemberData(nameof(KernelMapData))]
public void KernelMapContentIsCorrect(string resamplerName, int srcSize, int destSize)
{
var resampler = (IResampler)typeof(KnownResamplers).GetProperty(resamplerName).GetValue(null);

Loading…
Cancel
Save