예제 #1
0
            public void ShouldChangePixelsWhenArrayHasMaxNumberOfValues()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixelsUnsafe())
                    {
                        var values = new QuantumType[113 * 108 * image.ChannelCount];
                        pixels.SetArea(10, 10, 113, 108, values);

                        ColorAssert.AreEqual(MagickColors.Black, image, image.Width - 1, image.Height - 1);
                    }
                }
            }
예제 #2
0
            public void ShouldChangePixelWhenTooManyChannelsAreSupplied()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixelsUnsafe())
                    {
                        Pixel pixel = new Pixel(0, 0, new QuantumType[] { 0, 0, 0, 0 });
                        pixels.SetPixel(pixel);

                        ColorAssert.AreEqual(MagickColors.Black, image, 0, 0);
                    }
                }
            }
예제 #3
0
            public void ShouldReturnAllPixels()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixels())
                    {
                        var values = pixels.ToArray();
                        int length = image.Width * image.Height * image.ChannelCount;

                        Assert.AreEqual(length, values.Length);
                    }
                }
            }
예제 #4
0
 public void ShouldThrowExceptionWhenGeometryIsSpecifiedAndMappingIsEmpty()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             ExceptionAssert.Throws <MagickResourceLimitErrorException>(() =>
             {
                 var values = pixels.ToByteArray(new MagickGeometry(1, 2, 3, 4), string.Empty);
             });
         }
     }
 }
예제 #5
0
 public void ShouldThrowExceptionWhenOffsetWidthIsOutsideImage()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             ExceptionAssert.Throws <MagickCacheErrorException>(() =>
             {
                 pixels.SetPixel(image.Width + 1, 0, new QuantumType[] { 0 });
             });
         }
     }
 }
예제 #6
0
 public void ShouldThrowExceptionWhenMappingIsEmpty()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             ExceptionAssert.Throws <MagickResourceLimitErrorException>(() =>
             {
                 pixels.ToByteArray(string.Empty);
             });
         }
     }
 }
예제 #7
0
            public void ShouldReturnArrayWhenTwoChannelsAreSupplied()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixelsUnsafe())
                    {
                        var values = pixels.ToByteArray("RG");
                        int length = image.Width * image.Height * 2;

                        Assert.AreEqual(length, values.Length);
                    }
                }
            }
예제 #8
0
 public void ShouldThrowExceptionWhenWidthZero()
 {
     using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             ExceptionAssert.Throws <InvalidOperationException>(() =>
             {
                 pixels.GetArea(0, 0, 0, 1);
             });
         }
     }
 }
예제 #9
0
 public void ShouldThrowExceptionWhenMappingIsEmpty()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentException("mapping", () =>
             {
                 pixels.ToByteArray(string.Empty);
             });
         }
     }
 }
예제 #10
0
 public void ShouldThrowExceptionWhenPixelWidthIsOutsideImage()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentOutOfRangeException("x", () =>
             {
                 pixels.SetPixel(new Pixel(image.Width + 1, 0, 3));
             });
         }
     }
 }
예제 #11
0
 public void ShouldThrowExceptionWhenWidthTooLow()
 {
     using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             ExceptionAssert.Throws <OverflowException>(() =>
             {
                 pixels.GetArea(0, 0, -1, 1);
             });
         }
     }
 }
예제 #12
0
 public void ShouldThrowExceptionWhenPixelIsNull()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentNullException("pixel", () =>
             {
                 pixels.SetPixel((Pixel)null);
             });
         }
     }
 }
예제 #13
0
 public void ShouldThrowExceptionWhenArrayIsEmpty()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentException("value", () =>
             {
                 pixels.SetPixel(0, 0, new QuantumType[] { });
             });
         }
     }
 }
예제 #14
0
            public void ShouldChangePixelsWhenGeometryAndByteArrayAreSpecified()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixelsUnsafe())
                    {
                        var values = new byte[113 * 108 * image.ChannelCount];
                        pixels.SetArea(new MagickGeometry(10, 10, 113, 108), values);

                        ColorAssert.AreEqual(MagickColors.Black, image, image.Width - 1, image.Height - 1);
                    }
                }
            }
예제 #15
0
 public void ShouldThrowExceptionWhenDoubleArrayIsNull()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentNullException("values", () =>
             {
                 pixels.SetPixels((double[])null);
             });
         }
     }
 }
예제 #16
0
            public void ShouldReturnArrayWhenTwoChannelsAreSuppliedAndMappingIsEnum()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixels())
                    {
                        var values = pixels.ToByteArray(PixelMapping.RGB);
                        int length = image.Width * image.Height * 3;

                        Assert.AreEqual(length, values.Length);
                    }
                }
            }
