Example #1
0
        public void TestSetRowArgbArray()
        {
            using (var bitmap = SurfaceExtensionsTest.LoadResource("style.png"))
            {
                var line     = new Rectangle(13, 27, 64, 1);
                var data     = bitmap.LockBits(line, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                var expected = new byte[line.Width * 4];
                _ = data.GetRowArgb(expected, 0, 0);
                bitmap.UnlockBits(data);

                var tensor = new DenseTensor <float>(new Rectangle(Point.Empty, bitmap.Size).ToNHWC());
                tensor.SetRowArgb(expected, line.X, line.Y);

                var actual = new byte[expected.Length];
                _ = tensor.GetRowArgb(actual, line.X, line.Y);

                CollectionAssert.AreEqual(expected, actual);
            }
        }
Example #2
0
        public void TestSetRowArgbArraySegment()
        {
            using (var bitmap = SurfaceExtensionsTest.LoadResource("style.png"))
            {
                var line     = new Rectangle(13, 27, 64, 1);
                var data     = bitmap.LockBits(line, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                var expected = new byte[data.Stride + 32];
                var memory   = new ArraySegment <byte>(expected, 8, line.Width * 4);
                _ = data.GetRowArgb(memory, 0, 0);
                bitmap.UnlockBits(data);

                var tensor = new DenseTensor <float>(new Rectangle(Point.Empty, bitmap.Size).ToNHWC());
                tensor.SetRowArgb(memory, line.X, line.Y);

                var actual = new byte[memory.Count];
                _ = tensor.GetRowArgb(actual, line.X, line.Y);

                CollectionAssert.AreEqual(expected.Skip(memory.Offset).Take(memory.Count).ToArray(), actual);
            }
        }
Example #3
0
        public void TestToTensor()
        {
            using (var bitmap = SurfaceExtensionsTest.LoadResource("style.png"))
                using (var surf = new Surface(bitmap.Width, bitmap.Height, SurfaceCreationFlags.Default))
                {
                    surf.CopyFromGdipBitmap(bitmap);
                    using (var copy = surf.Clone())
                    {
                        // round-trip: surface->tensor->surface
                        surf.ToTensor().ToSurface(copy);

                        var(cols, rows) = (surf.Width, surf.Height);

                        // compare pixel by pixel
                        for (int y = 0; y < rows; ++y)
                        {
                            for (int x = 0; x < cols; ++x)
                            {
                                Assert.AreEqual(surf[x, y], copy[x, y]);
                            }
                        }
                    }
                }
        }