From 8f25f14202ad079686621529c66481e02ba79a23 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Mon, 11 Nov 2024 21:25:08 +0100 Subject: [PATCH] Moved Chop to IMagickImageCreateOperations. --- src/Magick.NET.Core/IMagickImage.cs | 23 ------------------- .../IMagickImageCreateOperations.cs | 23 +++++++++++++++++++ src/Magick.NET/MagickImage.CloneMutator.cs | 9 ++++++++ src/Magick.NET/MagickImage.cs | 15 +++++++++--- src/Magick.NET/Native/MagickImage.cs | 3 +-- src/Magick.NET/Types/MagickRectangle.cs | 7 ++++-- 6 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/Magick.NET.Core/IMagickImage.cs b/src/Magick.NET.Core/IMagickImage.cs index e714f70009..5c1b591295 100644 --- a/src/Magick.NET.Core/IMagickImage.cs +++ b/src/Magick.NET.Core/IMagickImage.cs @@ -369,29 +369,6 @@ public partial interface IMagickImage : IMagickImageCreateOperations, IDisposabl /// Thrown when an error is raised by ImageMagick. void BrightnessContrast(Percentage brightness, Percentage contrast, Channels channels); - /// - /// Chop image (remove vertical or horizontal subregion of image) using the specified geometry. - /// - /// The geometry to use. - /// Thrown when an error is raised by ImageMagick. - void Chop(IMagickGeometry geometry); - - /// - /// Chop image (remove horizontal subregion of image). - /// - /// The X offset from origin. - /// The width of the part to chop horizontally. - /// Thrown when an error is raised by ImageMagick. - void ChopHorizontal(int offset, uint width); - - /// - /// Chop image (remove horizontal subregion of image). - /// - /// The Y offset from origin. - /// The height of the part to chop vertically. - /// Thrown when an error is raised by ImageMagick. - void ChopVertical(int offset, uint height); - /// /// A variant of adaptive histogram equalization in which the contrast amplification is limited, /// so as to reduce this problem of noise amplification. diff --git a/src/Magick.NET.Core/IMagickImageCreateOperations.cs b/src/Magick.NET.Core/IMagickImageCreateOperations.cs index fc89d9df07..131d2c247b 100644 --- a/src/Magick.NET.Core/IMagickImageCreateOperations.cs +++ b/src/Magick.NET.Core/IMagickImageCreateOperations.cs @@ -305,6 +305,29 @@ public interface IMagickImageCreateOperations /// Thrown when an error is raised by ImageMagick. void Charcoal(double radius, double sigma); + /// + /// Chop image (remove vertical or horizontal subregion of image) using the specified geometry. + /// + /// The geometry to use. + /// Thrown when an error is raised by ImageMagick. + void Chop(IMagickGeometry geometry); + + /// + /// Chop image (remove horizontal subregion of image). + /// + /// The X offset from origin. + /// The width of the part to chop horizontally. + /// Thrown when an error is raised by ImageMagick. + void ChopHorizontal(int offset, uint width); + + /// + /// Chop image (remove horizontal subregion of image). + /// + /// The Y offset from origin. + /// The height of the part to chop vertically. + /// Thrown when an error is raised by ImageMagick. + void ChopVertical(int offset, uint height); + /// /// Resize image to specified size. /// diff --git a/src/Magick.NET/MagickImage.CloneMutator.cs b/src/Magick.NET/MagickImage.CloneMutator.cs index ca232d6b2e..f0b1402dfb 100644 --- a/src/Magick.NET/MagickImage.CloneMutator.cs +++ b/src/Magick.NET/MagickImage.CloneMutator.cs @@ -153,6 +153,15 @@ public void Charcoal() public void Charcoal(double radius, double sigma) => SetResult(NativeMagickImage.Charcoal(radius, sigma)); + public void Chop(IMagickGeometry geometry) + => SetResult(NativeMagickImage.Chop(MagickRectangle.FromGeometry(geometry, (uint)NativeMagickImage.Width_Get(), (uint)NativeMagickImage.Height_Get()))); + + public void ChopHorizontal(int offset, uint width) + => Chop(new MagickGeometry(offset, 0, width, 0)); + + public void ChopVertical(int offset, uint height) + => Chop(new MagickGeometry(0, offset, 0, height)); + public void Resize(uint width, uint height) => Resize(new MagickGeometry(width, height)); diff --git a/src/Magick.NET/MagickImage.cs b/src/Magick.NET/MagickImage.cs index 182c4a3d77..d0d8d3697e 100644 --- a/src/Magick.NET/MagickImage.cs +++ b/src/Magick.NET/MagickImage.cs @@ -1487,7 +1487,10 @@ public void Charcoal(double radius, double sigma) /// The geometry to use. /// Thrown when an error is raised by ImageMagick. public void Chop(IMagickGeometry geometry) - => _nativeInstance.Chop(MagickRectangle.FromGeometry(geometry, this)); + { + using var mutator = new Mutator(_nativeInstance); + mutator.Chop(geometry); + } /// /// Chop image (remove horizontal subregion of image). @@ -1496,7 +1499,10 @@ public void Chop(IMagickGeometry geometry) /// The width of the part to chop horizontally. /// Thrown when an error is raised by ImageMagick. public void ChopHorizontal(int offset, uint width) - => Chop(new MagickGeometry(offset, 0, width, 0)); + { + using var mutator = new Mutator(_nativeInstance); + mutator.ChopHorizontal(offset, width); + } /// /// Chop image (remove horizontal subregion of image). @@ -1505,7 +1511,10 @@ public void ChopHorizontal(int offset, uint width) /// The height of the part to chop vertically. /// Thrown when an error is raised by ImageMagick. public void ChopVertical(int offset, uint height) - => Chop(new MagickGeometry(0, offset, 0, height)); + { + using var mutator = new Mutator(_nativeInstance); + mutator.ChopVertical(offset, height); + } /// /// A variant of adaptive histogram equalization in which the contrast amplification is limited, diff --git a/src/Magick.NET/Native/MagickImage.cs b/src/Magick.NET/Native/MagickImage.cs index 67b4f1be62..a9c097fc8f 100644 --- a/src/Magick.NET/Native/MagickImage.cs +++ b/src/Magick.NET/Native/MagickImage.cs @@ -289,8 +289,7 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeM public partial IntPtr Charcoal(double radius, double sigma); [Throws] - [SetInstance] - public partial void Chop(MagickRectangle geometry); + public partial IntPtr Chop(MagickRectangle geometry); [Throws] public partial void Clahe(nuint xTiles, nuint yTiles, nuint numberBins, double clipLimit); diff --git a/src/Magick.NET/Types/MagickRectangle.cs b/src/Magick.NET/Types/MagickRectangle.cs index 882fb07fb6..024505cdc9 100644 --- a/src/Magick.NET/Types/MagickRectangle.cs +++ b/src/Magick.NET/Types/MagickRectangle.cs @@ -35,6 +35,9 @@ private MagickRectangle(NativeMagickRectangle instance) => NativeMagickRectangle.FromPageSize(pageSize); public static MagickRectangle FromGeometry(IMagickGeometry geometry, MagickImage image) + => FromGeometry(geometry, image.Width, image.Height); + + public static MagickRectangle FromGeometry(IMagickGeometry geometry, uint imageWidth, uint imageHeight) { Throw.IfNull(nameof(geometry), geometry); @@ -43,8 +46,8 @@ public static MagickRectangle FromGeometry(IMagickGeometry geometry, MagickImage if (geometry.IsPercentage) { - width = (uint)(image.Width * new Percentage(geometry.Width)); - height = (uint)(image.Height * new Percentage(geometry.Height)); + width = (uint)(imageWidth * new Percentage(geometry.Width)); + height = (uint)(imageHeight * new Percentage(geometry.Height)); } return new MagickRectangle(geometry.X, geometry.Y, width, height);