예제 #17
0
            public void ShouldReturnArrayWhenGeometryIsCorrect()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixelsUnsafe())
                    {
                        var values = pixels.ToByteArray(new MagickGeometry(10, 10, 113, 108), "RG");
                        int length = 113 * 108 * 2;

                        Assert.AreEqual(length, values.Length);
                    }
                }
            }
예제 #18
0
 public void ShouldThrowExceptionWhenXTooLow()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentOutOfRangeException("x", () =>
             {
                 pixels.ToByteArray(-1, 0, 1, 1, "RGB");
             });
         }
     }
 }
예제 #19
0
 public void ShouldThrowExceptionWhenMappingIsInvalid()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             ExceptionAssert.Throws <MagickOptionErrorException>(() =>
             {
                 pixels.ToByteArray("FOO");
             });
         }
     }
 }
예제 #20
0
 public void ShouldThrowExceptionWhenGeometryIsNullAndMappingIsEnum()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentNullException("geometry", () =>
             {
                 pixels.ToByteArray(null, PixelMapping.RGB);
             });
         }
     }
 }
예제 #21
0
            public void ShouldReturnPixelsWhenAreaIsCorrecy()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixelsUnsafe())
                    {
                        var values = pixels.ToByteArray(60, 60, 63, 58, "RGBA");
                        int length = 63 * 58 * 4;

                        Assert.AreEqual(length, values.Length);
                    }
                }
            }
예제 #22
0
 public void ShouldThrowExceptionWhenGeometryIsSpecifiedAndMappingIsNull()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentNullException("mapping", () =>
             {
                 pixels.ToByteArray(new MagickGeometry(1, 2, 3, 4), null);
             });
         }
     }
 }
예제 #23
0
            public void ShouldChangePixelWhenCompletePixelIsSupplied()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixelsUnsafe())
                    {
                        Pixel pixel = new Pixel(0, 0, new QuantumType[] { 0, Quantum.Max, 0 });
                        pixels.SetPixel(pixel);

                        ColorAssert.AreEqual(MagickColors.Lime, image, 0, 0);
                    }
                }
            }
예제 #24
0
            public void ShouldReturnArrayWhenGeometryIsCorrectAndMappingIsEnum()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixelsUnsafe())
                    {
                        var values = pixels.ToShortArray(new MagickGeometry(10, 10, 113, 108), PixelMapping.RGB);
                        var length = 113 * 108 * 3;

                        Assert.AreEqual(length, values.Length);
                    }
                }
            }
예제 #25
0
 public void ShouldThrowExceptionWhenPixelHeightIsOutsideImage()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             ExceptionAssert.Throws <MagickCacheErrorException>(() =>
             {
                 pixels.SetPixel(new Pixel(0, image.Height + 1, 3));
             });
         }
     }
 }
예제 #26
0
 public void ShouldThrowExceptionWhenByteArrayHasInvalidSize()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentException("values", () =>
             {
                 pixels.SetPixels(new byte[] { 0, 0, 0, 0 });
             });
         }
     }
 }
예제 #27
0
 public void ShouldThrowExceptionWhenHeightOutsideImage()
 {
     using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentOutOfRangeException("y", () =>
             {
                 pixels.GetPixel(0, image.Height + 1);
             });
         }
     }
 }
예제 #28
0
            public void ShouldChangePixelsWhenByteArrayHasMaxNumberOfValues()
            {
                using (IMagickImage image = new MagickImage(Files.ImageMagickJPG))
                {
                    using (IPixelCollection pixels = image.GetPixels())
                    {
                        var values = new byte[image.Width * image.Height * image.ChannelCount];
                        pixels.SetPixels(values);

                        ColorAssert.AreEqual(MagickColors.Black, image, image.Width - 1, image.Height - 1);
                    }
                }
            }
예제 #29
0
            public void ShouldReturnAllPixels()
            {
                using (IMagickImage image = new MagickImage(MagickColors.Purple, 4, 2))
                {
                    using (IPixelCollection pixels = image.GetPixels())
                    {
                        var values = pixels.GetValues();
                        int length = 4 * 2 * 3;

                        Assert.AreEqual(length, values.Length);
                    }
                }
            }
예제 #30
0
 private static void ThrowsArgumentException(string paramName, int x, int y, int width, int height)
 {
     using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.Throws <ArgumentOutOfRangeException>(paramName, () =>
             {
                 pixels.GetArea(x, y, width, height);
             });
         }
     }
 }