コード例 #1
0
ファイル: PixelReferenceTests.cs プロジェクト: sahwar/DjvuNet
        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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }