Skip to content

Commit

Permalink
Fixed implementation of methods and corrected unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Oct 15, 2023
1 parent 4972151 commit 58fbcd1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3351,7 +3351,7 @@ public void ImportPixels(QuantumType[] data, int offset, IPixelImportSettings se
Throw.IfTrue(nameof(settings), settings.StorageType != StorageType.Quantum, $"Storage type should be {nameof(StorageType.Quantum)}.");

var length = data.Length - offset;
var expectedLength = GetExpectedByteLength(settings);
var expectedLength = GetExpectedLength(settings);
Throw.IfTrue(nameof(data), length < expectedLength, "The data length is {0} but should be at least {1}.", data.Length, expectedLength + offset);

_nativeInstance.ImportPixels(settings.X, settings.Y, settings.Width, settings.Height, settings.Mapping, settings.StorageType, data, offset);
Expand Down
6 changes: 3 additions & 3 deletions src/Magick.NET/Netstandard21/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void ImportPixels(ReadOnlySpan<byte> data, IPixelImportSettings settings)
Throw.IfTrue(nameof(settings), settings.StorageType == StorageType.Undefined, "Storage type should not be undefined.");

var length = data.Length;
var expectedLength = GetExpectedByteLength(settings);
var expectedLength = GetExpectedLength(settings);
Throw.IfTrue(nameof(data), length < expectedLength, "The data length is {0} but should be at least {1}.", length, expectedLength);

_nativeInstance.ImportPixels(settings.X, settings.Y, settings.Width, settings.Height, settings.Mapping, settings.StorageType, data, 0);
Expand All @@ -124,7 +124,7 @@ public void ImportPixels(ReadOnlySpan<QuantumType> data, IPixelImportSettings se
Throw.IfTrue(nameof(settings), settings.StorageType != StorageType.Quantum, $"Storage type should be {nameof(StorageType.Quantum)}.");

var length = data.Length;
var expectedLength = GetExpectedByteLength(settings);
var expectedLength = GetExpectedLength(settings);
Throw.IfTrue(nameof(data), length < expectedLength, "The data length is {0} but should be at least {1}.", length, expectedLength);

_nativeInstance.ImportPixels(settings.X, settings.Y, settings.Width, settings.Height, settings.Mapping, settings.StorageType, data, 0);
Expand Down Expand Up @@ -274,7 +274,7 @@ public void ReadPixels(ReadOnlySpan<QuantumType> data, IPixelReadSettings<Quantu
SetSettings(newReadSettings);

var length = data.Length;
var expectedLength = GetExpectedByteLength(settings);
var expectedLength = GetExpectedLength(settings);
Throw.IfTrue(nameof(data), length < expectedLength, "The data length is {0} but should be at least {1}.", length, expectedLength);

_nativeInstance.ReadPixels(settings.ReadSettings.Width!.Value, settings.ReadSettings.Height!.Value, settings.Mapping, settings.StorageType, data, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void ShouldThrowExceptionWhenStorageTypeIsNotQuantum()
[Fact]
public void ShouldThrowExceptionWhenLengthIsTooLow()
{
var settings = new PixelImportSettings(1, 1, StorageType.Char, PixelMapping.RGB);
var settings = new PixelImportSettings(1, 1, StorageType.Quantum, PixelMapping.RGB);

using var image = new MagickImage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void ShouldThrowExceptionWhenStorageTypeIsNotQuantum()
[Fact]
public void ShouldThrowExceptionWhenLengthIsTooLow()
{
var settings = new PixelReadSettings(2, 2, StorageType.Char, "R");
var settings = new PixelReadSettings(2, 2, StorageType.Quantum, "R");
using var image = new MagickImage();

var exception = Assert.Throws<ArgumentException>("data", () => image.ReadPixels(new Span<QuantumType>(new QuantumType[] { 215, 215 }), settings));
Expand Down

0 comments on commit 58fbcd1

Please sign in to comment.