Esempio n. 1
0
        public static Bitmap get8bitBitmap(int width, int height, BPalette palette, byte[] data, int mode)
        {
            if ((mode & 1) == 1)
            {
                data = switchMode1to0(data, ref width, ref height);
            }
            Bitmap       bmp    = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
            ColorPalette tmppal = bmp.Palette;

            Color[] cls = palette.getPal(true, false, ((mode & 2) != 0));
            for (int i = 0; i < 256; i++)
            {
                tmppal.Entries[i] = cls[i];
            }
            bmp.Palette = tmppal;
            BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height),
                                         ImageLockMode.WriteOnly, bmp.PixelFormat);

            for (int i = 0; i < height; i++)
            {
                System.Runtime.InteropServices.Marshal.Copy(data, i * bd.Width, new IntPtr(bd.Scan0.ToInt64() + i * bd.Stride), bd.Width);
            }
            bmp.UnlockBits(bd);
            return(bmp);
        }
Esempio n. 2
0
        public static byte[] import8bitBitmap(string filename, int width, int height, BPalette palette, int mode)
        {
            int w = width;
            int h = height;

            if ((mode & 1) == 1)
            {
                width  *= 16;
                height *= 8;
            }
            Bitmap bmp = new Bitmap(filename);

            if (bmp.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new ApplicationException("Bad bitmap pixel format");
            }
            if (bmp.Width != width || bmp.Height != height)
            {
                throw new ApplicationException("Bad Size");
            }
            int md = 0;

            Color[] cls = palette.getPal(true, false, ((mode & 2) != 0));
            for (int i = 0; i < 256 && md == 0; i++)
            {
                if (bmp.Palette.Entries[i] != cls[i])
                {
                    md = ResView.BResourceControl.askForBadPal();
                }
            }
            byte[]     res = new byte[width * height];
            BitmapData bd  = bmp.LockBits(new Rectangle(0, 0, width, height),
                                          ImageLockMode.ReadWrite, bmp.PixelFormat);

            for (int i = 0; i < height; i++)
            {
                System.Runtime.InteropServices.Marshal.Copy(new IntPtr(bd.Scan0.ToInt64() + i * bd.Stride), res, i * bd.Width, bd.Width);
            }
            bmp.UnlockBits(bd);
            if (mode == 1)
            {
                res = switchMode0to1(res, w, h);
            }
            return(res);
        }
Esempio n. 3
0
        public static Bitmap get32bitBitmap(int width, int height, BPalette palette, byte[] data, int mode)
        {
            width  *= (mode == 0?1:16);
            height *= (mode == 0?1:8);
            Bitmap   bmp = new Bitmap(width, height);
            Graphics g   = Graphics.FromImage(bmp);

            Color[] cls = palette.getPal(true, false, ((mode & 2) != 0));
            g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, width, height));
            if ((mode & 1) != 1)
            {
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        int idx = i * width + j;
                        if (data.Length > idx)
                        {
                            bmp.SetPixel(j, i, cls[data[idx]]);
                        }
                    }
                }
            }
            else
            {
                for (int k = 0; k < height / 8; k++)
                {
                    for (int m = 0; m < width / 16; m++)
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            for (int j = 0; j < 16; j++)
                            {
                                int idx = (k * width / 16 + m) * 8 * 16 + i * 16 + j;
                                if (data.Length > idx)
                                {
                                    bmp.SetPixel(m * 16 + j, k * 8 + i, cls[data[idx]]);
                                }
                            }
                        }
                    }
                }
            }
            return(bmp);
        }
Esempio n. 4
0
 public static Bitmap get32bitBitmap(int width, int height, BPalette palette, byte[] data, int mode)
 {
     width*=(mode==0?1:16);
     height*=(mode==0?1:8);
     Bitmap bmp = new Bitmap(width, height);
     Graphics g = Graphics.FromImage(bmp);
     Color[] cls = palette.getPal(true, false, ((mode & 2) != 0));
     g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, width, height));
     if ((mode&1) != 1)
     {
         for (int i=0;i<height;i++)
             for (int j = 0; j < width; j++)
             {
                 int idx = i * width + j;
                 if (data.Length > idx)
                     bmp.SetPixel(j, i, cls[data[idx]]);
             }
     }
     else
     {
         for (int k = 0; k < height/8; k++)
         {
             for (int m = 0; m < width/16; m++)
             {
                 for(int i=0;i<8;i++)
                     for (int j = 0; j < 16; j++)
                     {
                         int idx = (k * width/16 + m) * 8*16 + i * 16 + j;
                         if (data.Length > idx)
                             bmp.SetPixel(m*16+j,k*8+i,cls[data[idx]]);
                     }
             }
         }
     }
     return bmp;
 }
