Accord.Imaging.Tests.UnmanagedImageTest.Collect8bppPixelValuesTest_RGB C# (CSharp) Method

Collect8bppPixelValuesTest_RGB() private method

private Collect8bppPixelValuesTest_RGB ( ) : void
return void
        public void Collect8bppPixelValuesTest_RGB()
        {
            // create grayscale image
            UnmanagedImage image = UnmanagedImage.Create(320, 240, PixelFormat.Format24bppRgb);

            // draw vertical and horizontal lines
            Drawing.Line(image, new IntPoint(10, 10), new IntPoint(20, 10), Color.FromArgb(128, 129, 130));
            Drawing.Line(image, new IntPoint(20, 20), new IntPoint(20, 30), Color.FromArgb(64, 65, 66));

            // prepare lists with coordinates
            List<IntPoint> horizontal = new List<IntPoint>();
            List<IntPoint> horizontalU = new List<IntPoint>();
            List<IntPoint> horizontalD = new List<IntPoint>();

            for (int x = 10; x <= 20; x++)
            {
                horizontal.Add(new IntPoint(x, 10));  // on the line
                horizontalU.Add(new IntPoint(x, 9));  // above
                horizontalD.Add(new IntPoint(x, 11)); // below
            }

            List<IntPoint> vertical = new List<IntPoint>();
            List<IntPoint> verticalL = new List<IntPoint>();
            List<IntPoint> verticalR = new List<IntPoint>();

            for (int y = 20; y <= 30; y++)
            {
                vertical.Add(new IntPoint(20, y));    // on the line
                verticalL.Add(new IntPoint(19, y));   // left
                verticalR.Add(new IntPoint(21, y));   // right
            }

            // collect all pixel's values
            byte[] horizontalValues = image.Collect8bppPixelValues(horizontal);
            byte[] horizontalUValues = image.Collect8bppPixelValues(horizontalU);
            byte[] horizontalDValues = image.Collect8bppPixelValues(horizontalD);
            byte[] verticalValues = image.Collect8bppPixelValues(vertical);
            byte[] verticalLValues = image.Collect8bppPixelValues(verticalL);
            byte[] verticalRValues = image.Collect8bppPixelValues(verticalR);

            Assert.AreEqual(horizontal.Count * 3, horizontalValues.Length);
            Assert.AreEqual(vertical.Count * 3, verticalValues.Length);

            // check all pixel values
            for (int i = 0, n = horizontalValues.Length; i < n; i += 3)
            {
                Assert.AreEqual(128, horizontalValues[i]);
                Assert.AreEqual(129, horizontalValues[i + 1]);
                Assert.AreEqual(130, horizontalValues[i + 2]);

                Assert.AreEqual(0, horizontalUValues[i]);
                Assert.AreEqual(0, horizontalUValues[i + 1]);
                Assert.AreEqual(0, horizontalUValues[i + 2]);

                Assert.AreEqual(0, horizontalDValues[i]);
                Assert.AreEqual(0, horizontalDValues[i + 1]);
                Assert.AreEqual(0, horizontalDValues[i + 2]);
            }

            for (int i = 0, n = verticalValues.Length; i < n; i += 3)
            {
                Assert.AreEqual(64, verticalValues[i]);
                Assert.AreEqual(65, verticalValues[i + 1]);
                Assert.AreEqual(66, verticalValues[i + 2]);

                Assert.AreEqual(0, verticalLValues[i]);
                Assert.AreEqual(0, verticalLValues[i + 1]);
                Assert.AreEqual(0, verticalLValues[i + 2]);

                Assert.AreEqual(0, verticalRValues[i]);
                Assert.AreEqual(0, verticalRValues[i + 1]);
                Assert.AreEqual(0, verticalRValues[i + 2]);
            }
        }