Exemple #1
0
        public static SurfaceCollection LoadSurfaces(string resourceName, Size tileSize)
        {
            SurfaceCollection ret = new SurfaceCollection();
            ret.AlphaBlending = true;

            using (Surface s = LoadSurface(resourceName))
            {
                for (int i = 0; i < s.Width; i += tileSize.Width)
                {
                    for (int j = 0; j < s.Height; j += tileSize.Height)
                    {
                        Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
                        ss.Transparent = true;
                        ss.AlphaBlending = true;
                        Color[,] tmp = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
                        ss.SetPixels(Point.Empty, tmp);
                        tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
                        ss.Update();
                        ret.Add(ss);
                    }
                }
            }
            return ret;
        }
Exemple #2
0
        public static SurfaceCollection LoadSurfacesFromFile(string filePath, Size tileSize)
        {
            SurfaceCollection ret = new SurfaceCollection();
            ret.AlphaBlending = true;
            if (!File.Exists(filePath)) return ret;

            using (Bitmap bmp = (Bitmap)Bitmap.FromFile(filePath))
            {
                using (Surface s = new Surface(bmp))
                {
                    s.Lock();
                    for (int i = 0; i < s.Width; i += tileSize.Width)
                    {
                        for (int j = 0; j < s.Height; j += tileSize.Height)
                        {
                            Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
                            ss.Transparent = true;
                            ss.AlphaBlending = true;

                            Color[,] tmp = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
                            ss.Lock();
                            ss.SetPixels(Point.Empty, tmp);
                            tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
                            ss.Unlock();
                            ss.Update();
                            ret.Add(ss);
                        }
                    }
                    s.Unlock();
                }
            }

            return ret;
        }
Exemple #3
0
 public static void SetAlpha(Surface s, float a)
 {
     if (s == null) return;
     Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
     s.Lock();
     for (int i = 0; i < colors.GetLength(0); i++)
     {
         for (int j = 0; j < colors.GetLength(1); j++)
         {
             Color c = colors[i, j];
             int na = (int)(c.A * a);
             colors[i, j] = Color.FromArgb(na < 0 ? 0 : (na > 255 ? 255 : na), c.R, c.G, c.B);
         }
     }
     s.SetPixels(Point.Empty, colors);
     s.Unlock();
     s.Update();
 }
Exemple #4
0
 public static void SetColor(Surface s, Color c)
 {
     if (s == null) return;
     Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
     s.Lock();
     for (int i = 0; i < colors.GetLength(0); i++)
     {
         for (int j = 0; j < colors.GetLength(1); j++)
         {
             colors[i, j] = Color.FromArgb(colors[i, j].A, c.R, c.G, c.B);
         }
     }
     s.SetPixels(Point.Empty, colors);
     s.Unlock();
     s.Update();
 }
Exemple #5
0
        public static Surface CreateColored(Surface s, Color c0, Color c1)
        {
            if (s == null) return null;
            Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));

            for (int i = 0; i < colors.GetLength(0); i++)
            {
                for (int j = 0; j < colors.GetLength(1); j++)
                {
                    Color c = colors[i, j];
                    float br = (c.R / 255.0f + c.G / 255.0f + c.B / 255.0f) / 3.0f;
                    if (br > 0.8f)
                    {
                        br = 1.0f;
                    }
                    else if (br < 0.2f)
                    {
                        br = 0.0f;
                    }
                    int r = (int)((1 - br) * c0.R + br * c1.R);
                    int g = (int)((1 - br) * c0.G + br * c1.G);
                    int b = (int)((1 - br) * c0.B + br * c1.B);
                    r = r < 0 ? 0 : (r > 255 ? 255 : r);
                    g = g < 0 ? 0 : (g > 255 ? 255 : g);
                    b = b < 0 ? 0 : (b > 255 ? 255 : b);
                    colors[i, j] = Color.FromArgb(c.A, r, g, b);
                    Color nc = Color.FromArgb(c.A, r, g, b);
                }
            }

            Surface ns = new Surface(s.Width, s.Height, s.BitsPerPixel, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
            ns.AlphaBlending = s.AlphaBlending;
            ns.Alpha = s.Alpha;
            ns.Transparent = s.Transparent;
            ns.TransparentColor = s.TransparentColor;

            ns.Lock();
            ns.SetPixels(Point.Empty, colors);
            ns.Unlock();
            ns.Update();
            return ns;
        }
