Skip to content

Commit

Permalink
Added channel overloads for AdaptiveThreshold and Threshold.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Oct 22, 2019
1 parent 6091ba8 commit bd48f14
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/Magick.NET/Native/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static class X64
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickImage_AdaptiveSharpen(IntPtr Instance, double radius, double sigma, UIntPtr channels, out IntPtr exception);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickImage_AdaptiveThreshold(IntPtr Instance, UIntPtr width, UIntPtr height, double bias, out IntPtr exception);
public static extern IntPtr MagickImage_AdaptiveThreshold(IntPtr Instance, UIntPtr width, UIntPtr height, double bias, UIntPtr channels, out IntPtr exception);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickImage_AddNoise(IntPtr Instance, UIntPtr noiseType, double attenuate, UIntPtr channels, out IntPtr exception);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -560,7 +560,7 @@ public static class X64
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickImage_Texture(IntPtr Instance, IntPtr image, out IntPtr exception);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickImage_Threshold(IntPtr Instance, double threshold, out IntPtr exception);
public static extern void MagickImage_Threshold(IntPtr Instance, double threshold, UIntPtr channels, out IntPtr exception);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickImage_Thumbnail(IntPtr Instance, IntPtr geometry, out IntPtr exception);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -779,7 +779,7 @@ public static class X86
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickImage_AdaptiveSharpen(IntPtr Instance, double radius, double sigma, UIntPtr channels, out IntPtr exception);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickImage_AdaptiveThreshold(IntPtr Instance, UIntPtr width, UIntPtr height, double bias, out IntPtr exception);
public static extern IntPtr MagickImage_AdaptiveThreshold(IntPtr Instance, UIntPtr width, UIntPtr height, double bias, UIntPtr channels, out IntPtr exception);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickImage_AddNoise(IntPtr Instance, UIntPtr noiseType, double attenuate, UIntPtr channels, out IntPtr exception);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -1110,7 +1110,7 @@ public static class X86
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickImage_Texture(IntPtr Instance, IntPtr image, out IntPtr exception);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickImage_Threshold(IntPtr Instance, double threshold, out IntPtr exception);
public static extern void MagickImage_Threshold(IntPtr Instance, double threshold, UIntPtr channels, out IntPtr exception);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickImage_Thumbnail(IntPtr Instance, IntPtr geometry, out IntPtr exception);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -2810,21 +2810,21 @@ public void AdaptiveSharpen(double radius, double sigma, Channels channels)
CheckException(exception, result);
Instance = result;
}
public void AdaptiveThreshold(int width, int height, double bias)
public void AdaptiveThreshold(int width, int height, double bias, Channels channels)
{
IntPtr exception = IntPtr.Zero;
IntPtr result;
#if PLATFORM_AnyCPU
if (NativeLibrary.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
result = NativeMethods.X64.MagickImage_AdaptiveThreshold(Instance, (UIntPtr)width, (UIntPtr)height, bias, out exception);
result = NativeMethods.X64.MagickImage_AdaptiveThreshold(Instance, (UIntPtr)width, (UIntPtr)height, bias, (UIntPtr)channels, out exception);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
result = NativeMethods.X86.MagickImage_AdaptiveThreshold(Instance, (UIntPtr)width, (UIntPtr)height, bias, out exception);
result = NativeMethods.X86.MagickImage_AdaptiveThreshold(Instance, (UIntPtr)width, (UIntPtr)height, bias, (UIntPtr)channels, out exception);
#endif
CheckException(exception, result);
Instance = result;
Expand Down Expand Up @@ -5948,20 +5948,20 @@ public void Texture(IMagickImage image)
#endif
CheckException(exception);
}
public void Threshold(double threshold)
public void Threshold(double threshold, Channels channels)
{
IntPtr exception = IntPtr.Zero;
#if PLATFORM_AnyCPU
if (NativeLibrary.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
NativeMethods.X64.MagickImage_Threshold(Instance, threshold, out exception);
NativeMethods.X64.MagickImage_Threshold(Instance, threshold, (UIntPtr)channels, out exception);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
NativeMethods.X86.MagickImage_Threshold(Instance, threshold, out exception);
NativeMethods.X86.MagickImage_Threshold(Instance, threshold, (UIntPtr)channels, out exception);
#endif
CheckException(exception);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Magick.NET/Native/MagickImage.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@
{
"name": "bias",
"type": "double"
},
{
"name": "channels",
"type": "Channels"
}
]
},
Expand Down Expand Up @@ -2615,6 +2619,10 @@
{
"name": "threshold",
"type": "double"
},
{
"name": "channels",
"type": "Channels"
}
]
},
Expand Down
32 changes: 32 additions & 0 deletions src/Magick.NET/Shared/IMagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ public partial interface IMagickImage : IEquatable<IMagickImage>, IComparable<IM
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void AdaptiveThreshold(int width, int height);

