|
|
|
@ -3,10 +3,12 @@ |
|
|
|
|
|
|
|
using System.Numerics; |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Exif; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
using SixLabors.ImageSharp.Processing; |
|
|
|
using SixLabors.ImageSharp.Processing.Processors.Transforms; |
|
|
|
using SixLabors.ImageSharp.Tests.Memory; |
|
|
|
using SixLabors.ImageSharp.Tests.TestUtilities; |
|
|
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
@ -20,15 +22,15 @@ public class ResizeTests |
|
|
|
|
|
|
|
public static readonly string[] AllResamplerNames = TestUtils.GetAllResamplerNames(); |
|
|
|
|
|
|
|
public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial }; |
|
|
|
public static readonly string[] CommonTestImages = [TestImages.Png.CalliphoraPartial]; |
|
|
|
|
|
|
|
public static readonly string[] SmokeTestResamplerNames = |
|
|
|
{ |
|
|
|
[ |
|
|
|
nameof(KnownResamplers.NearestNeighbor), |
|
|
|
nameof(KnownResamplers.Bicubic), |
|
|
|
nameof(KnownResamplers.Box), |
|
|
|
nameof(KnownResamplers.Lanczos5), |
|
|
|
}; |
|
|
|
]; |
|
|
|
|
|
|
|
private static readonly ImageComparer ValidatorComparer = |
|
|
|
ImageComparer.TolerantPercentage(0.07F); |
|
|
|
@ -78,7 +80,7 @@ public class ResizeTests |
|
|
|
// resizing: (15, 12) -> (10, 6)
|
|
|
|
// kernel dimensions: (3, 4)
|
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
Size destSize = new Size(image.Width * wN / wD, image.Height * hN / hD); |
|
|
|
Size destSize = new(image.Width * wN / wD, image.Height * hN / hD); |
|
|
|
image.Mutate(x => x.Resize(destSize, KnownResamplers.Bicubic, false)); |
|
|
|
FormattableString outputInfo = $"({wN}÷{wD},{hN}÷{hD})"; |
|
|
|
image.DebugSave(provider, outputInfo, appendPixelTypeToFileName: false); |
|
|
|
@ -106,7 +108,7 @@ public class ResizeTests |
|
|
|
Configuration configuration = Configuration.CreateDefaultInstance(); |
|
|
|
|
|
|
|
int workingBufferSizeHintInBytes = workingBufferLimitInRows * destSize.Width * SizeOfVector4; |
|
|
|
TestMemoryAllocator allocator = new TestMemoryAllocator(); |
|
|
|
TestMemoryAllocator allocator = new(); |
|
|
|
allocator.EnableNonThreadSafeLogging(); |
|
|
|
configuration.MemoryAllocator = allocator; |
|
|
|
configuration.WorkingBufferSizeHintInBytes = workingBufferSizeHintInBytes; |
|
|
|
@ -211,7 +213,7 @@ public class ResizeTests |
|
|
|
provider.RunValidatingProcessorTest( |
|
|
|
x => |
|
|
|
{ |
|
|
|
ResizeOptions resizeOptions = new ResizeOptions() |
|
|
|
ResizeOptions resizeOptions = new() |
|
|
|
{ |
|
|
|
Size = x.GetCurrentSize() / 2, |
|
|
|
Mode = ResizeMode.Crop, |
|
|
|
@ -242,9 +244,7 @@ public class ResizeTests |
|
|
|
[WithTestPatternImages(50, 50, CommonNonDefaultPixelTypes)] |
|
|
|
public void Resize_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
provider.RunValidatingProcessorTest(x => x.Resize(x.GetCurrentSize() / 2), comparer: ValidatorComparer); |
|
|
|
} |
|
|
|
=> provider.RunValidatingProcessorTest(x => x.Resize(x.GetCurrentSize() / 2), comparer: ValidatorComparer); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)] |
|
|
|
@ -257,7 +257,7 @@ public class ResizeTests |
|
|
|
|
|
|
|
using Image<TPixel> image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height); |
|
|
|
Assert.ThrowsAny<Exception>( |
|
|
|
() => { image1.Mutate(x => x.Resize(image0.Width / 2, image0.Height / 2, true)); }); |
|
|
|
() => image1.Mutate(x => x.Resize(image0.Width / 2, image0.Height / 2, true))); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
@ -365,12 +365,12 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
Rectangle sourceRectangle = new Rectangle( |
|
|
|
Rectangle sourceRectangle = new( |
|
|
|
image.Width / 8, |
|
|
|
image.Height / 8, |
|
|
|
image.Width / 4, |
|
|
|
image.Height / 4); |
|
|
|
Rectangle destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); |
|
|
|
Rectangle destRectangle = new(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); |
|
|
|
|
|
|
|
image.Mutate( |
|
|
|
x => x.Resize( |
|
|
|
@ -437,7 +437,7 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
ResizeOptions options = new ResizeOptions |
|
|
|
ResizeOptions options = new() |
|
|
|
{ |
|
|
|
Size = new Size(image.Width + 200, image.Height + 200), |
|
|
|
Mode = ResizeMode.BoxPad, |
|
|
|
@ -456,7 +456,8 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
ResizeOptions options = new ResizeOptions { Size = new Size(image.Width, image.Height / 2) }; |
|
|
|
ResizeOptions options = new() |
|
|
|
{ Size = new Size(image.Width, image.Height / 2) }; |
|
|
|
|
|
|
|
image.Mutate(x => x.Resize(options)); |
|
|
|
|
|
|
|
@ -470,7 +471,8 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
ResizeOptions options = new ResizeOptions { Size = new Size(image.Width / 2, image.Height) }; |
|
|
|
ResizeOptions options = new() |
|
|
|
{ Size = new Size(image.Width / 2, image.Height) }; |
|
|
|
|
|
|
|
image.Mutate(x => x.Resize(options)); |
|
|
|
|
|
|
|
@ -484,7 +486,7 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
ResizeOptions options = new ResizeOptions |
|
|
|
ResizeOptions options = new() |
|
|
|
{ |
|
|
|
Size = new Size(480, 600), |
|
|
|
Mode = ResizeMode.Crop |
|
|
|
@ -502,7 +504,8 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
ResizeOptions options = new ResizeOptions { Size = new Size(300, 300), Mode = ResizeMode.Max }; |
|
|
|
ResizeOptions options = new() |
|
|
|
{ Size = new Size(300, 300), Mode = ResizeMode.Max }; |
|
|
|
|
|
|
|
image.Mutate(x => x.Resize(options)); |
|
|
|
|
|
|
|
@ -516,7 +519,7 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
ResizeOptions options = new ResizeOptions |
|
|
|
ResizeOptions options = new() |
|
|
|
{ |
|
|
|
Size = new Size((int)Math.Round(image.Width * .75F), (int)Math.Round(image.Height * .95F)), |
|
|
|
Mode = ResizeMode.Min |
|
|
|
@ -534,7 +537,7 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
ResizeOptions options = new ResizeOptions |
|
|
|
ResizeOptions options = new() |
|
|
|
{ |
|
|
|
Size = new Size(image.Width + 200, image.Height), |
|
|
|
Mode = ResizeMode.Pad, |
|
|
|
@ -553,7 +556,7 @@ public class ResizeTests |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
ResizeOptions options = new ResizeOptions |
|
|
|
ResizeOptions options = new() |
|
|
|
{ |
|
|
|
Size = new Size(image.Width / 2, image.Height), |
|
|
|
Mode = ResizeMode.Stretch |
|
|
|
@ -579,6 +582,7 @@ public class ResizeTests |
|
|
|
} |
|
|
|
|
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
|
|
|
|
// Don't bother saving, we're testing the EXIF metadata updates.
|
|
|
|
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2)); |
|
|
|
} |
|
|
|
@ -586,8 +590,8 @@ public class ResizeTests |
|
|
|
[Fact] |
|
|
|
public void Issue1195() |
|
|
|
{ |
|
|
|
using Image<Rgba32> image = new Image<Rgba32>(2, 300); |
|
|
|
Size size = new Size(50, 50); |
|
|
|
using Image<Rgba32> image = new(2, 300); |
|
|
|
Size size = new(50, 50); |
|
|
|
image.Mutate(x => x |
|
|
|
.Resize( |
|
|
|
new ResizeOptions |
|
|
|
@ -605,8 +609,8 @@ public class ResizeTests |
|
|
|
[InlineData(3, 7)] |
|
|
|
public void Issue1342(int width, int height) |
|
|
|
{ |
|
|
|
using Image<Rgba32> image = new Image<Rgba32>(1, 1); |
|
|
|
Size size = new Size(width, height); |
|
|
|
using Image<Rgba32> image = new(1, 1); |
|
|
|
Size size = new(width, height); |
|
|
|
image.Mutate(x => x |
|
|
|
.Resize( |
|
|
|
new ResizeOptions |
|
|
|
@ -630,4 +634,28 @@ public class ResizeTests |
|
|
|
appendPixelTypeToFileName: false, |
|
|
|
appendSourceFileOrDescription: false); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithTestPatternImages(100, 100, PixelTypes.Rgba32)] |
|
|
|
public void ResizeUpdatesSubject<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using Image<TPixel> image = provider.GetImage(); |
|
|
|
|
|
|
|
image.Metadata.ExifProfile = new(); |
|
|
|
image.Metadata.ExifProfile.SetValue(ExifTag.SubjectLocation, [5, 15]); |
|
|
|
image.Metadata.ExifProfile.SetValue(ExifTag.SubjectArea, [5, 15, 20, 20]); |
|
|
|
|
|
|
|
image.Mutate(ctx => ctx.Resize(new Size(image.Width / 2, image.Height / 2))); |
|
|
|
|
|
|
|
// The transform operates in pixel space, so the resulting values correspond to the
|
|
|
|
// scaled pixel centers, producing whole-number coordinates after resizing.
|
|
|
|
Assert.Equal( |
|
|
|
[2, 7], |
|
|
|
image.Metadata.ExifProfile.GetValue(ExifTag.SubjectLocation).Value); |
|
|
|
|
|
|
|
Assert.Equal( |
|
|
|
[2, 7, 11, 11], |
|
|
|
image.Metadata.ExifProfile.GetValue(ExifTag.SubjectArea).Value); |
|
|
|
} |
|
|
|
} |
|
|
|
|