Set() public method

public Set ( byte data, int length ) : void
data byte
length int
return void
Exemplo n.º 1
0
        public static void Fill(Surface surface, Rect r, int color)
        {
            r = new Rect(r.Left, r.Top, r.Right, r.Bottom);
            r.Clip(surface.Width, surface.Height);

            if (!r.IsValid)
            {
                return;
            }

            int  width     = r.Width;
            int  lineLen   = width;
            int  height    = r.Height;
            bool useMemset = true;

            var bpp = Surface.GetBytesPerPixel(surface.PixelFormat);

            if (bpp == 2)
            {
                lineLen *= 2;
                if ((ushort)color != ((color & 0xff) | (color & 0xff) << 8))
                {
                    useMemset = false;
                }
            }
            else if (bpp == 4)
            {
                useMemset = false;
            }
            else if (bpp != 1)
            {
                throw new InvalidOperationException("Surface::fillRect: bytesPerPixel must be 1, 2, or 4");
            }

            if (useMemset)
            {
                var pn = new PixelNavigator(surface);
                pn.GoTo(r.Left, r.Top);
                for (int i = 0; i < height; i++)
                {
                    pn.Set((byte)color, lineLen);
                    pn.OffsetY(1);
                }
            }
            else
            {
                if (bpp == 2)
                {
                    var pn = new PixelNavigator(surface);
                    pn.GoTo(r.Left, r.Top);
                    for (int i = 0; i < height; i++)
                    {
                        pn.Set((ushort)color, lineLen);
                        pn.OffsetX(surface.Width);
                    }
                }
                else
                {
                    var pn = new PixelNavigator(surface);
                    pn.GoTo(r.Left, r.Top);
                    for (int i = 0; i < height; i++)
                    {
                        pn.Set((uint)color, lineLen);
                        pn.OffsetX(surface.Width / 2);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void Fill(Surface surface, Rect r, int color)
        {
            r = new Rect(r.Left, r.Top, r.Right, r.Bottom);
            r.Clip(surface.Width, surface.Height);

            if (!r.IsValid)
                return;

            int width = r.Width;
            int lineLen = width;
            int height = r.Height;
            bool useMemset = true;

            var bpp = Surface.GetBytesPerPixel(surface.PixelFormat);
            if (bpp == 2)
            {
                lineLen *= 2;
                if ((ushort)color != ((color & 0xff) | (color & 0xff) << 8))
                    useMemset = false;
            }
            else if (bpp == 4)
            {
                useMemset = false;
            }
            else if (bpp != 1)
            {
                throw new InvalidOperationException("Surface::fillRect: bytesPerPixel must be 1, 2, or 4");
            }

            if (useMemset)
            {
                var pn = new PixelNavigator(surface);
                pn.GoTo(r.Left, r.Top);
                for (int i = 0; i < height; i++)
                {
                    pn.Set((byte)color, lineLen);
                    pn.OffsetY(1);
                }
            }
            else
            {
                if (bpp == 2)
                {
                    var pn = new PixelNavigator(surface);
                    pn.GoTo(r.Left, r.Top);
                    for (int i = 0; i < height; i++)
                    {
                        pn.Set((ushort)color, lineLen);
                        pn.OffsetX(surface.Width);
                    }
                }
                else
                {
                    var pn = new PixelNavigator(surface);
                    pn.GoTo(r.Left, r.Top);
                    for (int i = 0; i < height; i++)
                    {
                        pn.Set((uint)color, lineLen);
                        pn.OffsetX(surface.Width / 2);
                    }
                }
            }
        }