Browse Source

Rename helper, fix docs.

pull/3011/head
James Jackson-South 6 months ago
parent
commit
726794a98f
  1. 4
      src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs
  2. 12
      src/ImageSharp/Processing/AffineTransformBuilder.cs
  3. 4
      src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs
  4. 2
      src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor.cs
  5. 2
      src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs
  6. 2
      src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor.cs
  7. 6
      src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs
  8. 4
      src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor.cs
  9. 4
      src/ImageSharp/Processing/Processors/Transforms/Linear/SkewProcessor.cs
  10. 2
      src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs
  11. 10
      src/ImageSharp/Processing/Processors/Transforms/TransformUtilities.cs
  12. 20
      src/ImageSharp/Processing/ProjectiveTransformBuilder.cs
  13. 4
      tests/ImageSharp.Tests/Processing/Transforms/TransformBuilderTestBase.cs
  14. 2
      tests/ImageSharp.Tests/TestImages.cs

4
src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs

@ -318,7 +318,7 @@ public sealed class ExifProfile : IDeepCloneable<ExifProfile>
{
if (location.Value?.Length == 2)
{
Vector2 point = TransformUtils.ProjectiveTransform2D(location.Value[0], location.Value[1], matrix);
Vector2 point = TransformUtilities.ProjectiveTransform2D(location.Value[0], location.Value[1], matrix);
// Ensure the point is within the image dimensions.
point = Vector2.Clamp(point, Vector2.Zero, new Vector2(width - 1, height - 1));
@ -340,7 +340,7 @@ public sealed class ExifProfile : IDeepCloneable<ExifProfile>
if (area.Value?.Length == 4)
{
RectangleF rectangle = new(area.Value[0], area.Value[1], area.Value[2], area.Value[3]);
if (!TransformUtils.TryGetTransformedRectangle(rectangle, matrix, out RectangleF bounds))
if (!TransformUtilities.TryGetTransformedRectangle(rectangle, matrix, out RectangleF bounds))
{
return;
}

12
src/ImageSharp/Processing/AffineTransformBuilder.cs

@ -37,7 +37,7 @@ public class AffineTransformBuilder
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
public AffineTransformBuilder PrependRotationRadians(float radians)
=> this.Prepend(
size => TransformUtils.CreateRotationTransformMatrixRadians(radians, size));
size => TransformUtilities.CreateRotationTransformMatrixRadians(radians, size));
/// <summary>
/// Prepends a rotation matrix using the given rotation in degrees at the given origin.
@ -73,7 +73,7 @@ public class AffineTransformBuilder
/// <param name="radians">The amount of rotation, in radians.</param>
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
public AffineTransformBuilder AppendRotationRadians(float radians)
=> this.Append(size => TransformUtils.CreateRotationTransformMatrixRadians(radians, size));
=> this.Append(size => TransformUtilities.CreateRotationTransformMatrixRadians(radians, size));
/// <summary>
/// Appends a rotation matrix using the given rotation in degrees at the given origin.
@ -157,7 +157,7 @@ public class AffineTransformBuilder
/// <param name="radiansY">The Y angle, in radians.</param>
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
public AffineTransformBuilder PrependSkewRadians(float radiansX, float radiansY)
=> this.Prepend(size => TransformUtils.CreateSkewTransformMatrixRadians(radiansX, radiansY, size));
=> this.Prepend(size => TransformUtilities.CreateSkewTransformMatrixRadians(radiansX, radiansY, size));
/// <summary>
/// Prepends a skew matrix using the given angles in degrees at the given origin.
@ -195,7 +195,7 @@ public class AffineTransformBuilder
/// <param name="radiansY">The Y angle, in radians.</param>
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
public AffineTransformBuilder AppendSkewRadians(float radiansX, float radiansY)
=> this.Append(size => TransformUtils.CreateSkewTransformMatrixRadians(radiansX, radiansY, size));
=> this.Append(size => TransformUtilities.CreateSkewTransformMatrixRadians(radiansX, radiansY, size));
/// <summary>
/// Appends a skew matrix using the given angles in degrees at the given origin.
@ -347,11 +347,11 @@ public class AffineTransformBuilder
/// </exception>
/// <returns>The <see cref="Size"/>.</returns>
internal static SizeF GetTransformedSize(Rectangle sourceRectangle, Matrix3x2 matrix)
=> TransformUtils.GetRawTransformedSize(matrix, sourceRectangle.Size);
=> TransformUtilities.GetRawTransformedSize(matrix, sourceRectangle.Size);
private static void CheckDegenerate(Matrix3x2 matrix)
{
if (TransformUtils.IsDegenerate(matrix))
if (TransformUtilities.IsDegenerate(matrix))
{
throw new DegenerateTransformException("Matrix is degenerate. Check input values.");
}

4
src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs

@ -51,7 +51,7 @@ public static class TransformExtensions
IResampler sampler)
{
Matrix3x2 transform = builder.BuildMatrix(sourceRectangle);
Size targetDimensions = TransformUtils.GetTransformedCanvasSize(transform, sourceRectangle.Size);
Size targetDimensions = TransformUtilities.GetTransformedCanvasSize(transform, sourceRectangle.Size);
return source.Transform(sourceRectangle, transform, targetDimensions, sampler);
}
@ -113,7 +113,7 @@ public static class TransformExtensions
IResampler sampler)
{
Matrix4x4 transform = builder.BuildMatrix(sourceRectangle);
Size targetDimensions = TransformUtils.GetTransformedCanvasSize(transform, sourceRectangle.Size);
Size targetDimensions = TransformUtilities.GetTransformedCanvasSize(transform, sourceRectangle.Size);
return source.Transform(sourceRectangle, transform, targetDimensions, sampler);
}

2
src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor.cs

@ -21,7 +21,7 @@ public class AffineTransformProcessor : CloningImageProcessor
Guard.NotNull(sampler, nameof(sampler));
Guard.MustBeValueType(sampler);
if (TransformUtils.IsDegenerate(matrix))
if (TransformUtilities.IsDegenerate(matrix))
{
throw new DegenerateTransformException("Matrix is degenerate. Check input values.");
}

2
src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs

@ -79,7 +79,7 @@ internal class AffineTransformProcessor<TPixel> : TransformProcessor<TPixel>, IR
// All matrices are defined in normalized coordinate space so we need to convert to pixel space.
// After normalization we need to invert the matrix for correct sampling.
matrix = TransformUtils.NormalizeToPixel(matrix);
matrix = TransformUtilities.NormalizeToPixel(matrix);
Matrix3x2.Invert(matrix, out matrix);
if (sampler is NearestNeighborResampler)

2
src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor.cs

@ -21,7 +21,7 @@ public sealed class ProjectiveTransformProcessor : CloningImageProcessor
Guard.NotNull(sampler, nameof(sampler));
Guard.MustBeValueType(sampler);
if (TransformUtils.IsDegenerate(matrix))
if (TransformUtilities.IsDegenerate(matrix))
{
throw new DegenerateTransformException("Matrix is degenerate. Check input values.");
}

6
src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs

@ -77,7 +77,7 @@ internal class ProjectiveTransformProcessor<TPixel> : TransformProcessor<TPixel>
// All matrices are defined in normalized coordinate space so we need to convert to pixel space.
// After normalization we need to invert the matrix for correct sampling.
matrix = TransformUtils.NormalizeToPixel(matrix);
matrix = TransformUtilities.NormalizeToPixel(matrix);
Matrix4x4.Invert(matrix, out matrix);
if (sampler is NearestNeighborResampler)
@ -137,7 +137,7 @@ internal class ProjectiveTransformProcessor<TPixel> : TransformProcessor<TPixel>
for (int x = 0; x < destinationRowSpan.Length; x++)
{
Vector2 point = TransformUtils.ProjectiveTransform2D(x, y, this.matrix);
Vector2 point = TransformUtilities.ProjectiveTransform2D(x, y, this.matrix);
int px = (int)MathF.Round(point.X);
int py = (int)MathF.Round(point.Y);
@ -209,7 +209,7 @@ internal class ProjectiveTransformProcessor<TPixel> : TransformProcessor<TPixel>
for (int x = 0; x < span.Length; x++)
{
Vector2 point = TransformUtils.ProjectiveTransform2D(x, y, matrix);
Vector2 point = TransformUtilities.ProjectiveTransform2D(x, y, matrix);
float pY = point.Y;
float pX = point.X;

4
src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor.cs

@ -28,14 +28,14 @@ public sealed class RotateProcessor : AffineTransformProcessor
/// <param name="sourceSize">The source image size</param>
public RotateProcessor(float degrees, IResampler sampler, Size sourceSize)
: this(
TransformUtils.CreateRotationTransformMatrixDegrees(degrees, sourceSize),
TransformUtilities.CreateRotationTransformMatrixDegrees(degrees, sourceSize),
sampler,
sourceSize)
=> this.Degrees = degrees;
// Helper constructor
private RotateProcessor(Matrix3x2 rotationMatrix, IResampler sampler, Size sourceSize)
: base(rotationMatrix, sampler, TransformUtils.GetTransformedCanvasSize(rotationMatrix, sourceSize))
: base(rotationMatrix, sampler, TransformUtilities.GetTransformedCanvasSize(rotationMatrix, sourceSize))
{
}

4
src/ImageSharp/Processing/Processors/Transforms/Linear/SkewProcessor.cs

@ -30,7 +30,7 @@ public sealed class SkewProcessor : AffineTransformProcessor
/// <param name="sourceSize">The source image size</param>
public SkewProcessor(float degreesX, float degreesY, IResampler sampler, Size sourceSize)
: this(
TransformUtils.CreateSkewTransformMatrixDegrees(degreesX, degreesY, sourceSize),
TransformUtilities.CreateSkewTransformMatrixDegrees(degreesX, degreesY, sourceSize),
sampler,
sourceSize)
{
@ -40,7 +40,7 @@ public sealed class SkewProcessor : AffineTransformProcessor
// Helper constructor:
private SkewProcessor(Matrix3x2 skewMatrix, IResampler sampler, Size sourceSize)
: base(skewMatrix, sampler, TransformUtils.GetTransformedCanvasSize(skewMatrix, sourceSize))
: base(skewMatrix, sampler, TransformUtilities.GetTransformedCanvasSize(skewMatrix, sourceSize))
{
}

2
src/ImageSharp/Processing/Processors/Transforms/SwizzleProcessor{TSwizzler,TPixel}.cs

@ -24,7 +24,7 @@ internal class SwizzleProcessor<TSwizzler, TPixel> : TransformProcessor<TPixel>
// Calculate the transform matrix from the swizzle operation to allow us
// to update any metadata that represents pixel coordinates in the source image.
this.transformMatrix = new ProjectiveTransformBuilder()
.AppendMatrix(TransformUtils.GetSwizzlerMatrix(swizzler, sourceRectangle))
.AppendMatrix(TransformUtilities.GetSwizzlerMatrix(swizzler, sourceRectangle))
.BuildMatrix(sourceRectangle);
}

10
src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs → src/ImageSharp/Processing/Processors/Transforms/TransformUtilities.cs

@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms;
/// <summary>
/// Contains utility methods for working with transforms.
/// </summary>
internal static class TransformUtils
internal static class TransformUtilities
{
/// <summary>
/// Returns a value that indicates whether the specified matrix is degenerate
@ -80,7 +80,7 @@ internal static class TransformUtils
}
/// <summary>
/// Creates a centered rotation transform matrix using the given rotation in degrees and The original source size.
/// Creates a centered rotation transform matrix using the given rotation in degrees and the original source size.
/// </summary>
/// <param name="degrees">The amount of rotation, in degrees.</param>
/// <param name="size">The source image size.</param>
@ -90,7 +90,7 @@ internal static class TransformUtils
=> CreateRotationTransformMatrixRadians(GeometryUtilities.DegreeToRadian(degrees), size);
/// <summary>
/// Creates a centered rotation transform matrix using the given rotation in radians and The original source size.
/// Creates a centered rotation transform matrix using the given rotation in radians and the original source size.
/// </summary>
/// <param name="radians">The amount of rotation, in radians.</param>
/// <param name="size">The source image size.</param>
@ -100,7 +100,7 @@ internal static class TransformUtils
=> CreateCenteredTransformMatrix(Matrix3x2Extensions.CreateRotation(radians, PointF.Empty), size);
/// <summary>
/// Creates a centered skew transform matrix from the give angles in degrees and The original source size.
/// Creates a centered skew transform matrix from the give angles in degrees and the original source size.
/// </summary>
/// <param name="degreesX">The X angle, in degrees.</param>
/// <param name="degreesY">The Y angle, in degrees.</param>
@ -111,7 +111,7 @@ internal static class TransformUtils
=> CreateSkewTransformMatrixRadians(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY), size);
/// <summary>
/// Creates a centered skew transform matrix from the give angles in radians and The original source size.
/// Creates a centered skew transform matrix from the give angles in radians and the original source size.
/// </summary>
/// <param name="radiansX">The X angle, in radians.</param>
/// <param name="radiansY">The Y angle, in radians.</param>

20
src/ImageSharp/Processing/ProjectiveTransformBuilder.cs

@ -28,7 +28,7 @@ public class ProjectiveTransformBuilder
/// <param name="fraction">The amount to taper.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
public ProjectiveTransformBuilder PrependTaper(TaperSide side, TaperCorner corner, float fraction)
=> this.Prepend(size => TransformUtils.CreateTaperMatrix(size, side, corner, fraction));
=> this.Prepend(size => TransformUtilities.CreateTaperMatrix(size, side, corner, fraction));
/// <summary>
/// Appends a matrix that performs a tapering projective transform.
@ -38,7 +38,7 @@ public class ProjectiveTransformBuilder
/// <param name="fraction">The amount to taper.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
public ProjectiveTransformBuilder AppendTaper(TaperSide side, TaperCorner corner, float fraction)
=> this.Append(size => TransformUtils.CreateTaperMatrix(size, side, corner, fraction));
=> this.Append(size => TransformUtilities.CreateTaperMatrix(size, side, corner, fraction));
/// <summary>
/// Prepends a centered rotation matrix using the given rotation in degrees.
@ -54,7 +54,7 @@ public class ProjectiveTransformBuilder
/// <param name="radians">The amount of rotation, in radians.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
public ProjectiveTransformBuilder PrependRotationRadians(float radians)
=> this.Prepend(size => new Matrix4x4(TransformUtils.CreateRotationTransformMatrixRadians(radians, size)));
=> this.Prepend(size => new Matrix4x4(TransformUtilities.CreateRotationTransformMatrixRadians(radians, size)));
/// <summary>
/// Prepends a centered rotation matrix using the given rotation in degrees at the given origin.
@ -89,7 +89,7 @@ public class ProjectiveTransformBuilder
/// <param name="radians">The amount of rotation, in radians.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
public ProjectiveTransformBuilder AppendRotationRadians(float radians)
=> this.Append(size => new Matrix4x4(TransformUtils.CreateRotationTransformMatrixRadians(radians, size)));
=> this.Append(size => new Matrix4x4(TransformUtilities.CreateRotationTransformMatrixRadians(radians, size)));
/// <summary>
/// Appends a centered rotation matrix using the given rotation in degrees at the given origin.
@ -173,7 +173,7 @@ public class ProjectiveTransformBuilder
/// <param name="radiansY">The Y angle, in radians.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
public ProjectiveTransformBuilder PrependSkewRadians(float radiansX, float radiansY)
=> this.Prepend(size => new Matrix4x4(TransformUtils.CreateSkewTransformMatrixRadians(radiansX, radiansY, size)));
=> this.Prepend(size => new Matrix4x4(TransformUtilities.CreateSkewTransformMatrixRadians(radiansX, radiansY, size)));
/// <summary>
/// Prepends a skew matrix using the given angles in degrees at the given origin.
@ -211,7 +211,7 @@ public class ProjectiveTransformBuilder
/// <param name="radiansY">The Y angle, in radians.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
public ProjectiveTransformBuilder AppendSkewRadians(float radiansX, float radiansY)
=> this.Append(size => new Matrix4x4(TransformUtils.CreateSkewTransformMatrixRadians(radiansX, radiansY, size)));
=> this.Append(size => new Matrix4x4(TransformUtilities.CreateSkewTransformMatrixRadians(radiansX, radiansY, size)));
/// <summary>
/// Appends a skew matrix using the given angles in degrees at the given origin.
@ -274,7 +274,7 @@ public class ProjectiveTransformBuilder
/// <param name="bottomLeft">The bottom-left corner point of the distorted quad.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
public ProjectiveTransformBuilder PrependQuadDistortion(PointF topLeft, PointF topRight, PointF bottomRight, PointF bottomLeft)
=> this.Prepend(size => TransformUtils.CreateQuadDistortionMatrix(
=> this.Prepend(size => TransformUtilities.CreateQuadDistortionMatrix(
new Rectangle(Point.Empty, size),
topLeft,
topRight,
@ -290,7 +290,7 @@ public class ProjectiveTransformBuilder
/// <param name="bottomLeft">The bottom-left corner point of the distorted quad.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
public ProjectiveTransformBuilder AppendQuadDistortion(PointF topLeft, PointF topRight, PointF bottomRight, PointF bottomLeft)
=> this.Append(size => TransformUtils.CreateQuadDistortionMatrix(
=> this.Append(size => TransformUtilities.CreateQuadDistortionMatrix(
new Rectangle(Point.Empty, size),
topLeft,
topRight,
@ -395,11 +395,11 @@ public class ProjectiveTransformBuilder
/// </exception>
/// <returns>The <see cref="Size"/>.</returns>
internal static SizeF GetTransformedSize(Rectangle sourceRectangle, Matrix4x4 matrix)
=> TransformUtils.GetRawTransformedSize(matrix, sourceRectangle.Size);
=> TransformUtilities.GetRawTransformedSize(matrix, sourceRectangle.Size);
private static void CheckDegenerate(Matrix4x4 matrix)
{
if (TransformUtils.IsDegenerate(matrix))
if (TransformUtilities.IsDegenerate(matrix))
{
throw new DegenerateTransformException("Matrix is degenerate. Check input values.");
}

4
tests/ImageSharp.Tests/Processing/Transforms/TransformBuilderTestBase.cs

@ -98,7 +98,7 @@ public abstract class TransformBuilderTestBase<TBuilder>
this.AppendRotationDegrees(builder, degrees);
// TODO: We should also test CreateRotationMatrixDegrees() (and all TransformUtils stuff!) for correctness
Matrix3x2 matrix = TransformUtils.CreateRotationTransformMatrixDegrees(degrees, size);
Matrix3x2 matrix = TransformUtilities.CreateRotationTransformMatrixDegrees(degrees, size);
Vector2 position = new(x, y);
Vector2 expected = Vector2.Transform(position, matrix);
@ -152,7 +152,7 @@ public abstract class TransformBuilderTestBase<TBuilder>
this.AppendSkewDegrees(builder, degreesX, degreesY);
Matrix3x2 matrix = TransformUtils.CreateSkewTransformMatrixDegrees(degreesX, degreesY, size);
Matrix3x2 matrix = TransformUtilities.CreateSkewTransformMatrixDegrees(degreesX, degreesY, size);
Vector2 position = new(x, y);
Vector2 expected = Vector2.Transform(position, matrix);

2
tests/ImageSharp.Tests/TestImages.cs

@ -163,7 +163,7 @@ public static class TestImages
// Issue 2924: https://github.com/SixLabors/ImageSharp/issues/2924
public const string Issue2924 = "Png/issues/Issue_2924.png";
// Issue 3000: htps://github.com/SixLabors/ImageSharp/issues/3000
// Issue 3000: https://github.com/SixLabors/ImageSharp/issues/3000
public const string Issue3000 = "Png/issues/issue_3000.png";
public static class Bad

Loading…
Cancel
Save