Esempio n. 5
0
        public Bitmap makeBitmap(Color bgColor, BPalette pal)
        {
            if (ucolor == -1)
            {
                throw new ApplicationException("No unused color");
            }
            Bitmap       bmp = new Bitmap(320, GAME_SCREEN_HEIGHT * screenCnt, PixelFormat.Format8bppIndexed);
            ColorPalette p   = bmp.Palette;

            for (int i = 0; i < 256; i++)
            {
                if (i == ucolor)
                {
                    p.Entries[i] = bgColor;
                }
                else
                {
                    p.Entries[i] = pal.getPal()[i];
                }
            }
            bmp.Palette = p;
            int        pos    = 1;
            int        scrpos = 0;
            int        scrsz  = 320 * GAME_SCREEN_HEIGHT;
            int        curscr = 0;
            BitmapData bd     = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                             ImageLockMode.WriteOnly, bmp.PixelFormat);

            while (pos < seqdata.Length)
            {
                while (scrpos < scrsz && pos < seqdata.Length)
                {
                    byte skp = 0;
                    do
                    {
                        skp = seqdata[pos++];
                        for (int i = 0; i < skp; i++)
                        {
                            putPixel(curscr, scrpos + i, bd, (byte)ucolor);
                        }
                        scrpos += skp;
                    } while (skp == 0xFF);
                    do
                    {
                        skp = seqdata[pos++];
                        for (int i = 0; i < skp; i++)
                        {
                            putPixel(curscr, scrpos + i, bd, seqdata[pos++]);
                        }
                        scrpos += skp;
                    } while (skp == 0xFF);
                    if (scrpos >= scrsz)
                    {
                        curscr++;
                        scrpos = 0;
                    }
                }
            }
            bmp.UnlockBits(bd);
            return(bmp);
        }
Esempio n. 6
0
 public Bitmap makeBitmap(Color bgColor, BPalette pal)
 {
     if (ucolor == -1)
         throw new ApplicationException("No unused color");
     Bitmap bmp = new Bitmap(320, GAME_SCREEN_HEIGHT * screenCnt,PixelFormat.Format8bppIndexed);
     ColorPalette p = bmp.Palette;
     for (int i = 0; i < 256; i++)
         if (i == ucolor)
             p.Entries[i] = bgColor;
         else
             p.Entries[i] = pal.getPal()[i];
     bmp.Palette = p;
     int pos = 1;
     int scrpos = 0;
     int scrsz = 320 * GAME_SCREEN_HEIGHT;
     int curscr = 0;
     BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                     ImageLockMode.WriteOnly, bmp.PixelFormat);
     while (pos < seqdata.Length)
     {
         while (scrpos < scrsz && pos < seqdata.Length)
         {
             byte skp = 0;
             do
             {
                 skp = seqdata[pos++];
                 for (int i = 0; i < skp; i++)
                     putPixel(curscr, scrpos+i, bd, (byte)ucolor);
                 scrpos += skp;
             } while (skp == 0xFF);
             do
             {
                 skp = seqdata[pos++];
                 for (int i = 0; i < skp; i++)
                     putPixel(curscr, scrpos + i, bd,seqdata[pos++]);
                 scrpos += skp;
             } while (skp == 0xFF);
             if (scrpos >= scrsz)
             {
                 curscr++;
                 scrpos = 0;
             }
         }
     }
     bmp.UnlockBits(bd);
     return bmp;
 }
Esempio n. 7
0
 public static byte[] import8bitBitmap(string filename,int width,int height,BPalette palette,int mode)
 {
     int w = width;
     int h = height;
     if ((mode &1)== 1)
     {
         width *= 16;
         height *= 8;
     }
     Bitmap bmp = new Bitmap(filename);
     if (bmp.PixelFormat != PixelFormat.Format8bppIndexed)
         throw new ApplicationException("Bad bitmap pixel format");
     if (bmp.Width != width || bmp.Height != height)
         throw new ApplicationException("Bad Size");
     int md=0;
     Color[] cls = palette.getPal(true, false, ((mode & 2) != 0));
     for (int i = 0; i < 256 && md == 0; i++)
         if (bmp.Palette.Entries[i] != cls[i])
             md = ResView.BResourceControl.askForBadPal();
     byte[] res = new byte[width * height];
     BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height),
         ImageLockMode.ReadWrite, bmp.PixelFormat);
     for (int i = 0; i < height; i++)
         System.Runtime.InteropServices.Marshal.Copy(new IntPtr(bd.Scan0.ToInt64()+i*bd.Stride), res, i * bd.Width, bd.Width);
     bmp.UnlockBits(bd);
     if (mode==1)
         res=switchMode0to1(res,w,h);
     return res;
 }
Esempio n. 8
0
 public static Bitmap get8bitBitmap(int width, int height, BPalette palette, byte[] data, int mode)
 {
     if ((mode & 1) == 1)
         data = switchMode1to0(data, ref width, ref height);
     Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
     ColorPalette tmppal = bmp.Palette;
     Color[] cls = palette.getPal(true, false, ((mode & 2) != 0));
     for (int i = 0; i < 256; i++)
         tmppal.Entries[i] = cls[i];
     bmp.Palette = tmppal;
     BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height),
         ImageLockMode.WriteOnly, bmp.PixelFormat);
     for (int i = 0; i < height; i++)
         System.Runtime.InteropServices.Marshal.Copy(data, i*bd.Width, new IntPtr(bd.Scan0.ToInt64()+i*bd.Stride), bd.Width);
     bmp.UnlockBits(bd);
     return bmp;
 }