Beispiel #1
0
        public void ThirtyTwoBitMaskBufferIsCopied()
        {
            var buffer = new byte[]
            {
                0, 0, 255, 255,
                255, 0, 0, 255,
                0, 0, 255, 255,
                255, 0, 0, 255,
                0, 0, 255, 255,
                255, 0, 0, 255,
                0, 0, 255, 255,
                255, 0, 0, 255
            };
            var    bounds   = new SKRectI(0, 0, 4, 2);
            UInt32 rowBytes = 16;
            var    format   = SKMaskFormat.Argb32;

            var mask = SKMask.Create(buffer, bounds, rowBytes, format);

            var red  = SKColors.Red;
            var blue = SKColors.Blue;

            Assert.Equal((uint)red, mask.GetAddr32(0, 0));
            Assert.Equal((uint)blue, mask.GetAddr32(1, 0));
            Assert.Equal((uint)red, mask.GetAddr32(2, 0));
            Assert.Equal((uint)blue, mask.GetAddr32(3, 0));
            Assert.Equal((uint)red, mask.GetAddr32(0, 1));
            Assert.Equal((uint)blue, mask.GetAddr32(1, 1));
            Assert.Equal((uint)red, mask.GetAddr32(2, 1));
            Assert.Equal((uint)blue, mask.GetAddr32(3, 1));

            mask.FreeImage();
        }
Beispiel #2
0
        public void MonochromeMaskBufferIsCopied()
        {
            byte   rawMask  = 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1;
            var    buffer   = new byte[] { rawMask };
            var    bounds   = new SKRectI(0, 0, 8, 1);
            UInt32 rowBytes = 1;
            var    format   = SKMaskFormat.BW;

            var mask = SKMask.Create(buffer, bounds, rowBytes, format);

            Assert.Equal(rawMask, mask.GetAddr1(0, 0));

            mask.FreeImage();
        }
Beispiel #3
0
        public unsafe void FixedImageMaskIsHandledCorrectly()
        {
            byte   rawMask  = 1 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 1 << 3 | 0 << 2 | 1 << 1 | 1;
            var    buffer   = new byte[] { rawMask };
            var    bounds   = new SKRectI(0, 0, 8, 1);
            UInt32 rowBytes = 1;
            var    format   = SKMaskFormat.BW;

            var mask = SKMask.Create(buffer, bounds, rowBytes, format);

            Assert.Equal(rawMask, mask.GetAddr1(0, 0));

            mask.FreeImage();
        }
        public void AlphaMaskIsApplied()
        {
            var srcInfo = new SKImageInfo(4, 4);
            var srcBmp  = new SKBitmap(srcInfo);

            srcBmp.Erase(SKColors.Red);
            var pixels = srcBmp.Pixels;

            foreach (var pixel in pixels)
            {
                Assert.AreEqual(255, pixel.Alpha);
            }

            var maskBuffer = new byte[]
            {
                128, 127, 126, 125,
                101, 102, 103, 104,
                96, 95, 94, 93,
                72, 73, 74, 75
            };
            var  bounds   = new SKRectI(0, 0, 4, 4);
            uint rowBytes = 4;
            var  format   = SKMaskFormat.A8;
            var  mask     = SKMask.Create(maskBuffer, bounds, rowBytes, format);

            srcBmp.InstallMaskPixels(mask);

            pixels = srcBmp.Pixels;
            Assert.AreEqual(128, pixels[0].Alpha);
            Assert.AreEqual(127, pixels[1].Alpha);
            Assert.AreEqual(126, pixels[2].Alpha);
            Assert.AreEqual(125, pixels[3].Alpha);
            Assert.AreEqual(101, pixels[4].Alpha);
            Assert.AreEqual(102, pixels[5].Alpha);
            Assert.AreEqual(103, pixels[6].Alpha);
            Assert.AreEqual(104, pixels[7].Alpha);
            Assert.AreEqual(96, pixels[8].Alpha);
            Assert.AreEqual(95, pixels[9].Alpha);
            Assert.AreEqual(94, pixels[10].Alpha);
            Assert.AreEqual(93, pixels[11].Alpha);
            Assert.AreEqual(72, pixels[12].Alpha);
            Assert.AreEqual(73, pixels[13].Alpha);
            Assert.AreEqual(74, pixels[14].Alpha);
            Assert.AreEqual(75, pixels[15].Alpha);

            mask.FreeImage();
        }
Beispiel #5
0
        public void Alpha8MaskBufferIsCopied()
        {
            var    buffer   = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var    bounds   = new SKRectI(0, 0, 4, 2);
            UInt32 rowBytes = 4;
            var    format   = SKMaskFormat.A8;

            var mask = SKMask.Create(buffer, bounds, rowBytes, format);

            Assert.Equal(buffer[0], mask.GetAddr8(0, 0));
            Assert.Equal(buffer[1], mask.GetAddr8(1, 0));
            Assert.Equal(buffer[2], mask.GetAddr8(2, 0));
            Assert.Equal(buffer[3], mask.GetAddr8(3, 0));
            Assert.Equal(buffer[4], mask.GetAddr8(0, 1));
            Assert.Equal(buffer[5], mask.GetAddr8(1, 1));
            Assert.Equal(buffer[6], mask.GetAddr8(2, 1));
            Assert.Equal(buffer[7], mask.GetAddr8(3, 1));

            mask.FreeImage();
        }