Ejemplo n.º 1
0
 public PixelData(int width, int height, int bytesPerPixel, byte[] raw, GetPixelDelegate getPixel, SetPixelDelegate setPixel)
 {
     Width         = width;
     Height        = height;
     BytesPerPixel = bytesPerPixel;
     Raw           = raw;
     _setPixel     = setPixel;
     _getPixel     = getPixel;
 }
Ejemplo n.º 2
0
        public static void SetPixel(
            int x,
            int y,
            int texWidth,
            int texHeight,
            SetPixelDelegate setPixelDelegate,
            int rad = 2)
        {
            if (x + rad < 0 || y + rad < 0)
            {
                return;
            }

            if (x - rad >= texWidth || y - rad >= texHeight)
            {
                return;
            }

            int dx_start = x - rad >= 0 ? -rad : -x;
            int dx_end   = x + rad < texWidth ? rad : texWidth - x - 1;
            int dy_start = y - rad >= 0 ? -rad : -y;
            int dy_end   = y + rad < texHeight ? rad : texHeight - y - 1;

            int rad_sq = rad * rad;

            for (int dx = dx_start; dx <= dx_end; dx++)
            {
                int cur_x = x + dx;
                int dx_sq = dx * dx;
                for (int dy = dy_start; dy <= dy_end; dy++)
                {
                    if (dx_sq + dy * dy <= rad_sq)
                    {
                        setPixelDelegate(cur_x, y + dy);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void SetGraphicsMode(ScreenSize aSize, ColorDepth aDepth)
        {
            switch (aSize)
            { 
                case ScreenSize.Size320x200:
                    if (aDepth == ColorDepth.BitDepth8)
                    {
                        WriteVGARegisters(g_320x200x8);

                        PixelWidth = 320;
                        PixelHeight = 200;
                        Colors = 256;
                        SetPixel = new SetPixelDelegate(SetPixel320x200x8);
                        GetPixel = new GetPixelDelegate(GetPixel320x200x8);
                    }
                    else if (aDepth == ColorDepth.BitDepth4)
                    {
                        WriteVGARegisters(g_320x200x4);

                        PixelWidth = 320;
                        PixelHeight = 200;
                        Colors = 16;
                        //SetPixel = new SetPixelDelegate(SetPixel320x200x4);
                        //GetPixel = new GetPixelDelegate(GetPixel320x200x4);
                    }
                    else throw new Exception("Unsupported color depth passed for specified screen size");
                    break;
                case ScreenSize.Size640x480:
                    if (aDepth == ColorDepth.BitDepth2)
                    {
                        WriteVGARegisters(g_640x480x2);

                        PixelWidth = 640;
                        PixelHeight = 480;
                        Colors = 4;
                        //SetPixel = new SetPixelDelegate(SetPixel640x480x2);
                        //GetPixel = new GetPixelDelegate(GetPixel640x480x2);
                    }
                    else if (aDepth == ColorDepth.BitDepth4)
                    {
                        WriteVGARegisters(g_640x480x4);

                        PixelWidth = 640;
                        PixelHeight = 480;
                        Colors = 16;
                        SetPixel = new SetPixelDelegate(SetPixel640x480x4);
                        GetPixel = new GetPixelDelegate(GetPixel640x480x4);
                    }
                    else throw new Exception("Unsupported color depth passed for specified screen size");
                    break;
                case ScreenSize.Size720x480:
                    if (aDepth == ColorDepth.BitDepth4)
                    {
                        WriteVGARegisters(g_720x480x4);

                        PixelWidth = 720;
                        PixelHeight = 480;
                        Colors = 16;
                        SetPixel = new SetPixelDelegate(SetPixel720x480x4);
                        GetPixel = new GetPixelDelegate(GetPixel720x480x4);
                    }
                    else throw new Exception("Unsupported color depth passed for specified screen size");
                    break;
                default:
                    throw new Exception("Unknown screen size");
            }
        }
Ejemplo n.º 4
0
 public VGAScreen()
 {
     SetPixel = new SetPixelDelegate(SetPixelNoMode);
     GetPixel = new GetPixelDelegate(GetPixelNoMode);
 }
Ejemplo n.º 5
0
        public static void SetMode640x480x4()
        {
            WriteVGARegisters(g_640x480x16);

            PixelWidth = 640;
            PixelHeight = 480;
            Colors = 16;
            SetPixel = new SetPixelDelegate(SetPixel640x480x4);
        }
Ejemplo n.º 6
0
        public static void SetMode320x200x8()
        {
            WriteVGARegisters(g_320x200x256);

            PixelWidth = 320;
            PixelHeight = 200;
            Colors = 256;
            SetPixel = new SetPixelDelegate(SetPixel320x200x8);
        }
Ejemplo n.º 7
0
    public static void DrawLine(Texture2D tex, Point2D p1, Point2D p2, Color color, SetPixelDelegate setPixel)
    {
        int x1 = p1.X;
        int y1 = p1.Y;
        int x2 = p2.X;
        int y2 = p2.Y;

        // zmienne pomocnicze
         	int d, dx, dy, ai, bi, xi, yi;
         	int x = x1, y = y1;
         	// ustalenie kierunku rysowania
         	if (x1 < x2)
         	{
         	xi = 1;
         	dx = x2 - x1;
         	}
         	else
        {
            xi = -1;
            dx = x1 - x2;
        }
        // ustalenie kierunku rysowania
        if (y1 < y2)
        {
            yi = 1;
            dy = y2 - y1;
        }
        else
        {
            yi = -1;
            dy = y1 - y2;
        }
        // pierwszy piksel
        if (x >= tex.width || x < 0 || y >= tex.height || y < 0)
            return;
        setPixel(new Point2D(x, y), color);
        // oś wiodąca OX
        if (dx > dy)
        {
            ai = (dy - dx) * 2;
            bi = dy * 2;
            d = bi - dx;
            // pętla po kolejnych x
            while (x != x2)
            {
                // test współczynnika
                if (d >= 0)
                {
                    x += xi;
                    y += yi;
                    d += ai;
                }
                else
                {
                    d += bi;
                    x += xi;
                }
                if (x >= tex.width || x < 0 || y >= tex.height || y < 0)
                    return;
                setPixel(new Point2D(x, y), color);
            }
        }
        // oś wiodąca OY
        else
        {
            ai = ( dx - dy ) * 2;
            bi = dx * 2;
            d = bi - dy;
            // pętla po kolejnych y
            while (y != y2)
            {
                // test współczynnika
                if (d >= 0)
                {
                    x += xi;
                    y += yi;
                    d += ai;
                }
                else
                {
                    d += bi;
                    y += yi;
                }
                if (x >= tex.width || x < 0 || y >= tex.height || y < 0)
                    return;
                setPixel(new Point2D(x, y), color);
            }
        }
    }