-
-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GetReadOnlyArea to IPixelCollection (#1456)
- Loading branch information
Showing
8 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...agick.NET.Tests/Netstandard21/Pixels/SafePixelCollectionTests/TheGetReadonlyAreaMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
#if NETCOREAPP | ||
|
||
using System; | ||
using ImageMagick; | ||
using Xunit; | ||
|
||
namespace Magick.NET.Tests | ||
{ | ||
public partial class SafePixelCollectionTests | ||
{ | ||
public partial class TheGetReadonlyAreaMethod | ||
{ | ||
[Fact] | ||
public void ShouldThrowExceptionWhenAreaIsInvalid() | ||
{ | ||
using var image = new MagickImage(MagickColors.Red, 1, 1); | ||
using var pixels = image.GetPixels(); | ||
|
||
Assert.Throws<ArgumentOutOfRangeException>(() => pixels.GetReadOnlyArea(1, 2, 3, 4)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotThrowExceptionWhenGeometryIsNull() | ||
{ | ||
using var image = new MagickImage(Files.ImageMagickJPG); | ||
using var pixels = image.GetPixels(); | ||
|
||
Assert.Throws<ArgumentNullException>("geometry", () => pixels.GetReadOnlyArea(null)); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnAllPixelsOfTheImage() | ||
{ | ||
using var input = new MagickImage(Files.ImageMagickJPG); | ||
using var pixels = input.GetPixels(); | ||
var area = pixels.GetReadOnlyArea(0, 0, input.Width, input.Height); | ||
|
||
Assert.Equal(43542, area.Length); | ||
|
||
var settings = new PixelReadSettings(input.Width, input.Height, StorageType.Quantum, PixelMapping.RGB); | ||
using var output = new MagickImage(); | ||
output.ReadPixels(area, settings); | ||
|
||
var difference = output.Compare(input, ErrorMetric.RootMeanSquared); | ||
Assert.Equal(0.0, difference); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
55 changes: 55 additions & 0 deletions
55
...ick.NET.Tests/Netstandard21/Pixels/UnsafePixelCollectionTests/TheGetReadonlyAreaMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
#if NETCOREAPP | ||
|
||
using ImageMagick; | ||
using Xunit; | ||
|
||
namespace Magick.NET.Tests | ||
{ | ||
public partial class UnsafePixelCollectionTests | ||
{ | ||
public partial class TheGetReadonlyAreaMethod | ||
{ | ||
[Fact] | ||
public void ShouldNotThrowExceptionWhenAreaIsInvalid() | ||
{ | ||
using var image = new MagickImage(MagickColors.Red, 1, 1); | ||
using var pixels = image.GetPixelsUnsafe(); | ||
var area = pixels.GetReadOnlyArea(1, 2, 3, 4); | ||
|
||
Assert.Equal(36, area.Length); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotThrowExceptionWhenGeometryIsNull() | ||
{ | ||
using var image = new MagickImage(Files.ImageMagickJPG); | ||
using var pixels = image.GetPixelsUnsafe(); | ||
var area = pixels.GetReadOnlyArea(null); | ||
|
||
Assert.Equal(0, area.Length); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnAllPixelsOfTheImage() | ||
{ | ||
using var input = new MagickImage(Files.ImageMagickJPG); | ||
using var pixels = input.GetPixelsUnsafe(); | ||
var area = pixels.GetReadOnlyArea(0, 0, input.Width, input.Height); | ||
|
||
Assert.Equal(43542, area.Length); | ||
|
||
var settings = new PixelReadSettings(input.Width, input.Height, StorageType.Quantum, PixelMapping.RGB); | ||
using var output = new MagickImage(); | ||
output.ReadPixels(area, settings); | ||
|
||
var difference = output.Compare(input, ErrorMetric.RootMeanSquared); | ||
Assert.Equal(0.0, difference); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |