Esempio n. 1
0
        public override bool export(string filename)
        {
            XmlDocument doc = BPalette.getXmlDoc("bassru-text");

            for (int i = 0; i < blockCount; i++)
            {
                XmlElement blk = (XmlElement)doc.DocumentElement.AppendChild(doc.CreateElement("block"));
                blk.Attributes.Append(doc.CreateAttribute("id")).Value = i.ToString();
                for (int j = 0; j < (i == blockCount - 1?lastblksz:32); j++)
                {
                    XmlElement t = (XmlElement)blk.AppendChild(doc.CreateElement("text"));
                    t.Attributes.Append(doc.CreateAttribute("id")).Value = j.ToString();
                    string cmt  = "";
                    bool   isRu = Config.get().isTextRu(filenum, i, j, ref cmt);
                    if (cmt != "" || isRu)
                    {
                        t.Attributes.Append(doc.CreateAttribute("comment")).Value = cmt;
                        t.Attributes.Append(doc.CreateAttribute("mode")).Value    = isRu ? "ru" : "en";
                    }
                    t.AppendChild(doc.CreateTextNode(getText(i, j, isRu)));
                }
            }
            doc.Save(filename);
            return(true);
        }
Esempio n. 2
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. 3
0
 public static BPalette GrayScalePalette()
 {
     if (gsp == null)
     {
         gsp = new BPalette();
     }
     return(gsp);
 }
Esempio n. 4
0
        private void paletteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 1)
            {
                return;
            }
            uint      fid  = uint.Parse(listView1.SelectedItems[0].SubItems[0].Text);
            String    men  = (sender as ToolStripMenuItem).Text;
            BResource bres = null;

            try
            {
                switch (men)
                {
                case "Palette": bres = new BPalette(fid, ""); break;

                case "Image": bres = new BImage(fid, 320, 200, "", 0); break;

                case "Sequence": bres = new BSequence(fid, "", "aqua"); break;

                case "Sprites": bres = new BSprites(fid, ""); break;

                case "Charset": bres = new BCharset(fid, 8, 0); break;

                case "Text": bres = new BText(fid); break;

                case "Script": bres = new BScripts(fid); break;

                case "Speech": bres = new BSpeech(fid); break;

                case "Sound": bres = new BSound(fid); break;
                }
            }
            catch (Exception ex)
            {
                bres = null;
                MessageBox.Show("Error creating resource.\n" + ex.GetType().Name + ":\n" + ex.Message);
            }
            if (bres != null)
            {
                clearRes();
                cntrl = bres.control;
                if (cntrl != null)
                {
                    panel1.Controls.Add(cntrl);
                    bres.initControl();
                }
            }
        }
Esempio n. 5
0
 public BPalette findPalette(String name, bool def)
 {
     foreach (PaletteInfo p in palettes)
     {
         if (p.name == name)
         {
             return(p.pal);
         }
     }
     if (def)
     {
         return(BPalette.GrayScalePalette());
     }
     return(null);
 }
Esempio n. 6
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. 7
0
 public PaletteInfo(XmlElement node, int mode)
 {
     if (node == null)
     {
         pal  = BPalette.GrayScalePalette();
         name = pal.name;
         fid  = 0;
         return;
     }
     if (mode == 0)
     {
         pal  = (BPalette)BResourceHelper.getResource(node);
         name = pal.name;
         fid  = pal.filenum;
     }
     else
     {
         pal  = new BPalette(node);
         name = pal.name;
         fid  = 0;
     }
 }
Esempio n. 8
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. 9
0
 public PaletteInfo(XmlElement node,int mode)
 {
     if (node == null)
     {
         pal = BPalette.GrayScalePalette();
         name = pal.name;
         fid = 0;
         return;
     }
     if (mode == 0)
     {
         pal = (BPalette)BResourceHelper.getResource(node);
         name = pal.name;
         fid = pal.filenum;
     }
     else
     {
         pal = new BPalette(node);
         name = pal.name;
         fid = 0;
     }
 }
Esempio n. 10
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. 11
0
 public Bitmap getBmp(int width, int height, BPalette palette, int mode)
 {
     return(get32bitBitmap(width, height, palette, imagedata, mode));
 }
Esempio n. 12
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. 13
0
 private void paletteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count!=1) return;
     uint fid = uint.Parse(listView1.SelectedItems[0].SubItems[0].Text);
     String men = (sender as ToolStripMenuItem).Text;
     BResource bres = null;
     try
     {
         switch (men)
         {
             case "Palette": bres = new BPalette(fid, ""); break;
             case "Image": bres = new BImage(fid, 320, 200, "",0); break;
             case "Sequence": bres = new BSequence(fid, "", "aqua"); break;
             case "Sprites": bres = new BSprites(fid, ""); break;
             case "Charset": bres = new BCharset(fid, 8, 0); break;
             case "Text": bres = new BText(fid); break;
             case "Script": bres = new BScripts(fid); break;
             case "Speech": bres = new BSpeech(fid); break;
             case "Sound": bres = new BSound(fid); break;
         }
     }
     catch(Exception ex)
     {
         bres = null;
         MessageBox.Show("Error creating resource.\n"+ex.GetType().Name+":\n"+ex.Message);
     }
     if (bres != null)
     {
         clearRes();
         cntrl = bres.control;
         if (cntrl!=null)
         {
             panel1.Controls.Add(cntrl);
             bres.initControl();
         }
     }
 }
Esempio n. 14
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. 15
0
 public static BPalette GrayScalePalette()
 {
     if (gsp == null) gsp = new BPalette();
     return gsp;
 }
Esempio n. 16
0
 public Bitmap getBmp(int width, int height, BPalette palette, int mode)
 {
     return get32bitBitmap(width, height, palette, imagedata, mode);
 }
Esempio n. 17
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. 18
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;
 }