diff --git a/src/ImageSharp.Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/BoxBlurProcessor.cs index 367095b2b..3597ba7de 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/BoxBlurProcessor.cs @@ -57,8 +57,8 @@ namespace ImageSharp.Processing.Processors { int size = this.kernelSize; Fast2DArray kernel = horizontal - ? new Fast2DArray(new float[1, size]) - : new Fast2DArray(new float[size, 1]); + ? new Fast2DArray(size, 1) + : new Fast2DArray(1, size); float sum = 0F; for (int i = 0; i < size; i++) diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs index 6cdd5757e..6456cc073 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs @@ -21,23 +21,23 @@ namespace ImageSharp.Processing.Processors /// The horizontal gradient operator. /// private static readonly Fast2DArray KayyaliX = - new Fast2DArray(new float[,] + new float[,] { { 6, 0, -6 }, { 0, 0, 0 }, { -6, 0, 6 } - }); + }; /// /// The vertical gradient operator. /// private static readonly Fast2DArray KayyaliY = - new Fast2DArray(new float[,] + new float[,] { { -6, 0, 6 }, { 0, 0, 0 }, { 6, 0, -6 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs index e4e4e7bfa..90b3fc4b4 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs @@ -21,89 +21,89 @@ namespace ImageSharp.Processing.Processors /// The North gradient operator /// private static readonly Fast2DArray KirschNorth = - new Fast2DArray(new float[,] + new float[,] { { 5, 5, 5 }, { -3, 0, -3 }, { -3, -3, -3 } - }); + }; /// /// The NorthWest gradient operator /// private static readonly Fast2DArray KirschNorthWest = - new Fast2DArray(new float[,] + new float[,] { { 5, 5, -3 }, { 5, 0, -3 }, { -3, -3, -3 } - }); + }; /// /// The West gradient operator /// private static readonly Fast2DArray KirschWest = - new Fast2DArray(new float[,] + new float[,] { { 5, -3, -3 }, { 5, 0, -3 }, { 5, -3, -3 } - }); + }; /// /// The SouthWest gradient operator /// private static readonly Fast2DArray KirschSouthWest = - new Fast2DArray(new float[,] + new float[,] { { -3, -3, -3 }, { 5, 0, -3 }, { 5, 5, -3 } - }); + }; /// /// The South gradient operator /// private static readonly Fast2DArray KirschSouth = - new Fast2DArray(new float[,] + new float[,] { { -3, -3, -3 }, { -3, 0, -3 }, { 5, 5, 5 } - }); + }; /// /// The SouthEast gradient operator /// private static readonly Fast2DArray KirschSouthEast = - new Fast2DArray(new float[,] + new float[,] { { -3, -3, -3 }, { -3, 0, 5 }, { -3, 5, 5 } - }); + }; /// /// The East gradient operator /// private static readonly Fast2DArray KirschEast = - new Fast2DArray(new float[,] + new float[,] { { -3, -3, 5 }, { -3, 0, 5 }, { -3, -3, 5 } - }); + }; /// /// The NorthEast gradient operator /// private static readonly Fast2DArray KirschNorthEast = - new Fast2DArray(new float[,] + new float[,] { { -3, 5, 5 }, { -3, 0, 5 }, { -3, -3, -3 } - }); + }; /// public override Fast2DArray North => KirschNorth; diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs index 6dcea8b00..c8823efee 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs @@ -21,12 +21,12 @@ namespace ImageSharp.Processing.Processors /// The 2d gradient operator. /// private static readonly Fast2DArray Laplacian3X3XY = - new Fast2DArray(new float[,] + new float[,] { { -1, -1, -1 }, { -1, 8, -1 }, { -1, -1, -1 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs index 239cbb968..3aad6d1ef 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs @@ -21,14 +21,14 @@ namespace ImageSharp.Processing.Processors /// The 2d gradient operator. /// private static readonly Fast2DArray Laplacian5X5XY = - new Fast2DArray(new float[,] + new float[,] { { -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 }, { -1, -1, 24, -1, -1 }, { -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs index 73bc453a3..a7da76e13 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs @@ -21,14 +21,14 @@ namespace ImageSharp.Processing.Processors /// The 2d gradient operator. /// private static readonly Fast2DArray LaplacianOfGaussianXY = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, -1, 0, 0 }, { 0, -1, -2, -1, 0 }, { -1, -2, 16, -2, -1 }, { 0, -1, -2, -1, 0 }, { 0, 0, -1, 0, 0 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs index 5d4737e51..fea984418 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs @@ -21,23 +21,23 @@ namespace ImageSharp.Processing.Processors /// The horizontal gradient operator. /// private static readonly Fast2DArray PrewittX = - new Fast2DArray(new float[,] + new float[,] { { -1, 0, 1 }, { -1, 0, 1 }, { -1, 0, 1 } - }); + }; /// /// The vertical gradient operator. /// private static readonly Fast2DArray PrewittY = - new Fast2DArray(new float[,] + new float[,] { { 1, 1, 1 }, { 0, 0, 0 }, { -1, -1, -1 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs index 1be583cf3..329a995c0 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs @@ -21,21 +21,21 @@ namespace ImageSharp.Processing.Processors /// The horizontal gradient operator. /// private static readonly Fast2DArray RobertsCrossX = - new Fast2DArray(new float[,] + new float[,] { { 1, 0 }, { 0, -1 } - }); + }; /// /// The vertical gradient operator. /// private static readonly Fast2DArray RobertsCrossY = - new Fast2DArray(new float[,] + new float[,] { { 0, 1 }, { -1, 0 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs index 87651c3c6..60726deab 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs @@ -21,89 +21,89 @@ namespace ImageSharp.Processing.Processors /// The North gradient operator /// private static readonly Fast2DArray RobinsonNorth = - new Fast2DArray(new float[,] + new float[,] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } - }); + }; /// /// The NorthWest gradient operator /// private static readonly Fast2DArray RobinsonNorthWest = - new Fast2DArray(new float[,] + new float[,] { { 2, 1, 0 }, { 1, 0, -1 }, { 0, -1, -2 } - }); + }; /// /// The West gradient operator /// private static readonly Fast2DArray RobinsonWest = - new Fast2DArray(new float[,] + new float[,] { { 1, 0, -1 }, { 2, 0, -2 }, { 1, 0, -1 } - }); + }; /// /// The SouthWest gradient operator /// private static readonly Fast2DArray RobinsonSouthWest = - new Fast2DArray(new float[,] + new float[,] { { 0, -1, -2 }, { 1, 0, -1 }, { 2, 1, 0 } - }); + }; /// /// The South gradient operator /// private static readonly Fast2DArray RobinsonSouth = - new Fast2DArray(new float[,] + new float[,] { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } - }); + }; /// /// The SouthEast gradient operator /// private static readonly Fast2DArray RobinsonSouthEast = - new Fast2DArray(new float[,] + new float[,] { { -2, -1, 0 }, { -1, 0, 1 }, { 0, 1, 2 } - }); + }; /// /// The East gradient operator /// private static readonly Fast2DArray RobinsonEast = - new Fast2DArray(new float[,] + new float[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } - }); + }; /// /// The NorthEast gradient operator /// private static readonly Fast2DArray RobinsonNorthEast = - new Fast2DArray(new float[,] + new float[,] { { 0, 1, 2 }, { -1, 0, 1 }, { -2, -1, 0 } - }); + }; /// public override Fast2DArray North => RobinsonNorth; diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs index 4be2e720b..ed45ba0ac 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs @@ -21,23 +21,23 @@ namespace ImageSharp.Processing.Processors /// The horizontal gradient operator. /// private static readonly Fast2DArray ScharrX = - new Fast2DArray(new float[,] + new float[,] { { -3, 0, 3 }, { -10, 0, 10 }, { -3, 0, 3 } - }); + }; /// /// The vertical gradient operator. /// private static readonly Fast2DArray ScharrY = - new Fast2DArray(new float[,] + new float[,] { { 3, 10, 3 }, { 0, 0, 0 }, { -3, -10, -3 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs index bb64f3e13..3d2c583a7 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs @@ -21,23 +21,23 @@ namespace ImageSharp.Processing.Processors /// The horizontal gradient operator. /// private static readonly Fast2DArray SobelX = - new Fast2DArray(new float[,] + new float[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } - }); + }; /// /// The vertical gradient operator. /// private static readonly Fast2DArray SobelY = - new Fast2DArray(new float[,] + new float[,] { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp.Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/GaussianBlurProcessor.cs index daa660f84..ddaffc9b4 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/GaussianBlurProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/GaussianBlurProcessor.cs @@ -94,8 +94,8 @@ namespace ImageSharp.Processing.Processors int size = this.kernelSize; float weight = this.sigma; Fast2DArray kernel = horizontal - ? new Fast2DArray(new float[1, size]) - : new Fast2DArray(new float[size, 1]); + ? new Fast2DArray(size, 1) + : new Fast2DArray(1, size); float sum = 0F; float midpoint = (size - 1) / 2F; diff --git a/src/ImageSharp.Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp.Processing/Processors/Convolution/GaussianSharpenProcessor.cs index a51bb5b9f..6541b7380 100644 --- a/src/ImageSharp.Processing/Processors/Convolution/GaussianSharpenProcessor.cs +++ b/src/ImageSharp.Processing/Processors/Convolution/GaussianSharpenProcessor.cs @@ -96,8 +96,8 @@ namespace ImageSharp.Processing.Processors int size = this.kernelSize; float weight = this.sigma; Fast2DArray kernel = horizontal - ? new Fast2DArray(new float[1, size]) - : new Fast2DArray(new float[size, 1]); + ? new Fast2DArray(size, 1) + : new Fast2DArray(1, size); float sum = 0; diff --git a/src/ImageSharp/Common/Memory/Fast2DArray{T}.cs b/src/ImageSharp/Common/Memory/Fast2DArray{T}.cs index 88a979757..3455031fd 100644 --- a/src/ImageSharp/Common/Memory/Fast2DArray{T}.cs +++ b/src/ImageSharp/Common/Memory/Fast2DArray{T}.cs @@ -30,6 +30,22 @@ namespace ImageSharp /// public int Height; + /// + /// Initializes a new instance of the struct. + /// + /// The width. + /// The height. + public Fast2DArray(int width, int height) + { + this.Height = height; + this.Width = width; + + Guard.MustBeGreaterThan(width, 0, nameof(width)); + Guard.MustBeGreaterThan(height, 0, nameof(height)); + + this.Data = new T[this.Width * this.Height]; + } + /// /// Initializes a new instance of the struct. /// @@ -77,6 +93,19 @@ namespace ImageSharp } } + /// + /// Performs an implicit conversion from a 2D array to a . + /// + /// The source array. + /// + /// The represenation on the source data. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Fast2DArray(T[,] data) + { + return new Fast2DArray(data); + } + /// /// Checks the coordinates to ensure they are within bounds. /// diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs index 1fa6852c2..b94b87255 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Atkinson.cs @@ -15,12 +15,12 @@ namespace ImageSharp.Dithering /// The diffusion matrix /// private static readonly Fast2DArray AtkinsonMatrix = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, 1, 1 }, { 1, 1, 1, 0 }, { 0, 1, 0, 0 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs index a4adcb0a4..894b6e236 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Burks.cs @@ -15,11 +15,11 @@ namespace ImageSharp.Dithering /// The diffusion matrix /// private static readonly Fast2DArray BurksMatrix = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, 0, 8, 4 }, { 2, 4, 8, 4, 2 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs b/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs index 7b67d2dd1..f7a93667f 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/FloydSteinberg.cs @@ -15,11 +15,11 @@ namespace ImageSharp.Dithering /// The diffusion matrix /// private static readonly Fast2DArray FloydSteinbergMatrix = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, 7 }, { 3, 5, 1 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs b/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs index 32f38fbc8..60fef8121 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/JarvisJudiceNinke.cs @@ -15,12 +15,12 @@ namespace ImageSharp.Dithering /// The diffusion matrix /// private static readonly Fast2DArray JarvisJudiceNinkeMatrix = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, 0, 7, 5 }, { 3, 5, 7, 5, 3 }, { 1, 3, 5, 3, 1 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs index 47b14944e..4325438e0 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra2.cs @@ -15,11 +15,11 @@ namespace ImageSharp.Dithering /// The diffusion matrix /// private static readonly Fast2DArray Sierra2Matrix = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, 0, 4, 3 }, { 1, 2, 3, 2, 1 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs index ae33954cf..25ea70d0a 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Sierra3.cs @@ -15,12 +15,12 @@ namespace ImageSharp.Dithering /// The diffusion matrix /// private static readonly Fast2DArray Sierra3Matrix = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, 0, 5, 3 }, { 2, 4, 5, 4, 2 }, { 0, 2, 3, 2, 0 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs b/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs index 8a1e17816..c7b1d214f 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/SierraLite.cs @@ -15,11 +15,11 @@ namespace ImageSharp.Dithering /// The diffusion matrix /// private static readonly Fast2DArray SierraLiteMatrix = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, 2 }, { 1, 1, 0 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs b/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs index b5d22b259..93258c350 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/Stucki.cs @@ -15,12 +15,12 @@ namespace ImageSharp.Dithering /// The diffusion matrix /// private static readonly Fast2DArray StuckiMatrix = - new Fast2DArray(new float[,] + new float[,] { { 0, 0, 0, 8, 4 }, { 2, 4, 8, 4, 2 }, { 1, 2, 4, 2, 1 } - }); + }; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Dithering/Ordered/Bayer.cs b/src/ImageSharp/Dithering/Ordered/Bayer.cs index 95545f46b..1027e51d9 100644 --- a/src/ImageSharp/Dithering/Ordered/Bayer.cs +++ b/src/ImageSharp/Dithering/Ordered/Bayer.cs @@ -18,13 +18,13 @@ namespace ImageSharp.Dithering.Ordered /// This is calculated by multiplying each value in the original matrix by 16 and subtracting 1 /// private static readonly Fast2DArray ThresholdMatrix = - new Fast2DArray(new byte[,] + new byte[,] { { 15, 143, 47, 175 }, { 207, 79, 239, 111 }, { 63, 191, 31, 159 }, { 255, 127, 223, 95 } - }); + }; /// public Fast2DArray Matrix { get; } = ThresholdMatrix; diff --git a/src/ImageSharp/Dithering/Ordered/Ordered.cs b/src/ImageSharp/Dithering/Ordered/Ordered.cs index df48a3167..aabca31aa 100644 --- a/src/ImageSharp/Dithering/Ordered/Ordered.cs +++ b/src/ImageSharp/Dithering/Ordered/Ordered.cs @@ -18,13 +18,13 @@ namespace ImageSharp.Dithering.Ordered /// This is calculated by multiplying each value in the original matrix by 16 /// private static readonly Fast2DArray ThresholdMatrix = - new Fast2DArray(new byte[,] + new byte[,] { { 0, 128, 32, 160 }, { 192, 64, 224, 96 }, { 48, 176, 16, 144 }, { 240, 112, 208, 80 } - }); + }; /// public Fast2DArray Matrix { get; } = ThresholdMatrix; diff --git a/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs b/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs index 903ea6f8d..7db7a4820 100644 --- a/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs +++ b/tests/ImageSharp.Tests/Common/Fast2DArrayTests.cs @@ -21,9 +21,27 @@ namespace ImageSharp.Tests.Common public void Fast2DArrayThrowsOnNullInitializer() { Assert.Throws(() => - { - Fast2DArray fast = new Fast2DArray(null); - }); + { + Fast2DArray fast = new Fast2DArray(null); + }); + } + + [Fact] + public void Fast2DArrayThrowsOnEmptyZeroWidth() + { + Assert.Throws(() => + { + Fast2DArray fast = new Fast2DArray(0, 10); + }); + } + + [Fact] + public void Fast2DArrayThrowsOnEmptyZeroHeight() + { + Assert.Throws(() => + { + Fast2DArray fast = new Fast2DArray(10, 0); + }); } [Fact] @@ -46,7 +64,7 @@ namespace ImageSharp.Tests.Common [Fact] public void Fast2DArrayGetReturnsCorrectResults() { - Fast2DArray fast = new Fast2DArray(FloydSteinbergMatrix); + Fast2DArray fast = FloydSteinbergMatrix; for (int row = 0; row < fast.Height; row++) { @@ -60,7 +78,7 @@ namespace ImageSharp.Tests.Common [Fact] public void Fast2DArrayGetSetReturnsCorrectResults() { - Fast2DArray fast = new Fast2DArray(new float[4, 4]); + Fast2DArray fast = new Fast2DArray(4, 4); const float Val = 5F; fast[3, 3] = Val;