Skip to content

Commit

Permalink
Moved Chop to IMagickImageCreateOperations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Nov 11, 2024
1 parent 340502d commit 8f25f14
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 30 deletions.
23 changes: 0 additions & 23 deletions src/Magick.NET.Core/IMagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,29 +369,6 @@ public partial interface IMagickImage : IMagickImageCreateOperations, IDisposabl
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void BrightnessContrast(Percentage brightness, Percentage contrast, Channels channels);

/// <summary>
/// Chop image (remove vertical or horizontal subregion of image) using the specified geometry.
/// </summary>
/// <param name="geometry">The geometry to use.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Chop(IMagickGeometry geometry);

/// <summary>
/// Chop image (remove horizontal subregion of image).
/// </summary>
/// <param name="offset">The X offset from origin.</param>
/// <param name="width">The width of the part to chop horizontally.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void ChopHorizontal(int offset, uint width);

/// <summary>
/// Chop image (remove horizontal subregion of image).
/// </summary>
/// <param name="offset">The Y offset from origin.</param>
/// <param name="height">The height of the part to chop vertically.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void ChopVertical(int offset, uint height);

/// <summary>
/// A variant of adaptive histogram equalization in which the contrast amplification is limited,
/// so as to reduce this problem of noise amplification.
Expand Down
23 changes: 23 additions & 0 deletions src/Magick.NET.Core/IMagickImageCreateOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,29 @@ public interface IMagickImageCreateOperations
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Charcoal(double radius, double sigma);

/// <summary>
/// Chop image (remove vertical or horizontal subregion of image) using the specified geometry.
/// </summary>
/// <param name="geometry">The geometry to use.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Chop(IMagickGeometry geometry);

/// <summary>
/// Chop image (remove horizontal subregion of image).
/// </summary>
/// <param name="offset">The X offset from origin.</param>
/// <param name="width">The width of the part to chop horizontally.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void ChopHorizontal(int offset, uint width);

/// <summary>
/// Chop image (remove horizontal subregion of image).
/// </summary>
/// <param name="offset">The Y offset from origin.</param>
/// <param name="height">The height of the part to chop vertically.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void ChopVertical(int offset, uint height);

/// <summary>
/// Resize image to specified size.
/// <para />
Expand Down
9 changes: 9 additions & 0 deletions src/Magick.NET/MagickImage.CloneMutator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
15 changes: 12 additions & 3 deletions src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,10 @@ public void Charcoal(double radius, double sigma)
/// <param name="geometry">The geometry to use.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void Chop(IMagickGeometry geometry)
=> _nativeInstance.Chop(MagickRectangle.FromGeometry(geometry, this));
{
using var mutator = new Mutator(_nativeInstance);
mutator.Chop(geometry);
}

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

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

/// <summary>
/// A variant of adaptive histogram equalization in which the contrast amplification is limited,
Expand Down
3 changes: 1 addition & 2 deletions src/Magick.NET/Native/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/Magick.NET/Types/MagickRectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 8f25f14

Please sign in to comment.