/// <summary>
/// Local adaptive threshold image.
/// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
/// </summary>
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <param name="channels">The channel(s) that should be thresholded.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void AdaptiveThreshold(int width, int height, Channels channels);

/// <summary>
/// Local adaptive threshold image.
/// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
Expand All @@ -417,6 +427,17 @@ public partial interface IMagickImage : IEquatable<IMagickImage>, IComparable<IM
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void AdaptiveThreshold(int width, int height, double bias);

/// <summary>
/// Local adaptive threshold image.
/// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
/// </summary>
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <param name="bias">Constant to subtract from pixel neighborhood mean (+/-)(0-QuantumRange).</param>
/// <param name="channels">The channel(s) that should be thresholded.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void AdaptiveThreshold(int width, int height, double bias, Channels channels);

/// <summary>
/// Local adaptive threshold image.
/// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
Expand All @@ -427,6 +448,17 @@ public partial interface IMagickImage : IEquatable<IMagickImage>, IComparable<IM
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void AdaptiveThreshold(int width, int height, Percentage biasPercentage);

/// <summary>
/// Local adaptive threshold image.
/// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
/// </summary>
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <param name="biasPercentage">Constant to subtract from pixel neighborhood mean.</param>
/// <param name="channels">The channel(s) that should be thresholded.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void AdaptiveThreshold(int width, int height, Percentage biasPercentage, Channels channels);

/// <summary>
/// Add noise to image with the specified noise type.
/// </summary>
Expand Down
48 changes: 44 additions & 4 deletions src/Magick.NET/Shared/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,27 @@ public void AdaptiveResize(MagickGeometry geometry)
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void AdaptiveThreshold(int width, int height) => AdaptiveThreshold(width, height, 0);
public void AdaptiveThreshold(int width, int height) => AdaptiveThreshold(width, height, 0, ImageMagick.Channels.All);

/// <summary>
/// Local adaptive threshold image.
/// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
/// </summary>
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <param name="channels">The channel(s) that should be thresholded.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void AdaptiveThreshold(int width, int height, Channels channels) => AdaptiveThreshold(width, height, 0, channels);

/// <summary>
/// Local adaptive threshold image.
/// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
/// </summary>
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <param name="bias">Constant to subtract from pixel neighborhood mean (+/-)(0-QuantumRange).</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void AdaptiveThreshold(int width, int height, double bias) => AdaptiveThreshold(width, height, bias, ImageMagick.Channels.All);

/// <summary>
/// Local adaptive threshold image.
Expand All @@ -1031,8 +1051,19 @@ public void AdaptiveResize(MagickGeometry geometry)
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <param name="bias">Constant to subtract from pixel neighborhood mean (+/-)(0-QuantumRange).</param>
/// <param name="channels">The channel(s) that should be thresholded.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void AdaptiveThreshold(int width, int height, double bias, Channels channels) => _nativeInstance.AdaptiveThreshold(width, height, bias, channels);

/// <summary>
/// Local adaptive threshold image.
/// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
/// </summary>
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <param name="biasPercentage">Constant to subtract from pixel neighborhood mean.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void AdaptiveThreshold(int width, int height, double bias) => _nativeInstance.AdaptiveThreshold(width, height, bias);
public void AdaptiveThreshold(int width, int height, Percentage biasPercentage) => AdaptiveThreshold(width, height, biasPercentage.ToQuantum(), ImageMagick.Channels.All);

/// <summary>
/// Local adaptive threshold image.
Expand All @@ -1041,8 +1072,9 @@ public void AdaptiveResize(MagickGeometry geometry)
/// <param name="width">The width of the pixel neighborhood.</param>
/// <param name="height">The height of the pixel neighborhood.</param>
/// <param name="biasPercentage">Constant to subtract from pixel neighborhood mean.</param>
/// <param name="channels">The channel(s) that should be thresholded.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void AdaptiveThreshold(int width, int height, Percentage biasPercentage) => AdaptiveThreshold(width, height, biasPercentage.ToQuantum());
public void AdaptiveThreshold(int width, int height, Percentage biasPercentage, Channels channels) => AdaptiveThreshold(width, height, biasPercentage.ToQuantum(), channels);

/// <summary>
/// Add noise to image with the specified noise type.
Expand Down Expand Up @@ -5580,7 +5612,15 @@ public void Texture(IMagickImage image)
/// </summary>
/// <param name="percentage">The threshold percentage.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void Threshold(Percentage percentage) => _nativeInstance.Threshold(percentage.ToQuantum());
public void Threshold(Percentage percentage) => Threshold(percentage, ImageMagick.Channels.All);

/// <summary>
/// Threshold image.
/// </summary>
/// <param name="percentage">The threshold percentage.</param>
/// <param name="channels">The channel(s) that should be thresholded.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void Threshold(Percentage percentage, Channels channels) => _nativeInstance.Threshold(percentage.ToQuantum(), channels);

/// <summary>
/// Resize image to thumbnail size.
Expand Down

0 comments on commit bd48f14

Please sign in to comment.