Skip to content

Commit 8c3f237

Browse files
committed
Moved Deskew to IMagickImageCreateOperations.
1 parent bf3c86f commit 8c3f237

File tree

5 files changed

+51
-40
lines changed

5 files changed

+51
-40
lines changed

src/Magick.NET.Core/IMagickImage.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -867,28 +867,6 @@ public partial interface IMagickImage : IMagickImageCreateOperations, IDisposabl
867867
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
868868
void Decipher(string passphrase);
869869

870-
/// <summary>
871-
/// Removes skew from the image. Skew is an artifact that occurs in scanned images because of
872-
/// the camera being misaligned, imperfections in the scanning or surface, or simply because
873-
/// the paper was not placed completely flat when scanned. The value of threshold ranges
874-
/// from 0 to QuantumRange.
875-
/// </summary>
876-
/// <param name="threshold">The threshold.</param>
877-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
878-
/// <returns>The angle that was used.</returns>
879-
double Deskew(Percentage threshold);
880-
881-
/// <summary>
882-
/// Removes skew from the image. Skew is an artifact that occurs in scanned images because of
883-
/// the camera being misaligned, imperfections in the scanning or surface, or simply because
884-
/// the paper was not placed completely flat when scanned. The value of threshold ranges
885-
/// from 0 to QuantumRange. After the image is deskewed, it is cropped.
886-
/// </summary>
887-
/// <param name="threshold">The threshold.</param>
888-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
889-
/// <returns>The angle that was used.</returns>
890-
double DeskewAndCrop(Percentage threshold);
891-
892870
/// <summary>
893871
/// Despeckle image (reduce speckle noise).
894872
/// </summary>

src/Magick.NET.Core/IMagickImageCreateOperations.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,28 @@ public interface IMagickImageCreateOperations
378378
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
379379
void Crop(IMagickGeometry geometry, Gravity gravity);
380380

381+
/// <summary>
382+
/// Removes skew from the image. Skew is an artifact that occurs in scanned images because of
383+
/// the camera being misaligned, imperfections in the scanning or surface, or simply because
384+
/// the paper was not placed completely flat when scanned. The value of threshold ranges
385+
/// from 0 to QuantumRange.
386+
/// </summary>
387+
/// <param name="threshold">The threshold.</param>
388+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
389+
/// <returns>The angle that was used.</returns>
390+
double Deskew(Percentage threshold);
391+
392+
/// <summary>
393+
/// Removes skew from the image. Skew is an artifact that occurs in scanned images because of
394+
/// the camera being misaligned, imperfections in the scanning or surface, or simply because
395+
/// the paper was not placed completely flat when scanned. The value of threshold ranges
396+
/// from 0 to QuantumRange. After the image is deskewed, it is cropped.
397+
/// </summary>
398+
/// <param name="threshold">The threshold.</param>
399+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
400+
/// <returns>The angle that was used.</returns>
401+
double DeskewAndCrop(Percentage threshold);
402+
381403
/// <summary>
382404
/// Resize image to specified size.
383405
/// <para />

src/Magick.NET/MagickImage.CloneMutator.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ public void Crop(uint width, uint height, Gravity gravity)
215215
public void Crop(IMagickGeometry geometry)
216216
=> Crop(geometry, Gravity.Undefined);
217217

218+
public double Deskew(Percentage threshold)
219+
=> Deskew(threshold, autoCrop: false);
220+
221+
public double DeskewAndCrop(Percentage threshold)
222+
=> Deskew(threshold, autoCrop: true);
223+
218224
public void Crop(IMagickGeometry geometry, Gravity gravity)
219225
{
220226
Throw.IfNull(nameof(geometry), geometry);
@@ -245,5 +251,19 @@ protected virtual void SetResult(IntPtr result)
245251

246252
_result = result;
247253
}
254+
255+
private double Deskew(Percentage threshold, bool autoCrop)
256+
{
257+
using var temporaryDefines = new TemporaryDefines(NativeMagickImage);
258+
temporaryDefines.SetArtifact("deskew:auto-crop", autoCrop);
259+
260+
SetResult(NativeMagickImage.Deskew(PercentageHelper.ToQuantum(nameof(threshold), threshold)));
261+
262+
var artifact = NativeMagickImage.GetArtifact("deskew:angle");
263+
if (!double.TryParse(artifact, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
264+
return 0.0;
265+
266+
return result;
267+
}
248268
}
249269
}

src/Magick.NET/MagickImage.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,7 +2520,10 @@ public void Decipher(string passphrase)
25202520
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
25212521
/// <returns>The angle that was used.</returns>
25222522
public double Deskew(Percentage threshold)
2523-
=> Deskew(threshold, autoCrop: false);
2523+
{
2524+
using var mutator = new Mutator(_nativeInstance);
2525+
return mutator.Deskew(threshold);
2526+
}
25242527

25252528
/// <summary>
25262529
/// Removes skew from the image. Skew is an artifact that occurs in scanned images because of
@@ -2532,7 +2535,10 @@ public double Deskew(Percentage threshold)
25322535
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
25332536
/// <returns>The angle that was used.</returns>
25342537
public double DeskewAndCrop(Percentage threshold)
2535-
=> Deskew(threshold, autoCrop: true);
2538+
{
2539+
using var mutator = new Mutator(_nativeInstance);
2540+
return mutator.DeskewAndCrop(threshold);
2541+
}
25362542

25372543
/// <summary>
25382544
/// Despeckle image (reduce speckle noise).
@@ -7293,20 +7299,6 @@ private MagickReadSettings CreateReadSettings(IMagickReadSettings<QuantumType>?
72937299
return newReadSettings;
72947300
}
72957301

7296-
private double Deskew(Percentage threshold, bool autoCrop)
7297-
{
7298-
using var temporaryDefines = new TemporaryDefines(this);
7299-
temporaryDefines.SetArtifact("deskew:auto-crop", autoCrop);
7300-
7301-
_nativeInstance.Deskew(PercentageHelper.ToQuantum(nameof(threshold), threshold));
7302-
7303-
var artifact = GetArtifact("deskew:angle");
7304-
if (!double.TryParse(artifact, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
7305-
return 0.0;
7306-
7307-
return result;
7308-
}
7309-
73107302
private void Dispose(bool disposing)
73117303
{
73127304
DisposeInstance();

src/Magick.NET/Native/MagickImage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeM
365365
public partial void Decipher(string passphrase);
366366

367367
[Throws]
368-
[SetInstance]
369-
public partial void Deskew(double threshold);
368+
public partial IntPtr Deskew(double threshold);
370369

371370
[Throws]
372371
[SetInstance]

0 commit comments

Comments
 (0)