Constrain Image processing operations to clip bounds.

Merged
JI
8mo ago
+56-26

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 matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules :cop:.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #375

This pull request refines the clipping implementation in ImageSharp.Drawing to more precisely constrain image processing operations to the bounds of the clipping path. The changes improve both the internal logic and documentation, and add a new test to verify correct behavior.

Clipping logic enhancements:

  • Modified ClipPathProcessor{TPixel}.cs to conservatively cover shape bounds using floating-point calculations, crop the operation to the intersection of the requested bounds and source region, and ensure that only pixels inside the clip are affected. The clone used for the brush is now created from the clipped context, and offsets are calculated to keep the effect confined to the clipped region.

Documentation improvements:

  • Updated the XML comments in ClipPathExtensions.cs to clarify that only pixels inside the clip region are affected by the operation, and that the operation executes in a clipped context.
  • Revised the class summary in ClipPathProcessor{TPixel}.cs to describe how the operation is constrained to the path bounds and that the processed result is used as an image brush.

Testing:

  • Added a new unit test Clip_ConstrainsOperationToClipBounds in ClipTests.cs to verify that the operation is properly constrained to the clip bounds.
  • Included a reference output file for the new test to validate the result.