Ejemplo n.º 1
0
        public void OpInequalityTest001()
        {
            int   width  = 16;
            int   height = 16;
            Pixel color  = Pixel.BlackPixel;
            Pixel spixel = new Pixel(127, 127, 127);
            sbyte scolor = 127;

            Bitmap bmp = new Bitmap();

            bmp.Init(height, width, 0);
            bmp.Fill(scolor);

            IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.BlackPixel);
            IPixelMap map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.GreenPixel);
            IPixelMap map3 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.RedPixel);

            PixelReference pix1  = (PixelReference)map1.CreateGPixelReference(0);
            PixelReference pix2  = (PixelReference)map2.CreateGPixelReference(0);
            PixelReference pix3  = (PixelReference)map3.CreateGPixelReference(0);
            PixelReference pix4  = (PixelReference)bmp.CreateGPixelReference(0);
            PixelReference pix11 = (PixelReference)pix1.Duplicate();
            PixelReference pix21 = (PixelReference)pix2.Duplicate();
            PixelReference pix31 = (PixelReference)pix3.Duplicate();

            Assert.True(pix1 != pix2);
            Assert.False(pix1 != pix11);
            Assert.True(pix3 != pix2);
            Assert.False(pix2 != pix21);
            Assert.True(pix3 != pix1);
            Assert.False(pix3 != pix31);
            Assert.True(pix3 != (PixelReference)null);
            Assert.True((PixelReference)null != pix3);
        }
Ejemplo n.º 2
0
        public void DuplicateTest001()
        {
            int   width  = 32;
            int   height = 32;
            Pixel color  = Pixel.RedPixel;

            Bitmap bmp = new Bitmap();

            bmp.Init(height, width, 0);
            bmp.Fill(-70);

            PixelReference pix = (PixelReference)bmp.CreateGPixelReference(0);

            pix.SetOffset(10, 16);

            var pix2 = (PixelReference)pix.Duplicate();

            Assert.Equal(pix.Offset, pix2.Offset);
            Assert.Same(pix.Parent, pix2.Parent);
            Assert.Equal(pix.ColorNumber, pix2.ColorNumber);
            Assert.True(pix == pix2);
            pix.SetGray(90);
            pix.IncOffset();
            Assert.True(pix != pix2);
            pix2.IncOffset();
            Assert.True(pix == pix2);
            pix2.SetBGR(0x00ffffff);
            Assert.True((Pixel)pix.ToPixel() == Pixel.WhitePixel);
        }
Ejemplo n.º 3
0
        public void OffsetTest001()
        {
            int   width  = 32;
            int   height = 32;
            Pixel color  = Pixel.BluePixel;

            IPixelMap      map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color);
            PixelReference pix  = (PixelReference)map1.CreateGPixelReference(0);

            pix.Offset = 3 * width;
            Assert.Equal(3 * width, pix.Offset);
        }
Ejemplo n.º 4
0
        public void RedOffsetTest()
        {
            int   width  = 256;
            int   height = 256;
            Pixel color  = Pixel.BluePixel;

            IPixelMap      map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color);
            PixelReference pix  = (PixelReference)map1.CreateGPixelReference(0);

            Assert.Equal(2, pix.RedOffset);
            pix.RedOffset = 0;
            Assert.Equal(0, pix.RedOffset);
        }
Ejemplo n.º 5
0
        public virtual Graphics.PixelMap GetPixmap(int subsample, Rectangle rect, Graphics.PixelMap retval)
        {
            if (_ymap == null)
            {
                return(null);
            }

            if (retval == null)
            {
                retval = new Graphics.PixelMap();
            }

            int w      = rect.Width;
            int h      = rect.Height;
            int pixsep = 3;
            int rowsep = w * pixsep;

            sbyte[] bytes = retval.Init(h, w, null).Data;

            _ymap.Image(subsample, rect, 0, bytes, rowsep, pixsep, false);

            if ((_crmap != null) && (_cbmap != null) && (_crcbDelay >= 0))
            {
                _cbmap.Image(subsample, rect, 1, bytes, rowsep, pixsep, _crcbHalf);
                _crmap.Image(subsample, rect, 2, bytes, rowsep, pixsep, _crcbHalf);
            }

            PixelReference pixel = retval.CreateGPixelReference(0);

            for (int i = 0; i < h;)
            {
                pixel.SetOffset(i++, 0);

                if ((_crmap != null) && (_cbmap != null) && (_crcbDelay >= 0))
                {
                    pixel.YCC_to_RGB(w);
                }
                else
                {
                    for (int x = w; x-- > 0; pixel.IncOffset())
                    {
                        pixel.SetGray((sbyte)(127 - pixel.Blue));
                    }
                }
            }

            return(retval);
        }
