Skip to content

Conversation

@JimBobSquarePants
Copy link
Member

@JimBobSquarePants JimBobSquarePants commented Nov 13, 2025

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

A proper fix for #2753 and #3000

See #3000 (comment) for the explanation of the theory.

This pull request refactors several transformation and primitive classes to improve consistency, performance, and accuracy in image processing operations. The main changes include making value type members and methods readonly for better immutability and optimization, removing unnecessary parameters related to transform space, and updating transformation logic to ensure correct coordinate space handling and more accurate results.

Transformation Logic and API Simplification

  • Removed the TransformSpace parameter and related properties from AffineTransformBuilder and transformation utility methods, simplifying the API and ensuring all transformations are consistently defined in pixel space. (src/ImageSharp/Processing/AffineTransformBuilder.cs [1] [2] [3] [4] [5] [6] [7]
  • Updated transformation processors (RotateProcessor, SkewProcessor, AffineTransformProcessor, ProjectiveTransformProcessor) to use new utility methods for canvas size calculation and matrix normalization, ensuring correct sampling and output dimensions. (src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor.cs [1] src/ImageSharp/Processing/Processors/Transforms/Linear/SkewProcessor.cs [2] [3] src/ImageSharp/Processing/Processors/Transforms/Linear/AffineTransformProcessor{TPixel}.cs [4] src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs [5]
  • Changed extension methods to use the new canvas size calculation for transformed images, improving output accuracy. (src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs [1] [2]

Value Type Improvements

  • Made properties and methods in Point, PointF, and SizeF structs readonly, which improves performance and thread safety by preventing modification of struct instances. (src/ImageSharp/Primitives/Point.cs [1] [2] [3] src/ImageSharp/Primitives/PointF.cs [4] [5] [6] src/ImageSharp/Primitives/SizeF.cs [7] [8]

Rectangle and Area Transformation Accuracy

  • Improved subject area transformation in ExifProfile.SyncSubject by switching from integer to floating-point rectangles for more accurate bounds calculation, and using MathF.Floor/MathF.Ceiling for coordinate rounding. (src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.cs src/ImageSharp/Metadata/Profiles/Exif/ExifProfile.csL343-R354)

Documentation and Naming Consistency

Internal Utility Refactoring

@JimBobSquarePants JimBobSquarePants added bug area:transforms breaking Signifies a binary breaking change. labels Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:transforms breaking Signifies a binary breaking change. bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rotation of AffineTransform with TransformSpace.Coordinate is off by 1 pixel

2 participants