Skip to content

Commit

Permalink
Moved Morphology to IMagickImageCreateOperations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Dec 21, 2024
1 parent fb84acd commit 97a246c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
7 changes: 0 additions & 7 deletions src/Magick.NET.Core/IMagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,13 +1355,6 @@ public partial interface IMagickImage : IMagickImageCreateOperations, IDisposabl
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Modulate(Percentage brightness, Percentage saturation, Percentage hue);

/// <summary>
/// Applies a kernel to the image according to the given mophology settings.
/// </summary>
/// <param name="settings">The morphology settings.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Morphology(IMorphologySettings settings);

/// <summary>
/// Returns the normalized moments of one or more image channels.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Magick.NET.Core/IMagickImageCreateOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,13 @@ public interface IMagickImageCreateOperations
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Minify();

/// <summary>
/// Applies a kernel to the image according to the given mophology settings.
/// </summary>
/// <param name="settings">The morphology settings.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Morphology(IMorphologySettings settings);

/// <summary>
/// Resize image to specified size.
/// <para />
Expand Down
26 changes: 23 additions & 3 deletions src/Magick.NET/MagickImage.CloneMutator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ public void LiquidRescale(Percentage percentage)
public void LiquidRescale(Percentage percentageWidth, Percentage percentageHeight)
=> LiquidRescale(new MagickGeometry(percentageWidth, percentageHeight));

public void LiquidRescale(Percentage percentageWidth, Percentage percentageHeight, double deltaX, double rigidity)
{
var geometry = new MagickGeometry(percentageWidth, percentageHeight);

SetResult(NativeMagickImage.LiquidRescale(geometry.ToString(), deltaX, rigidity));
}

public void Magnify()
=> SetResult(NativeMagickImage.Magnify());

Expand All @@ -401,11 +408,24 @@ public void MeanShift(uint width, uint height, Percentage colorDistance)
public void Minify()
=> SetResult(NativeMagickImage.Minify());

public void LiquidRescale(Percentage percentageWidth, Percentage percentageHeight, double deltaX, double rigidity)
public void Morphology(IMorphologySettings settings)
{
var geometry = new MagickGeometry(percentageWidth, percentageHeight);
Throw.IfNull(nameof(settings), settings);
Throw.IfTrue(nameof(settings), settings.Iterations < -1, "The number of iterations must be unlimited (-1) or positive");

SetResult(NativeMagickImage.LiquidRescale(geometry.ToString(), deltaX, rigidity));
using var temporaryDefines = new TemporaryDefines(NativeMagickImage);
temporaryDefines.SetArtifact("convolve:bias", settings.ConvolveBias);
temporaryDefines.SetArtifact("convolve:scale", settings.ConvolveScale);

if (settings.UserKernel is not null && settings.UserKernel.Length > 0)
{
SetResult(NativeMagickImage.Morphology(settings.Method, settings.UserKernel, settings.Channels, settings.Iterations));
}
else
{
var kernel = EnumHelper.GetName(settings.Kernel).ToLowerInvariant() + ":" + settings.KernelArguments;
SetResult(NativeMagickImage.Morphology(settings.Method, kernel, settings.Channels, settings.Iterations));
}
}

public void Resize(uint width, uint height)
Expand Down
18 changes: 2 additions & 16 deletions src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4193,22 +4193,8 @@ public void Modulate(Percentage brightness, Percentage saturation, Percentage hu
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void Morphology(IMorphologySettings settings)
{
Throw.IfNull(nameof(settings), settings);
Throw.IfTrue(nameof(settings), settings.Iterations < -1, "The number of iterations must be unlimited (-1) or positive");

using var temporaryDefines = new TemporaryDefines(this);
temporaryDefines.SetArtifact("convolve:bias", settings.ConvolveBias);
temporaryDefines.SetArtifact("convolve:scale", settings.ConvolveScale);

if (settings.UserKernel is not null && settings.UserKernel.Length > 0)
{
_nativeInstance.Morphology(settings.Method, settings.UserKernel, settings.Channels, settings.Iterations);
}
else
{
var kernel = EnumHelper.GetName(settings.Kernel).ToLowerInvariant() + ":" + settings.KernelArguments;
_nativeInstance.Morphology(settings.Method, kernel, settings.Channels, settings.Iterations);
}
using var mutator = new Mutator(_nativeInstance);
mutator.Morphology(settings);
}

/// <summary>
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 @@ -537,8 +537,7 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeM
public partial IntPtr MinimumBoundingBox(out nuint length);

[Throws]
[SetInstance]
public partial void Morphology(MorphologyMethod method, string kernel, Channels channels, nint iterations);
public partial IntPtr Morphology(MorphologyMethod method, string kernel, Channels channels, nint iterations);

[Throws]
[SetInstance]
Expand Down

0 comments on commit 97a246c

Please sign in to comment.