Ejemplo n.º 6
0
        public void ParentTest()
        {
            int   width  = 256;
            int   height = 256;
            Pixel color  = Pixel.BluePixel;

            IPixelMap      map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color);
            IPixelMap      map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color);
            PixelReference pix  = (PixelReference)map1.CreateGPixelReference(0);

            Assert.Same(pix.Parent, map1);
            pix.Parent = map2;
            Assert.NotSame(map1, map2);
            Assert.NotSame(pix.Parent, map1);
            Assert.Same(pix.Parent, map2);
        }
Ejemplo n.º 7
0
        public virtual Graphics.PixelMap GetPixmap()
        {
            if (_ymap == null)
            {
                return(null);
            }

            int w      = _ymap.Iw;
            int h      = _ymap.Ih;
            int pixsep = 3;
            int rowsep = w * pixsep;

            sbyte[] bytes = new sbyte[h * rowsep];

            _ymap.Image(0, bytes, rowsep, pixsep, false);

            if ((_crmap != null) && (_cbmap != null) && (_crcbDelay >= 0))
            {
                _cbmap.Image(1, bytes, rowsep, pixsep, _crcbHalf);
                _crmap.Image(2, bytes, rowsep, pixsep, _crcbHalf);
            }

            // Convert image to RGB
            Graphics.PixelMap ppm   = new Graphics.PixelMap().Init(bytes, h, w);
            PixelReference    pixel = ppm.CreateGPixelReference(0);

            for (int i = 0; i < h;)
            {
                pixel.SetOffset(i++, 0);

                if ((_crmap != null) && (_cbmap != null) && (_crcbDelay >= 0))
                {
                    pixel.YCC_to_RGB(w);
                }
                else
                {
                    for (int x = w; x-- > 0; pixel.IncOffset())
                    {
                        pixel.SetGray((sbyte)(127 - pixel.Blue));
                    }
                }
            }

            return(ppm);
        }
Ejemplo n.º 8
0
        public void EqualsPixelReference()
        {
            int   width  = 16;
            int   height = 16;
            Pixel color  = Pixel.BluePixel;

            IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color);
            IPixelMap map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color);
            IPixelMap map3 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.BlackPixel);

            PixelReference pix1 = (PixelReference)map1.CreateGPixelReference(0);
            PixelReference pix2 = (PixelReference)map2.CreateGPixelReference(0);
            PixelReference pix3 = (PixelReference)map3.CreateGPixelReference(0);

            Assert.True(pix1.Equals(pix2));
            Assert.False(pix1.Equals(pix3));
            Assert.False(pix1.Equals((PixelReference)null));
        }
Ejemplo n.º 9
0
        public void SetBGRTest001()
        {
            int   width  = 32;
            int   height = 32;
            Pixel color  = Pixel.RedPixel;

            var map = PixelMapTests.CreateInitVerifyPixelMap(width, height, color);

            PixelReference pix = (PixelReference)map.CreateGPixelReference(0);

            pix.SetOffset(10, 16);

            pix.SetBGR(0xafcfdf);
            Pixel testColor = new Pixel(0xafcfdf);

            Assert.True((Pixel)pix.ToPixel() == testColor);
            pix.SetOffset(10, 15);
            Assert.False((Pixel)pix.ToPixel() == testColor);
            pix.SetOffset(10, 17);
            Assert.False((Pixel)pix.ToPixel() == testColor);
        }