Skip to content

Commit 9275555

Browse files
Merge pull request #1060 from SixLabors/js/fix-1006
Fix #1006 Resize from large source to small thumbnail produces deformed top pixel rows
2 parents 1017121 + 674815c commit 9275555

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -122,7 +122,7 @@ public void FillDestinationPixels(RowInterval rowInterval, Buffer2D<TPixel> dest
122122
// Ensure offsets are normalized for cropping and padding.
123123
ResizeKernel kernel = this.verticalKernelMap.GetKernel(y - this.targetOrigin.Y);
124124

125-
if (kernel.StartIndex + kernel.Length > this.currentWindow.Max)
125+
while (kernel.StartIndex + kernel.Length > this.currentWindow.Max)
126126
{
127127
this.Slide();
128128
}

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

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void WorkingBufferSizeHintInBytes_IsAppliedCorrectly<TPixel>(
135135
destSize.Height,
136136
image0.Height,
137137
Configuration.Default.MemoryAllocator);
138-
int minimumWorkerAllocationInBytes = verticalKernelMap.MaxDiameter * 2 * destSize.Width * SizeOfVector4;
138+
int minimumWorkerAllocationInBytes = verticalKernelMap.MaxDiameter * 2 * destSize.Width * SizeOfVector4;
139139
verticalKernelMap.Dispose();
140140

141141
using (Image<TPixel> image = image0.Clone(configuration))
@@ -419,9 +419,10 @@ public void ResizeWithBoxPadMode<TPixel>(TestImageProvider<TPixel> provider)
419419
using (Image<TPixel> image = provider.GetImage())
420420
{
421421
var options = new ResizeOptions
422-
{
423-
Size = new Size(image.Width + 200, image.Height + 200), Mode = ResizeMode.BoxPad
424-
};
422+
{
423+
Size = new Size(image.Width + 200, image.Height + 200),
424+
Mode = ResizeMode.BoxPad
425+
};
425426

426427
image.Mutate(x => x.Resize(options));
427428

@@ -462,6 +463,26 @@ public void ResizeWithCropWidthMode<TPixel>(TestImageProvider<TPixel> provider)
462463
}
463464
}
464465

466+
[Theory]
467+
[WithFile(TestImages.Jpeg.Issues.IncorrectResize1006, DefaultPixelType)]
468+
public void CanResizeLargeImageWithCropMode<TPixel>(TestImageProvider<TPixel> provider)
469+
where TPixel : struct, IPixel<TPixel>
470+
{
471+
using (Image<TPixel> image = provider.GetImage())
472+
{
473+
var options = new ResizeOptions
474+
{
475+
Size = new Size(480, 600),
476+
Mode = ResizeMode.Crop
477+
};
478+
479+
image.Mutate(x => x.Resize(options));
480+
481+
image.DebugSave(provider);
482+
image.CompareToReferenceOutput(ValidatorComparer, provider);
483+
}
484+
}
485+
465486
[Theory]
466487
[WithFileCollection(nameof(CommonTestImages), DefaultPixelType)]
467488
public void ResizeWithMaxMode<TPixel>(TestImageProvider<TPixel> provider)
@@ -486,12 +507,12 @@ public void ResizeWithMinMode<TPixel>(TestImageProvider<TPixel> provider)
486507
using (Image<TPixel> image = provider.GetImage())
487508
{
488509
var options = new ResizeOptions
489-
{
490-
Size = new Size(
510+
{
511+
Size = new Size(
491512
(int)Math.Round(image.Width * .75F),
492513
(int)Math.Round(image.Height * .95F)),
493-
Mode = ResizeMode.Min
494-
};
514+
Mode = ResizeMode.Min
515+
};
495516

496517
image.Mutate(x => x.Resize(options));
497518

@@ -508,9 +529,10 @@ public void ResizeWithPadMode<TPixel>(TestImageProvider<TPixel> provider)
508529
using (Image<TPixel> image = provider.GetImage())
509530
{
510531
var options = new ResizeOptions
511-
{
512-
Size = new Size(image.Width + 200, image.Height), Mode = ResizeMode.Pad
513-
};
532+
{
533+
Size = new Size(image.Width + 200, image.Height),
534+
Mode = ResizeMode.Pad
535+
};
514536

515537
image.Mutate(x => x.Resize(options));
516538

@@ -527,9 +549,10 @@ public void ResizeWithStretchMode<TPixel>(TestImageProvider<TPixel> provider)
527549
using (Image<TPixel> image = provider.GetImage())
528550
{
529551
var options = new ResizeOptions
530-
{
531-
Size = new Size(image.Width / 2, image.Height), Mode = ResizeMode.Stretch
532-
};
552+
{
553+
Size = new Size(image.Width / 2, image.Height),
554+
Mode = ResizeMode.Stretch
555+
};
533556

534557
image.Mutate(x => x.Resize(options));
535558

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public static class Issues
190190
public const string ExifGetString750Load = "Jpg/issues/issue750-exif-load.jpg";
191191
public const string IncorrectQuality845 = "Jpg/issues/Issue845-Incorrect-Quality99.jpg";
192192
public const string IncorrectColorspace855 = "Jpg/issues/issue855-incorrect-colorspace.jpg";
193+
public const string IncorrectResize1006 = "Jpg/issues/issue1006-incorrect-resize.jpg";
193194

194195
public static class Fuzz
195196
{
604 KB
Loading

0 commit comments

Comments
 (0)