Browse Source
Merge pull request #3157 from SixLabors/fix/3156-resize-to-one
Fix degeneracy check for resize transforms
pull/3158/head
James Jackson-South
3 weeks ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
16 additions and
6 deletions
-
src/ImageSharp/Processing/Processors/Transforms/TransformUtilities.cs
-
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
|
|
|
@ -19,7 +19,7 @@ internal static class TransformUtilities |
|
|
|
/// </summary>
|
|
|
|
/// <param name="matrix">The transform matrix.</param>
|
|
|
|
public static bool IsDegenerate(Matrix3x2 matrix) |
|
|
|
=> IsNaN(matrix) || IsZero(matrix.GetDeterminant()); |
|
|
|
=> IsNaN(matrix) || matrix.GetDeterminant() == 0F; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a value that indicates whether the specified matrix is degenerate
|
|
|
|
@ -28,11 +28,7 @@ internal static class TransformUtilities |
|
|
|
/// </summary>
|
|
|
|
/// <param name="matrix">The transform matrix.</param>
|
|
|
|
public static bool IsDegenerate(Matrix4x4 matrix) |
|
|
|
=> IsNaN(matrix) || IsZero(matrix.GetDeterminant()); |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
private static bool IsZero(float a) |
|
|
|
=> a > -Constants.EpsilonSquared && a < Constants.EpsilonSquared; |
|
|
|
=> IsNaN(matrix) || matrix.GetDeterminant() == 0F; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a value that indicates whether the specified matrix contains any values
|
|
|
|
|
|
|
|
@ -699,6 +699,20 @@ public class ResizeTests |
|
|
|
appendSourceFileOrDescription: false); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(1024)] |
|
|
|
[InlineData(2048)] |
|
|
|
public void Issue3156_CanResizeLargeSquareToSinglePixel(int length) |
|
|
|
{ |
|
|
|
Rgba32 white = Color.White.ToPixel<Rgba32>(); |
|
|
|
using Image<Rgba32> image = new(length, length, white); |
|
|
|
|
|
|
|
image.Mutate(x => x.Resize(1, 1)); |
|
|
|
|
|
|
|
Assert.Equal(new Size(1, 1), image.Size); |
|
|
|
Assert.Equal(white, image[0, 0]); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithTestPatternImages(100, 100, PixelTypes.Rgba32)] |
|
|
|
public void ResizeUpdatesSubject<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
|