Exemple #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());
        }
Exemple #2
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));
        }
Exemple #3
0
        public void TestReinterpretBitmaps()
        {
            var src = new MemoryBitmap<Pixel.BGRA32>(16, 16);

            src.SetPixel(0, 0, (255, 0, 0, 255));

            var dst = src.AsSpanBitmap().ReinterpretAs<Pixel.RGBA32>();            

            var p = dst.GetPixel(0, 0);

            Assert.AreEqual(0, p.R);
            Assert.AreEqual(0, p.G);
            Assert.AreEqual(255, p.B); // formerly R
            Assert.AreEqual(255, p.A);

            // float RGB to Vector3

            var bgr = new MemoryBitmap<Pixel.BGR96F>(16, 16);

            var xyz = bgr.AsSpanBitmap().ReinterpretAs<System.Numerics.Vector3>();
        }