Skip to content

Comments

Constrain Image processing operations to clip bounds.#376

Open
JimBobSquarePants wants to merge 3 commits intomainfrom
js/clip-path-enhancements
Open

Constrain Image processing operations to clip bounds.#376
JimBobSquarePants wants to merge 3 commits intomainfrom
js/clip-path-enhancements

Conversation

@JimBobSquarePants
Copy link
Member

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 👮.
  • 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.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84%. Comparing base (46b1688) to head (a7eaa1b).

Files with missing lines Patch % Lines
...ng/Processors/Drawing/ClipPathProcessor{TPixel}.cs 88% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@         Coverage Diff         @@
##           main   #376   +/-   ##
===================================
- Coverage    85%    84%   -1%     
===================================
  Files       101    101           
  Lines      4523   4529    +6     
  Branches    655    654    -1     
===================================
+ Hits       3845   3849    +4     
- Misses      539    540    +1     
- Partials    139    140    +1     
Flag Coverage Δ
unittests 84% <88%> (-1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes issue #375 by constraining image processing operations within clipped regions to only use pixels from inside the clip bounds. Previously, operations like Flip would use the entire image as input while restricting output to the clip region, causing incorrect results. The fix crops the image to the clip bounds before applying operations, then uses the processed result as a brush to fill the clipped path.

Changes:

  • Modified clipping logic to crop the source image to the clipped region before applying operations
  • Updated documentation to clarify that operations execute in a clipped context
  • Added test to verify operations are properly constrained to clip bounds

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/ImageSharp.Drawing/Processing/Processors/Drawing/ClipPathProcessor{TPixel}.cs Core logic changes to crop image to clip bounds before processing, calculate correct brush offsets, and apply processed result only within the clipped region
src/ImageSharp.Drawing/Processing/Extensions/ClipPathExtensions.cs Documentation updates clarifying that operations execute in a clipped context and only affect pixels inside the clip
tests/ImageSharp.Drawing.Tests/Drawing/ClipTests.cs New test that verifies flip operation within a clip region only affects pixels inside the clip bounds
tests/Images/ReferenceOutput/Drawing/ClipTests/Clip_ConstrainsOperationToClipBounds.png Reference output for the new test case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…rocessor{TPixel}.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using Clip + Flip seems to use the data outside of the clip region, how do I avoid that?

1 participant