Beispiel #1
0
        public void TestHashCodes()
        {
            var gray = new MemoryBitmap <Byte>(256, 256, Pixel.Luminance8.Format);

            Assert.AreEqual(256, gray.Info.StepByteSize);
            var grayWithStride = new MemoryBitmap <Byte>(256, 256, Pixel.Luminance8.Format, 320);

            Assert.AreEqual(320, grayWithStride.Info.StepByteSize);


            var rnd = new Random(117);

            for (int i = 0; i < 256 * 256; ++i)
            {
                gray.SetPixel(i & 255, i / 256, (Byte)rnd.Next());
            }

            grayWithStride.SetPixels(0, 0, gray);

            Assert.AreEqual(gray.GetHashCode(), grayWithStride.GetHashCode());

            var span = gray.AsSpanBitmap();
            var less = span.AsTypeless();
            var hash = gray.GetHashCode();

            Assert.AreEqual(1953103375, hash);
            Assert.AreEqual(hash, gray.AsTypeless().GetHashCode());
            Assert.AreEqual(hash, span.GetHashCode());
            Assert.AreEqual(hash, less.GetHashCode());
        }
Beispiel #2
0
        public void TestPointerBitmapSlice()
        {
            void _testSlice(PointerBitmap ptr)
            {
                ptr = ptr.Slice((1, 1, 2, 2));

                Assert.AreEqual(true, ptr.IsReadOnly);

                Assert.AreEqual(2, ptr.Width);
                Assert.AreEqual(2, ptr.Height);
                Assert.AreEqual(16, ptr.StepByteSize);

                var ptrSpan = ptr.AsSpanBitmapOfType <int>();

                Assert.AreEqual(0, ptrSpan.GetPixel(0, 0));
                Assert.AreEqual(0, ptrSpan.GetPixel(1, 0));
                Assert.AreEqual(0, ptrSpan.GetPixel(0, 1));
                Assert.AreEqual(0, ptrSpan.GetPixel(1, 1));
            }

            var bmp = new MemoryBitmap <int>(4, 4, Pixel.ARGB32.Format);

            bmp.SetPixels(int.MaxValue);
            bmp.Slice((1, 1, 2, 2)).SetPixels(0);

            bmp.AsSpanBitmap().PinReadablePointer(_testSlice);
        }
Beispiel #3
0
        public void TestConvertBitmaps()
        {
            var src = new MemoryBitmap(1920, 1080, Pixel.BGRA32.Format);

            var dst = new MemoryBitmap(src.Info.WithPixelFormat<Pixel.RGBA32>());
            dst.SetPixels(0, 0, src);
        }
Beispiel #4
0
        public void CreateMemoryBitmap()
        {
            var m1 = new MemoryBitmap <UInt32>(16, 16, Pixel.BGRA32.Format);

            m1.SetPixels(0xff406040);

            m1.Save(new AttachmentInfo("result.png"));
        }
Beispiel #5
0
        public void TestSampler()
        {
            var map = new MemoryBitmap <Pixel.BGRA32>(16, 16);

            map.SetPixels(new Pixel.BGRA32(255, 127, 63, 31));

            var sampler = new Processing._PixelsTransformImplementation.SpanQuantized8Sampler <Pixel.BGRA32, Pixel.BGRA32>(map);

            var pix = sampler.GetSourcePixelOrDefault(8, 8);
        }
Beispiel #6
0
        private static MemoryBitmap LoadShannonImage()
        {
            var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\shannon.jpg");

            // load a bitmap with SkiaSharp, which is known to support WEBP.
            var mem = MemoryBitmap.Load(filePath, Codecs.GDICodec.Default);

            var mem2 = new MemoryBitmap(mem.Width, mem.Height, Pixel.BGR24.Format);

            mem2.SetPixels(0, 0, mem);

            return(mem2);
        }
Beispiel #7
0
        public void SetPixels()
        {
            var dst = new MemoryBitmap <Byte>(16, 16, Pixel.Luminance8.Format);
            var src = new MemoryBitmap <Byte>(8, 8, Pixel.Luminance8.Format);

            src.SetPixels(50);
            dst.SetPixels(4, 4, src);

            src.SetPixels(255);
            dst.SetPixels(-4, -4, src);

            src.SetPixels(130);
            dst.SetPixels(12, -4, src);

            src.SetPixels(255);
            dst.SetPixels(12, 12, src);

            src.SetPixels(70);
            dst.SetPixels(-4, 12, src);

            dst.SetPixels(-50, 0, src);

            dst.Save(new AttachmentInfo("Result.png"));
        }
Beispiel #8
0
        public void CopyPixelsWithStride()
        {
            var m1 = new MemoryBitmap <UInt32>(16, 16, Pixel.BGRA32.Format);

            m1.SetPixel(0, 0, 0xff00ff00);
            m1.SetPixel(0, 1, 0xffff00ff);

            var m2 = new MemoryBitmap <UInt32>(16, 16, Pixel.BGRA32.Format, 17 * 4);

            m2.SetPixels(0, 0, m1);

            m2.Save(new AttachmentInfo("result.png"));

            Assert.AreEqual(0xff00ff00, m2.GetPixel(0, 0));
            Assert.AreEqual(0xffff00ff, m2.GetPixel(0, 1));
        }
Beispiel #9
0
        public void CopyGreyPixels()
        {
            var src = new MemoryBitmap <float>(177, 177).Slice((10, 10, 150, 150));
            var dst = new MemoryBitmap <Byte>(177, 177).Slice((10, 10, 150, 150));

            src.SetPixels(1);

            var(min, max) = SpanBitmap.MinMax(src);
            Assert.AreEqual(min, 1);
            Assert.AreEqual(max, 1);

            SpanBitmap.CopyPixels(src, dst, (0, 128), (0, 255));
            Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel == 128));

            SpanBitmap.CopyPixels(src, dst, (0, 1), (10, 255));
            Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel == 10));

            SpanBitmap.CopyPixels(src, dst, (0, 1), (2, 3));
            Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel == 2));
        }
Beispiel #10
0
        public void CopyRGBPixels()
        {
            var src = new MemoryBitmap <Vector3>(177, 177).Slice((10, 10, 150, 150));
            var dst = new MemoryBitmap <PixelBGR>(177, 177).Slice((10, 10, 150, 150));

            src.SetPixels(Vector3.One);

            Assert.IsTrue(SpanBitmap.ArePixelsEqual(src, src));

            SpanBitmap.CopyPixels(src, dst, (0, 128), (0, 255));
            Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel.Equals(new PixelBGR(128))));

            SpanBitmap.CopyPixels(src, dst, (0, 1), (10, 255));
            Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel.Equals(new PixelBGR(10))));

            SpanBitmap.CopyPixels(src, dst, (0, 1), (2, 3));
            Assert.IsTrue(dst.EnumeratePixels().All(p => p.Pixel.Equals(new PixelBGR(2))));

            Assert.IsTrue(SpanBitmap.ArePixelsEqual(dst, dst));
        }