Browse Source

Fix ResizeProcessor Compand UnPremultiply bug + tests

af/merge-core
Anton Firszov 7 years ago
parent
commit
86b2bfe100
  1. 3
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  2. 2
      src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs
  3. 64
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  4. 2
      tests/Images/External

3
src/ImageSharp/Common/Helpers/ImageMaths.cs

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@ -33,6 +31,7 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Determine the Least Common Multiple (LCM) of two numbers.
/// TODO: This method might be useful for building a more compact <see cref="Processing.Processors.Transforms.KernelMap"/>
/// </summary>
public static int LeastCommonMultiple(int a, int b)
{

2
src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs

@ -263,7 +263,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
ResizeKernel window = this.horizontalKernelMap.Kernels[x - startX];
Unsafe.Add(ref firstPassBaseRef, x * sourceHeight) =
window.ConvolveExpand(tempRowSpan, sourceX).UnPremultiply();
window.ConvolveExpand(tempRowSpan, sourceX);
}
}
else

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

@ -18,8 +18,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial };
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.069F);
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.07F);
public static readonly TheoryData<string, IResampler> AllReSamplers =
new TheoryData<string, IResampler>
{
@ -65,20 +65,16 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
public void Resize_WorksWithAllParallelismLevels<TPixel>(TestImageProvider<TPixel> provider, int maxDegreeOfParallelism)
where TPixel : struct, IPixel<TPixel>
{
if (maxDegreeOfParallelism >= 0)
{
provider.Configuration.MaxDegreeOfParallelism = maxDegreeOfParallelism;
}
provider.Configuration.MaxDegreeOfParallelism =
maxDegreeOfParallelism > 0 ? maxDegreeOfParallelism : Environment.ProcessorCount;
using (Image<TPixel> image = provider.GetImage())
{
SizeF newSize = image.Size() * 0.5f;
image.Mutate(x => x.Resize((Size)newSize, false));
FormattableString details = $"MDP{maxDegreeOfParallelism}";
FormattableString details = $"MDP{maxDegreeOfParallelism}";
image.DebugSave(provider, details);
//image.CompareToReferenceOutput(ImageComparer.TolerantPercentage(0.005f), provider, details);
}
provider.RunValidatingProcessorTest(
x => x.Resize(x.GetCurrentSize() / 2),
details,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}
[Theory]
@ -100,16 +96,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
public void Resize_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true));
image.DebugSave(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
provider.RunValidatingProcessorTest(x => x.Resize(x.GetCurrentSize() / 2), comparer: ValidatorComparer);
}
[Theory]
[WithFileCollection(nameof(CommonTestImages), DefaultPixelType)]
public void Resize_ThrowsForWrappedMemoryImage<TPixel>(TestImageProvider<TPixel> provider)
@ -130,32 +119,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
}
}
[Theory]
[WithFile(TestImages.Png.Kaboom, DefaultPixelType)]
public void Resize_DoesNotBleedAlphaPixels<TPixel>(TestImageProvider<TPixel> provider)
[WithFile(TestImages.Png.Kaboom, DefaultPixelType, false)]
[WithFile(TestImages.Png.Kaboom, DefaultPixelType, true)]
public void Resize_DoesNotBleedAlphaPixels<TPixel>(TestImageProvider<TPixel> provider, bool compand)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2));
image.DebugSave(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
string details = compand ? "Compand" : "";
[Theory]
[WithFile(TestImages.Png.Kaboom, DefaultPixelType)]
public void Resize_Compand_DoesNotBleedAlphaPixels<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, true));
image.DebugSave(provider);
}
provider.RunValidatingProcessorTest(
x => x.Resize(x.GetCurrentSize() / 2, compand),
details,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
}
[Theory]
[WithFile(TestImages.Gif.Giphy, DefaultPixelType)]
public void Resize_IsAppliedToAllFrames<TPixel>(TestImageProvider<TPixel> provider)

2
tests/Images/External

@ -1 +1 @@
Subproject commit c0627f384c1d3d2f8d914c9578ae31354c35fd2c
Subproject commit 03c7fa7582dea75cea0d49514ccb7e1b6dc9e780
Loading…
Cancel
Save