Exemple #6
0
        public virtual void Render(Surface s, Rectangle r)
        {
            if (_startLineSurface == null)
            {
#warning パフォーマンスチェック
                using (Surface ts = ResourceManager.LargePFont.Render("START", _foreColor, true))
                {
                    _startLineSurface = new Surface(ts.Width + 20, view.Height, 32, ts.RedMask, ts.GreenMask, ts.BlueMask, ts.AlphaMask);

                    Color[,] tmp = ts.GetColors(new Rectangle(0, 0, ts.Width, ts.Height));
                    for (int i = 0; i < tmp.GetLength(0); i++)
                    {
                        for (int j = 0; j < tmp.GetLength(1); j++)
                        {
                            Color c = tmp[i, j];
                            tmp[i, j] = Color.FromArgb((int)(c.A / 2.0), c.R, c.G, c.B);
                        }
                    }
                    _startLineSurface.Lock();
                    _startLineSurface.SetPixels(new Point(20, (int)(_startLineSurface.Height / 2.0 - ts.Height / 2.0)), tmp);
                    _startLineSurface.Unlock();
                }
                _startLineSurface.Fill(new Rectangle(0, 0, 3, _startLineSurface.Height), Color.FromArgb(128, _foreColor.R, _foreColor.G, _foreColor.B));
                _startLineSurface.Update();
                _startLineSurface.AlphaBlending = true;
            }
            if (_goalLineSurface == null)
            {
                using (Surface ts = ResourceManager.LargePFont.Render("GOAL", _foreColor, true))
                {
                    _goalLineSurface = new Surface(ts.Width + 20, view.Height, 32, ts.RedMask, ts.GreenMask, ts.BlueMask, ts.AlphaMask);
                    Color[,] tmp = ts.GetColors(new Rectangle(0, 0, ts.Width, ts.Height));
                    for (int i = 0; i < tmp.GetLength(0); i++)
                    {
                        for (int j = 0; j < tmp.GetLength(1); j++)
                        {
                            Color c = tmp[i, j];
                            tmp[i, j] = Color.FromArgb((int)(c.A / 2.0), c.R, c.G, c.B);
                        }
                    }
                    _goalLineSurface.Lock();
                    _goalLineSurface.SetPixels(new Point(0, (int)(_goalLineSurface.Height / 2.0 - ts.Height / 2.0)), tmp);
                    _goalLineSurface.Unlock();
                }
                _goalLineSurface.Fill(new Rectangle(_goalLineSurface.Width - 3, 0, 3, _goalLineSurface.Height), Color.FromArgb(128, _foreColor.R, _foreColor.G, _foreColor.B));
                _goalLineSurface.Update();
                _goalLineSurface.AlphaBlending = true;
            }


            renderBackground(s, r);

            if (_startLineSurface.Width >= view.X && view.X + view.Width >= 0)
            {
                s.Blit(_startLineSurface, new Point(
                    (int)(r.X - view.X),
                    (int)(r.Y + view.Height / 2.0 - _startLineSurface.Height / 2.0)));
            }
            if (this.HasEnd)
            {
                if (this.Width >= view.X && view.X + view.Width >= this.Width - _goalLineSurface.Width)
                {
                    s.Blit(_goalLineSurface, new Point(
                        (int)(r.X + this.Width - _goalLineSurface.Width - view.X),
                        (int)(r.Y + view.Height / 2.0 - _goalLineSurface.Height / 2.0)));
                }
            }

            renderForeground(s, r);
        }
