Skip to content

Commit 8f25f14

Browse files
committed
Moved Chop to IMagickImageCreateOperations.
1 parent 340502d commit 8f25f14

File tree

6 files changed

+50
-30
lines changed

6 files changed

+50
-30
lines changed

src/Magick.NET.Core/IMagickImage.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -369,29 +369,6 @@ public partial interface IMagickImage : IMagickImageCreateOperations, IDisposabl
369369
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
370370
void BrightnessContrast(Percentage brightness, Percentage contrast, Channels channels);
371371

372-
/// <summary>
373-
/// Chop image (remove vertical or horizontal subregion of image) using the specified geometry.
374-
/// </summary>
375-
/// <param name="geometry">The geometry to use.</param>
376-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
377-
void Chop(IMagickGeometry geometry);
378-
379-
/// <summary>
380-
/// Chop image (remove horizontal subregion of image).
381-
/// </summary>
382-
/// <param name="offset">The X offset from origin.</param>
383-
/// <param name="width">The width of the part to chop horizontally.</param>
384-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
385-
void ChopHorizontal(int offset, uint width);
386-
387-
/// <summary>
388-
/// Chop image (remove horizontal subregion of image).
389-
/// </summary>
390-
/// <param name="offset">The Y offset from origin.</param>
391-
/// <param name="height">The height of the part to chop vertically.</param>
392-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
393-
void ChopVertical(int offset, uint height);
394-
395372
/// <summary>
396373
/// A variant of adaptive histogram equalization in which the contrast amplification is limited,
397374
/// so as to reduce this problem of noise amplification.

src/Magick.NET.Core/IMagickImageCreateOperations.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,29 @@ public interface IMagickImageCreateOperations
305305
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
306306
void Charcoal(double radius, double sigma);
307307

308+
/// <summary>
309+
/// Chop image (remove vertical or horizontal subregion of image) using the specified geometry.
310+
/// </summary>
311+
/// <param name="geometry">The geometry to use.</param>
312+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
313+
void Chop(IMagickGeometry geometry);
314+
315+
/// <summary>
316+
/// Chop image (remove horizontal subregion of image).
317+
/// </summary>
318+
/// <param name="offset">The X offset from origin.</param>
319+
/// <param name="width">The width of the part to chop horizontally.</param>
320+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
321+
void ChopHorizontal(int offset, uint width);
322+
323+
/// <summary>
324+
/// Chop image (remove horizontal subregion of image).
325+
/// </summary>
326+
/// <param name="offset">The Y offset from origin.</param>
327+
/// <param name="height">The height of the part to chop vertically.</param>
328+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
329+
void ChopVertical(int offset, uint height);
330+
308331
/// <summary>
309332
/// Resize image to specified size.
310333
/// <para />

src/Magick.NET/MagickImage.CloneMutator.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ public void Charcoal()
153153
public void Charcoal(double radius, double sigma)
154154
=> SetResult(NativeMagickImage.Charcoal(radius, sigma));
155155

156+
public void Chop(IMagickGeometry geometry)
157+
=> SetResult(NativeMagickImage.Chop(MagickRectangle.FromGeometry(geometry, (uint)NativeMagickImage.Width_Get(), (uint)NativeMagickImage.Height_Get())));
158+
159+
public void ChopHorizontal(int offset, uint width)
160+
=> Chop(new MagickGeometry(offset, 0, width, 0));
161+
162+
public void ChopVertical(int offset, uint height)
163+
=> Chop(new MagickGeometry(0, offset, 0, height));
164+
156165
public void Resize(uint width, uint height)
157166
=> Resize(new MagickGeometry(width, height));
158167

src/Magick.NET/MagickImage.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,10 @@ public void Charcoal(double radius, double sigma)
14871487
/// <param name="geometry">The geometry to use.</param>
14881488
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
14891489
public void Chop(IMagickGeometry geometry)
1490-
=> _nativeInstance.Chop(MagickRectangle.FromGeometry(geometry, this));
1490+
{
1491+
using var mutator = new Mutator(_nativeInstance);
1492+
mutator.Chop(geometry);
1493+
}
14911494

14921495
/// <summary>
14931496
/// Chop image (remove horizontal subregion of image).
@@ -1496,7 +1499,10 @@ public void Chop(IMagickGeometry geometry)
14961499
/// <param name="width">The width of the part to chop horizontally.</param>
14971500
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
14981501
public void ChopHorizontal(int offset, uint width)
1499-
=> Chop(new MagickGeometry(offset, 0, width, 0));
1502+
{
1503+
using var mutator = new Mutator(_nativeInstance);
1504+
mutator.ChopHorizontal(offset, width);
1505+
}
15001506

15011507
/// <summary>
15021508
/// Chop image (remove horizontal subregion of image).
@@ -1505,7 +1511,10 @@ public void ChopHorizontal(int offset, uint width)
15051511
/// <param name="height">The height of the part to chop vertically.</param>
15061512
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
15071513
public void ChopVertical(int offset, uint height)
1508-
=> Chop(new MagickGeometry(0, offset, 0, height));
1514+
{
1515+
using var mutator = new Mutator(_nativeInstance);
1516+
mutator.ChopVertical(offset, height);
1517+
}
15091518

15101519
/// <summary>
15111520
/// A variant of adaptive histogram equalization in which the contrast amplification is limited,

src/Magick.NET/Native/MagickImage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeM
289289
public partial IntPtr Charcoal(double radius, double sigma);
290290

291291
[Throws]
292-
[SetInstance]
293-
public partial void Chop(MagickRectangle geometry);
292+
public partial IntPtr Chop(MagickRectangle geometry);
294293

295294
[Throws]
296295
public partial void Clahe(nuint xTiles, nuint yTiles, nuint numberBins, double clipLimit);

src/Magick.NET/Types/MagickRectangle.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ private MagickRectangle(NativeMagickRectangle instance)
3535
=> NativeMagickRectangle.FromPageSize(pageSize);
3636

3737
public static MagickRectangle FromGeometry(IMagickGeometry geometry, MagickImage image)
38+
=> FromGeometry(geometry, image.Width, image.Height);
39+
40+
public static MagickRectangle FromGeometry(IMagickGeometry geometry, uint imageWidth, uint imageHeight)
3841
{
3942
Throw.IfNull(nameof(geometry), geometry);
4043

@@ -43,8 +46,8 @@ public static MagickRectangle FromGeometry(IMagickGeometry geometry, MagickImage
4346

4447
if (geometry.IsPercentage)
4548
{
46-
width = (uint)(image.Width * new Percentage(geometry.Width));
47-
height = (uint)(image.Height * new Percentage(geometry.Height));
49+
width = (uint)(imageWidth * new Percentage(geometry.Width));
50+
height = (uint)(imageHeight * new Percentage(geometry.Height));
4851
}
4952

5053
return new MagickRectangle(geometry.X, geometry.Y, width, height);

0 commit comments

Comments
 (0)