Skip to content

Add sk_imagefilter_new_crop C API#261

Merged
mattleibow merged 1 commit into
skiasharpfrom
dev/issue-3938-imagefilter-crop
Jun 24, 2026
Merged

Add sk_imagefilter_new_crop C API#261
mattleibow merged 1 commit into
skiasharpfrom
dev/issue-3938-imagefilter-crop

Conversation

@mattleibow

Copy link
Copy Markdown
Collaborator

Wraps SkImageFilters::Crop(const SkRect& rect, SkTileMode tileMode, sk_sp input).

This is the modern replacement for the deprecated cropRect parameter pattern on individual filters.

Fixes mono/SkiaSharp#3938

Changes

  • Added sk_imagefilter_new_crop to sk_imagefilter.h
  • Implemented wrapper in sk_imagefilter.cpp

Testing

Tested in mono/SkiaSharp#TBD with comprehensive C# tests.

Wraps SkImageFilters::Crop(const SkRect& rect, SkTileMode tileMode, sk_sp<SkImageFilter> input).
This is the modern replacement for the deprecated cropRect parameter pattern on individual filters.

Fixes #3938

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mattleibow mattleibow force-pushed the dev/issue-3938-imagefilter-crop branch from 8e301ae to ce2dc98 Compare June 24, 2026 21:45
mattleibow added a commit to mono/SkiaSharp that referenced this pull request Jun 24, 2026
Wraps Skia's modern SkImageFilters::Crop(rect, tileMode, input), the
replacement for the deprecated cropRect parameter pattern on individual
filters. Crop restricts an image filter's output to a rectangle using a
tile mode for the area outside the rect.

Changes:
- C API: sk_imagefilter_new_crop in the skia submodule (mono/skia#261),
  rebased onto main's skia which includes CreateEmpty (#260) + m150 fixes.
- C# wrapper: three CreateCrop overloads (no default parameters) -
  (rect), (rect, tileMode), (rect, tileMode, input) - with GC.KeepAlive.
- Regenerated SkiaApi.generated.cs P/Invoke binding.
- Tests validating non-null, null input, blur composition, pixel-level
  Decal crop rendering, and Decal-vs-Clamp behavioral differences.
- ImageFilterCropSample gallery demo with enable toggle, crop sliders,
  tile mode picker, blur composition, and an aligned crop-rect outline.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mattleibow mattleibow merged commit 214e2d2 into skiasharp Jun 24, 2026
1 check passed
@mattleibow mattleibow deleted the dev/issue-3938-imagefilter-crop branch June 24, 2026 22:51
mattleibow added a commit to mono/SkiaSharp that referenced this pull request Jun 24, 2026
Wraps Skia's modern SkImageFilters::Crop(rect, tileMode, input), the
replacement for the deprecated cropRect parameter pattern on individual
filters. Crop restricts an image filter's output to a rectangle using a
tile mode for the area outside the rect.

Changes:
- C API: sk_imagefilter_new_crop in the skia submodule (mono/skia#261),
  rebased onto main's skia which includes CreateEmpty (#260) + m150 fixes.
- C# wrapper: three CreateCrop overloads (no default parameters) -
  (rect), (rect, tileMode), (rect, tileMode, input) - with GC.KeepAlive.
- Regenerated SkiaApi.generated.cs P/Invoke binding.
- Tests validating non-null, null input, blur composition, pixel-level
  Decal crop rendering, and Decal-vs-Clamp behavioral differences.
- ImageFilterCropSample gallery demo with enable toggle, crop sliders,
  tile mode picker, blur composition, and an aligned crop-rect outline.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mattleibow added a commit to mono/SkiaSharp that referenced this pull request Jun 25, 2026
Add SKImageFilter.CreateCrop() (#4229)

Closes: #3938
Requires: mono/skia#261

Exposes SkImageFilters::Crop as SKImageFilter.CreateCrop(), the modern
replacement for the deprecated per-filter `cropRect` pattern. Crop restricts
an image filter's output to a rectangle using a tile mode, and composes with
other filters (e.g. blur then crop) instead of every filter carrying its own
crop argument.

Add three ABI-safe overloads (no default parameters):

  * CreateCrop(SKRect)                                  - defaults to Decal
  * CreateCrop(SKRect, SKShaderTileMode)                - null input (source)
  * CreateCrop(SKRect, SKShaderTileMode, SKImageFilter?) - full control

The full overload calls sk_imagefilter_new_crop and uses GC.KeepAlive on the
input filter to keep it alive across the native call. A null input maps to
IntPtr.Zero, which Skia interprets as the source image.

  * binding/SkiaSharp/SKImageFilter.cs       - the three CreateCrop overloads
  * binding/SkiaSharp/SkiaApi.generated.cs   - regenerated P/Invoke binding
  * externals/skia                           - bump to pick up mono/skia#261

Tests in SKImageFilterTest.cs go beyond non-null checks and verify behavior:
null input is accepted, Crop composes with CreateBlur, Decal leaves pixels
outside the crop transparent while Clamp produces a different (edge-extended)
result, and a rendering test confirms pixels inside the rect are drawn and
those outside are cropped away.

ImageFilterCropSample.cs adds an interactive gallery demo with crop bounds
sliders, a tile-mode picker, an "Enable Crop" toggle, and an optional blur
composition, drawing the crop rect as an overlay so the effect is visible.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[api] Add SKImageFilter.CreateCrop()

1 participant