Exemple #7
0
        public static void decodeCursor(byte index, byte frame, ref Cursors_v2 cursorMan, ref Surface s)
        {
            // Icons!
            bool isCursor4 = index == 4;
            if (isCursor4)
                index--;

            V2_Cursor newCursor = cursorMan.cursors[index];

            byte[] backBuffer = new byte[/*cursor.width * cursor.height*/ 88 * 88 * 4 /** 2*/], cursorBuffer = new byte[backBuffer.Length];

            int backCtr = 0, cursorCtr = 0;

            int var64 = 0, var65 = 0;
            int ptr = 0;
            byte alpha = 0, palIdx = 0;

            byte r = 0, g = 0, b = 0;

            for (int y = 0; y < newCursor.height; y++)
            {
                for (int x = 0; x < newCursor.width; x++)
                {

                    /*if (px < cursor.width && py < cursor.height)
                    {*/
                    if (var64 == 0 && var65 == 0)
                    {
                        alpha = newCursor.frameData[frame][ptr];
                        ptr++;
                        if ((alpha & 0x80) == 0x80)
                        {
                            var64 = (alpha & 0x7f) + 1;
                        }
                        else
                        {
                            var65 = alpha + 1;
                            alpha = newCursor.frameData[frame][ptr];
                            palIdx = (byte)(alpha & 0x1F);
                            ptr++;
                            alpha &= 0xE0;
                        }
                    }

                    if (var64 > 0)
                    {
                        var64--;
                        palIdx = (byte)(newCursor.frameData[frame][ptr] & 0x1F);

                        r = newCursor.cursorData[0][palIdx];
                        g = newCursor.cursorData[1][palIdx];
                        b = newCursor.cursorData[2][palIdx];

                        alpha = (byte)(newCursor.frameData[frame][ptr] & 0xE0);

                        ptr++;
                    }
                    else
                    {
                        var65--;
                        r = newCursor.cursorData[0][palIdx];
                        g = newCursor.cursorData[1][palIdx];
                        b = newCursor.cursorData[2][palIdx];
                        //flag = 0palIdx
                    }
                    /*}
                    else { b = 0; }*/

                    switch (index)
                    {
                        case 0:
                        case 1:
                        case 2:
                        case 5:
                        case 7:
                        case 8:
                        case 0xD:
                        case 0xE:
                            //b = (byte)((uint)b * 5 / 4);
                            //b = (byte)((b >> 3) + (b >> 1));
                            //b = (byte)((uint)b * 5 / 8);
                            break;
                        default:
                            break;
                    }

                    if (alpha > 0 || 0 == 1) //var46 goes here
                    {
                        byte v71, v72, v73;
                        if (/*lots of stuff*/ false)
                        {
                            // direct byte copies
                        }
                        else
                        {

                            // pixel colour underneath goes here
                            v71 = 0;// 0xc8;
                            v72 = 0;// 0xfc;
                            v73 = 0;// 0xf8;
                        }
                        backBuffer[backCtr + 1] = v71;
                        backBuffer[backCtr + 2] = v72;
                        backBuffer[backCtr + 3] = v73;
                        backBuffer[backCtr] = 1;

                        if (isCursor4)
                        {
                            byte t = v71;
                            v71 = v73;
                            v73 = t;
                        }

                        if (alpha > 0)
                        {
                            if (alpha != 0xE0)
                            {
                                alpha = (byte)(((uint)alpha << 8) / 224);
                                r = (byte)((alpha * r + (256 - alpha) * v71) >> 8);
                                g = (byte)((alpha * g + (256 - alpha) * v72) >> 8);
                                b = (byte)((alpha * b + (256 - alpha) * v73) >> 8);

                            }
                        }
                        cursorBuffer[cursorCtr] = 1;
                        cursorBuffer[cursorCtr + 1] = r;
                        cursorBuffer[cursorCtr + 2] = g;
                        cursorBuffer[cursorCtr + 3] = b;
                    }
                    cursorCtr += 4;
                    backCtr += 4;
                }

            }

            /*
            for (int i = 0; i < cursor.height * cursor.width; i++, x++)
            {
                if (x >= cursor.width){
                    x = 0;
                    y++;
                }
                pix[x, y] = Color.FromArgb(cursor.frameData[0][i]);
            }
             * */

            // perform interlace magic
            Surface cSurf = new Surface(newCursor.width, newCursor.height);
            Color[,] pix = new Color[cSurf.Width, cSurf.Height];
            cursorCtr = 0;
            Color last = Color.Black;
            for (int y = 0; y < newCursor.height; y++)
            {
                for (int x = 0; x < newCursor.width; x++)
                {
                    if (cursorBuffer[cursorCtr] > 0)
                    {
                        //sub_406720(v9 + v13, v6 + v11, *(_BYTE*)(memBlockC + 1), *(_BYTE*)(memBlockC + 2), *(_BYTE*)(memBlockC + 3));
                        /*(unsigned __int8)(*(_BYTE *)v3 >> (3))
            + ((unsigned __int8)(*(_BYTE *)(v3 + 1) >> (2)) << 5)
            + ((unsigned __int8)(*(_BYTE *)(v3 + 2) >> (3)) << 0xb) */

                        /*
                         * inline static void YUV2RGB(byte y, byte u, byte v, byte &r, byte &g, byte &b) {
            r = CLIP<int>(y + ((1357 * (v - 128)) >> 10), 0, 255);
            g = CLIP<int>(y - (( 691 * (v - 128)) >> 10) - ((333 * (u - 128)) >> 10), 0, 255);
            b = CLIP<int>(y + ((1715 * (u - 128)) >> 10), 0, 255);*/
                        /*byte yy = memB[bctr + 1];
                        byte u = memB[bctr + 2];
                        byte v = memB[bctr + 3];
                        uint bb = (uint)(y + ((1357 * (v - 128)) >> 10));
                        uint g = (uint)(y - ((691 * (v - 128)) >> 10) - ((333 * (u - 128)) >> 10));
                        uint r = (uint)(y + ((1715 * (u - 128)) >> 10));

                         Color.FromArgb((byte)(r > 255 ? 255 : 0), (byte)(g > 255 ? 255 : g), (byte)(bb > 255 ? 255 : bb));*/

                        pix[x, y] = Color.FromArgb(cursorBuffer[cursorCtr + 1], cursorBuffer[cursorCtr + 2], cursorBuffer[cursorCtr + 3]);
                        last = pix[x, y];
                        cursorBuffer[cursorCtr] = 0;
                    }

                    cursorCtr += 4;
                }
            }
            cSurf.SetPixels(new Point(0, 0), pix);
            //cSurf.SaveBmp("h:\\test.bmp");
            s.Fill(Color.Black);
            s.Blit(cSurf, new Point(20, 20));
        }