Constrain Image processing operations to clip bounds.#376
Constrain Image processing operations to clip bounds.#376JimBobSquarePants wants to merge 3 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.
src/ImageSharp.Drawing/Processing/Processors/Drawing/ClipPathProcessor{TPixel}.cs
Outdated
Show resolved
Hide resolved
…rocessor{TPixel}.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Prerequisites
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:
ClipPathProcessor{TPixel}.csto 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:
ClipPathExtensions.csto clarify that only pixels inside the clip region are affected by the operation, and that the operation executes in a clipped context.ClipPathProcessor{TPixel}.csto describe how the operation is constrained to the path bounds and that the processed result is used as an image brush.Testing:
Clip_ConstrainsOperationToClipBoundsinClipTests.csto verify that the operation is properly constrained to the clip bounds.