Ejemplo n.º 1
0
 private static void ThrowsNoException(int x, int y)
 {
     using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             pixels.GetValue(x, y);
         }
     }
 }
Ejemplo n.º 2
0
 private static void ThrowsOverflowException(int x, int y)
 {
     using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10))
     {
         using (IPixelCollection pixels = image.GetPixelsUnsafe())
         {
             if (Is64Bit)
             {
                 pixels.GetValue(x, y);
             }
             else
             {
                 ExceptionAssert.Throws <OverflowException>(() =>
                 {
                     pixels.GetValue(x, y);
                 });
             }
         }
     }
 }
Ejemplo n.º 3
0
        public static void ClampBorder(this MagickImage image, int borderSize)
        {
            IPixelCollection pixels = image.GetPixels();

            // Fill left and right borders by going row by row
            int rightOffset = image.Width - borderSize;

            byte[] targetColor;
            for (int y = borderSize; y < image.Height - borderSize; y++)
            {
                MagickGeometry left = new MagickGeometry(0, y, borderSize, 1);
                targetColor = pixels.GetValue(borderSize, y);
                pixels.SetArea(left, targetColor.RepeatArray(borderSize));

                MagickGeometry right = new MagickGeometry(rightOffset, y, borderSize, 1);
                targetColor = pixels.GetValue(rightOffset - 1, y);
                pixels.SetArea(right, targetColor.RepeatArray(borderSize));
            }

            // Fill top and bottom by going column by column
            int bottomOffset = image.Height - borderSize;

            for (int x = borderSize; x < image.Width - borderSize; x++)
            {
                MagickGeometry top = new MagickGeometry(x, 0, 1, borderSize);
                targetColor = pixels.GetValue(x, borderSize);
                pixels.SetArea(top, targetColor.RepeatArray(borderSize));

                MagickGeometry bottom = new MagickGeometry(x, bottomOffset, 1, borderSize);
                targetColor = pixels.GetValue(x, bottomOffset - 1);
                pixels.SetArea(bottom, targetColor.RepeatArray(borderSize));
            }

            int cornerSize = borderSize * borderSize;

            // Fill top left corner
            targetColor = pixels.GetValue(borderSize, borderSize);
            pixels.SetArea(0, 0, borderSize, borderSize, targetColor.RepeatArray(cornerSize));

            // Fill top right corner
            targetColor = pixels.GetValue(rightOffset - 1, borderSize);
            pixels.SetArea(rightOffset, 0, borderSize, borderSize, targetColor.RepeatArray(cornerSize));

            // Fill bottom left corner
            targetColor = pixels.GetValue(borderSize, bottomOffset - 1);
            pixels.SetArea(0, bottomOffset, borderSize, borderSize, targetColor.RepeatArray(cornerSize));

            // Fill bottom right corner
            targetColor = pixels.GetValue(rightOffset - 1, bottomOffset - 1);
            pixels.SetArea(rightOffset, bottomOffset, borderSize, borderSize, targetColor.RepeatArray(cornerSize));
        }
Ejemplo n.º 4
0
 private static void ThrowsArgumentOutOfRangeException(string paramName, int x, int y)
 {
     using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10))
     {
         using (IPixelCollection pixels = image.GetPixels())
         {
             ExceptionAssert.ThrowsArgumentOutOfRangeException(paramName, () =>
             {
                 pixels.GetValue(x, y);
             });
         }
     }
 }
Ejemplo n.º 5
0
            public void ShouldReturnCorrectValue()
            {
                using (IMagickImage image = new MagickImage(MagickColors.Red, 1, 1))
                {
                    using (IPixelCollection pixels = image.GetPixels())
                    {
                        var pixel = pixels.GetValue(0, 0);

                        Assert.AreEqual(3, pixel.Length);
                        Assert.AreEqual(Quantum.Max, pixel[0]);
                        Assert.AreEqual(0, pixel[1]);
                        Assert.AreEqual(0, pixel[2]);
                    }
                }
            }