Browse Source

Fix #1006 ResizeMode.Crop

pull/1060/head
James Jackson-South 6 years ago
parent
commit
674815ca9d
  1. 4
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs
  2. 51
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. 2
      tests/Images/External
  5. BIN
      tests/Images/Input/Jpg/issues/issue1006-incorrect-resize.jpg

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

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
@ -122,7 +122,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
// Ensure offsets are normalized for cropping and padding.
ResizeKernel kernel = this.verticalKernelMap.GetKernel(y - this.targetOrigin.Y);
if (kernel.StartIndex + kernel.Length > this.currentWindow.Max)
while (kernel.StartIndex + kernel.Length > this.currentWindow.Max)
{
this.Slide();
}

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

@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
destSize.Height,
image0.Height,
Configuration.Default.MemoryAllocator);
int minimumWorkerAllocationInBytes = verticalKernelMap.MaxDiameter * 2 * destSize.Width * SizeOfVector4;
int minimumWorkerAllocationInBytes = verticalKernelMap.MaxDiameter * 2 * destSize.Width * SizeOfVector4;
verticalKernelMap.Dispose();
using (Image<TPixel> image = image0.Clone(configuration))
@ -419,9 +419,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Size = new Size(image.Width + 200, image.Height + 200), Mode = ResizeMode.BoxPad
};
{
Size = new Size(image.Width + 200, image.Height + 200),
Mode = ResizeMode.BoxPad
};
image.Mutate(x => x.Resize(options));
@ -462,6 +463,26 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
}
}
[Theory]
[WithFile(TestImages.Jpeg.Issues.IncorrectResize1006, DefaultPixelType)]
public void CanResizeLargeImageWithCropMode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Size = new Size(480, 600),
Mode = ResizeMode.Crop
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);
}
}
[Theory]
[WithFileCollection(nameof(CommonTestImages), DefaultPixelType)]
public void ResizeWithMaxMode<TPixel>(TestImageProvider<TPixel> provider)
@ -486,12 +507,12 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Size = new Size(
{
Size = new Size(
(int)Math.Round(image.Width * .75F),
(int)Math.Round(image.Height * .95F)),
Mode = ResizeMode.Min
};
Mode = ResizeMode.Min
};
image.Mutate(x => x.Resize(options));
@ -508,9 +529,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Size = new Size(image.Width + 200, image.Height), Mode = ResizeMode.Pad
};
{
Size = new Size(image.Width + 200, image.Height),
Mode = ResizeMode.Pad
};
image.Mutate(x => x.Resize(options));
@ -527,9 +549,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Size = new Size(image.Width / 2, image.Height), Mode = ResizeMode.Stretch
};
{
Size = new Size(image.Width / 2, image.Height),
Mode = ResizeMode.Stretch
};
image.Mutate(x => x.Resize(options));

1
tests/ImageSharp.Tests/TestImages.cs

@ -190,6 +190,7 @@ namespace SixLabors.ImageSharp.Tests
public const string ExifGetString750Load = "Jpg/issues/issue750-exif-load.jpg";
public const string IncorrectQuality845 = "Jpg/issues/Issue845-Incorrect-Quality99.jpg";
public const string IncorrectColorspace855 = "Jpg/issues/issue855-incorrect-colorspace.jpg";
public const string IncorrectResize1006 = "Jpg/issues/issue1006-incorrect-resize.jpg";
public static class Fuzz
{

2
tests/Images/External

@ -1 +1 @@
Subproject commit ca4cf8318fe4d09f0fc825686dcd477ebfb5e3e5
Subproject commit d7c099cebd58f1d3ff997383351d52d28a29df3d

BIN
tests/Images/Input/Jpg/issues/issue1006-incorrect-resize.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 KiB

Loading…
Cancel
Save