Esempio n. 1
0
        private void button8_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "CTR VRAM file|*.vrm";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Tim buf = CtrVrm.FromFile(ofd.FileName);

                MessageBox.Show(buf.data.Length / 256 + "");

                if (scn != null)
                {
                    Dictionary <string, TextureLayout> tex = scn.GetTexturesList();
                    MessageBox.Show(tex.Count.ToString());

                    foreach (TextureLayout tl in tex.Values)
                    {
                        //buf.GetTexturePage(tl, "");
                    }
                }

                buf.SaveBMP("test.bmp", BMPHeader.GrayScalePalette(16));
                //buf.palbmp.Save("palletes.png", System.Drawing.Imaging.ImageFormat.Png);

                //Process.Start("palletes.png");
            }
        }
Esempio n. 2
0
        private void button30_Click(object sender, EventArgs e)
        {
            Scene s = Scene.FromFile("test.lev");

            s.ctrvram.SaveBMP("before.bmp", BMPHeader.GrayScalePalette(16));

            s.ctrvram = new Tim(new Rectangle(0, 0, 1024, 512));

            foreach (var t in s.GetTexturesList())
            {
                if (File.Exists("test\\" + t.Value.Tag() + ".tim"))
                {
                    try
                    {
                        s.ctrvram.DrawTim(Tim.FromFile("test\\" + t.Value.Tag() + ".tim"));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

            s.ctrvram.SaveBMP("after.bmp", BMPHeader.GrayScalePalette(16));

            MessageBox.Show("done");
        }
Esempio n. 3
0
        private void button18_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "CTR VRAM file|*.vram";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Tim      buf = CtrVrm.FromFile(ofd.FileName);
                Bitmap   bmp = new Bitmap(160, 80);
                Graphics g   = Graphics.FromImage(bmp);

                using (BinaryReaderEx br2 = new BinaryReaderEx(File.Open("ui_map", FileMode.Open)))
                {
                    int           z    = br2.ReadInt32();
                    List <TexMap> list = new List <TexMap>();

                    for (int i = 0; i < 50; i++)
                    {
                        list.Add(new TexMap(br2));
                    }


                    int x = 0;
                    int y = 0;

                    foreach (TexMap map in list)
                    {
                        buf.GetTexture(map.tl, "tex", map.name);

                        Bitmap b = (Bitmap)Bitmap.FromFile("tex" + "\\" + map.name + ".png");

                        g.DrawImage(b, x * 16, y * 16);

                        x++;
                        if (x >= 10)
                        {
                            x = 0;
                            y++;
                        }
                    }

                    bmp.Save("font.png", System.Drawing.Imaging.ImageFormat.Png);
                }

                /*
                 *  Dictionary<string, TextureLayout> tex = scn.GetTexturesList();
                 *  MessageBox.Show(tex.Count.ToString());
                 * }
                 */

                buf.SaveBMP("test.bmp", BMPHeader.GrayScalePalette(16));
                //buf.palbmp.Save("palletes.png", System.Drawing.Imaging.ImageFormat.Png);

                Process.Start("font.png");
            }
        }
Esempio n. 4
0
        private static void ParseBytes(ref Stream file, ref BMPHeader bmpHeader)
        {
            // detailed info:
            // http://www.daubnet.com/en/file-format-bmp

            //every BMP header is 54 bytes, followed by the image data
            //SIZE of the BMP: 2 bytes in (4 bytes long)
            //WIDTH of the BMP: 18 bytes in (4 bytes long)...in pixels
            //HEIGHT of the BMP: 22 bytes in (4 bytes long)...in pixels

            //PIXELDATA starts 54 bytes in, each row is 8 bytes long

            //grabs B[2,3,4,5] for the Size
            byte[] size = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                            (byte)file.ReadByte(), (byte)file.ReadByte() };
            bmpHeader.Size = FormUint4(size);

            //current position is at Byte 6 => must go to 18

            // B[14,15,16,17]
            // size of header

            file.Position = 18;
            //grabs B[18,19,20,21] for the width
            byte[] width = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                             (byte)file.ReadByte(), (byte)file.ReadByte() };
            bmpHeader.Width = FormUint4(width);

            //grabs B[22,23,24,25] for the height
            byte[] height = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                              (byte)file.ReadByte(), (byte)file.ReadByte() };
            bmpHeader.Height = FormUint4(height);

            // B[26, 27] Planes

            //current position is at Byte 26 => must go to 28
            file.Position = 28;

            //grabs B[28,29] for the BitCount
            byte[] bitCount = { (byte)file.ReadByte(), (byte)file.ReadByte() };
            bmpHeader.BitCount = FormUint2(bitCount);

            // [30, 31, 32, 33] Compression
            // [34, 35, 36, 37] ImageSize


            //current position is at Byte 30 => must go to 54
            file.Position = 54;

            //craete the Color[] and copy it over to the bmpHeader
            BuildPixels(ref bmpHeader.Pixels, ref file, bmpHeader.BitCount, (int)bmpHeader.Width, (int)bmpHeader.Height);
        }
Esempio n. 5
0
    public static void Decode(ReadStream data, Bitmap dest)
    {
        BMPHeader header = data.Struct <BMPHeader>();

        Debug.Assert(header.Signature == BMPSignature, "Specified file was not a BMP file.");
        Debug.Assert(header.Size == InfoHeaderSize, "The BMP file contains an unsupported info header.");
        Debug.Assert(header.Compression == 0, "Only uncompressed BMP files are supported.");
        Debug.Assert(header.BitsPerPixel == 32, "Only 32-bit colors are supported.");
        Debug.Assert(header.FileSize - header.DataOffset == header.Width * header.Height * 4, "The BMP file is missing pixel data.");
        dest.Width  = header.Width;
        dest.Height = header.Height;
        dest.Pixels = RemapData(data.Read(dest.Width * dest.Height * 4), dest.Width, dest.Height);
    }
Esempio n. 6
0
        static void LoadTextureFile(string filename)
        {
            using (BinaryReaderEx br = new BinaryReaderEx(File.OpenRead(filename)))
            {
                TexPak x = new TexPak(br);

                Console.WriteLine(x.numPals + " " + x.numTex);

                string path = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename));

                Helpers.CheckFolder(path);

                int num = 0;

                foreach (Tex t in x.tex)
                {
                    BMPHeader b = new BMPHeader();
                    b.Update(t.width * 4, t.height, 16, 4);

                    byte[] pal = new byte[16 * 4];

                    bool bad = false;

                    int palindex = t.unk2 / 2;

                    if (palindex < 0 || palindex > x.pals.Count)
                    {
                        palindex = 0;
                        bad      = true;
                    }

                    for (int i = 0; i < 16; i++)
                    {
                        pal[i * 4 + 0] = x.pals[palindex][i].B;
                        pal[i * 4 + 1] = x.pals[palindex][i].G;
                        pal[i * 4 + 2] = x.pals[palindex][i].R;
                        pal[i * 4 + 3] = x.pals[palindex][i].A;
                    }


                    b.UpdateData(pal, Tim.FixPixelOrder(t.data));

                    using (BinaryWriterEx bw = new BinaryWriterEx(File.OpenWrite($"{path}\\tex_" + num + (bad ? "_badpal" : "") + ".bmp")))
                    {
                        b.Write(bw);
                    }

                    num++;
                }
            }
        }
Esempio n. 7
0
        private void actionExtract_Click(object sender, EventArgs e)
        {
            if (!File.Exists(pathFile.Text))
            {
                MessageBox.Show($"File doesn't exist!\r\n{pathFile.Text}");
                return;
            }

            using (Scene s = Scene.FromFile(pathFile.Text))
            {
                if (optionTexHigh.Checked)
                {
                    s.ExportTextures(Path.Combine(pathFileParent, "texHigh"), Detail.High);
                }
                if (optionTexMed.Checked)
                {
                    s.ExportTextures(Path.Combine(pathFileParent, "texMed"), Detail.Med);
                }
                if (optionTexLow.Checked)
                {
                    s.ExportTextures(Path.Combine(pathFileParent, "texLow"), Detail.Low);
                }
                if (optionTexModels.Checked)
                {
                    s.ExportTextures(Path.Combine(pathFileParent, "texModels"), Detail.Models);
                }

                //generates colored vram, keep in mind same texture data may use different palettes
                Bitmap   bmp = new Bitmap(2048, 512);
                Graphics g   = Graphics.FromImage(bmp);

                foreach (var x in s.GetTexturesList())
                {
                    using (Bitmap bb = s.ctrvram.GetTexture(x.Value))
                    {
                        if (bb != null)
                        {
                            g.DrawImage(bb, x.Value.RealX * 4 - 2048, x.Value.RealY);
                        }
                    }
                }

                bmp.Save(Path.Combine(pathFileParent, "test_color.bmp"));
                s.ctrvram.SaveBMP(Path.Combine(pathFileParent, "test_bw.bmp"), BMPHeader.GrayScalePalette(16));
            }

            GC.Collect();
            MessageBox.Show("Done!");
        }
Esempio n. 8
0
        public static void WriteStructToFile(string filename)
        {
            string saveToFilePath = @"D:\" + filename;

            int bytesWritten = 0;

            using (System.IO.FileStream myFileStream = new System.IO.FileStream(saveToFilePath, System.IO.FileMode.Create))
            {
                BMPHeader myData = new BMPHeader();

                byte[] newBuffer = GetBytes <BMPHeader>(myData);
                myFileStream.Write(newBuffer, 0, newBuffer.Length);
                bytesWritten += newBuffer.Length;
            }
        }
Esempio n. 9
0
    public static byte[] Encode(Bitmap bitmap)
    {
        byte[]    data   = new byte[bitmap.Pixels.Length + HeaderSize];
        BMPHeader header = new BMPHeader {
            Signature    = BMPSignature,
            FileSize     = (uint)data.Length,
            DataOffset   = (uint)HeaderSize,
            Size         = (uint)(InfoHeaderSize),
            Width        = bitmap.Width,
            Height       = bitmap.Height,
            Planes       = 1,
            BitsPerPixel = 32,
        };

        Array.Copy(header.ToBytes(), 0, data, 0, HeaderSize);
        Array.Copy(RemapData(bitmap.Pixels, bitmap.Width, bitmap.Height), 0, data, HeaderSize, bitmap.Pixels.Length);
        return(data);
    }
Esempio n. 10
0
        /// <summary>
        /// ImageData takes a fileName (string) and loads the BMP from the file.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns>a new ImageData, containing the width, height, and data of the BMP that was loaded</returns>
        public static ImageData GetPixelData(string fileName)
        {
            //Load the file into "byte stream"
            Stream sourceStream = new MemoryStream(LoadFile(fileName));

            //Check the signature to verify this is an actual .bmp image
            if (!CheckSignature(ref sourceStream))
            {
                throw new ArgumentException(
                          String.Format("Argument Stream {0} does not contain a valid BMP file.", sourceStream));
            }

            BMPHeader bmpHeader = new BMPHeader();

            ParseBytes(ref sourceStream, ref bmpHeader);
            FileManager.Close(sourceStream);

            return(new ImageData((int)bmpHeader.Width, (int)bmpHeader.Height, bmpHeader.Pixels));
        }
Esempio n. 11
0
        private static void ParseBytes(ref Stream file, ref BMPHeader bmpHeader)
        {
            //every BMP header is 54 bytes, followed by the image data
            //SIZE of the BMP: 2 bytes in (4 bytes long)
            //WIDTH of the BMP: 18 bytes in (4 bytes long)...in pixels
            //HEIGHT of the BMP: 22 bytes in (4 bytes long)...in pixels

            //PIXELDATA starts 54 bytes in, each row is 8 bytes long

            //grabs B[2,3,4,5] for the Size
            byte[] size = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                            (byte)file.ReadByte(), (byte)file.ReadByte() };
            bmpHeader.Size = FormUint4(size);

            //current position is at Byte 6 => must go to 18
            file.Position = 18;

            //grabs B[18,19,20,21] for the width
            byte[] width = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                             (byte)file.ReadByte(), (byte)file.ReadByte() };
            bmpHeader.Width = FormUint4(width);

            //grabs B[22,23,24,25] for the height
            byte[] height = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                              (byte)file.ReadByte(), (byte)file.ReadByte() };
            bmpHeader.Height = FormUint4(height);

            //current position is at Byte 26 => must go to 28
            file.Position = 28;

            //grabs B[28,29] for the BitCount
            byte[] bitCount = { (byte)file.ReadByte(), (byte)file.ReadByte() };
            bmpHeader.BitCount = FormUint2(bitCount);

            //current position is at Byte 30 => must go to 54
            file.Position = 54;

            //craete the Color[] and copy it over to the bmpHeader
            BuildPixels(ref bmpHeader.Pixels, ref file, bmpHeader.BitCount, (int)bmpHeader.Width, (int)bmpHeader.Height);
        }
Esempio n. 12
0
        /// <summary>
        /// ImageData takes a fileName (string) and loads the BMP from the file. 
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns>a new ImageData, containing the width, height, and data of the BMP that was loaded</returns>
        public static ImageData GetPixelData(string fileName)
        {
            //Load the file into "byte stream"
            Stream sourceStream = new MemoryStream(LoadFile(fileName));

            //Check the signature to verify this is an actual .bmp image
            if (!CheckSignature(ref sourceStream))
                throw new ArgumentException(
                    String.Format("Argument Stream {0} does not contain a valid BMP file.", sourceStream));

            BMPHeader bmpHeader = new BMPHeader();
            ParseBytes(ref sourceStream, ref bmpHeader);
            FileManager.Close(sourceStream);

            return new ImageData((int)bmpHeader.Width, (int)bmpHeader.Height, bmpHeader.Pixels);
        }
Esempio n. 13
0
        private static void ParseBytes(ref Stream file, ref BMPHeader bmpHeader)
        {
            //every BMP header is 54 bytes, followed by the image data
            //SIZE of the BMP: 2 bytes in (4 bytes long)
            //WIDTH of the BMP: 18 bytes in (4 bytes long)...in pixels
            //HEIGHT of the BMP: 22 bytes in (4 bytes long)...in pixels
            
            //PIXELDATA starts 54 bytes in, each row is 8 bytes long

            //grabs B[2,3,4,5] for the Size
            byte[] size = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                            (byte)file.ReadByte(), (byte)file.ReadByte()};
            bmpHeader.Size = FormUint4(size);

            //current position is at Byte 6 => must go to 18
            file.Position = 18;

            //grabs B[18,19,20,21] for the width
            byte[] width = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                             (byte)file.ReadByte(), (byte)file.ReadByte()};
            bmpHeader.Width = FormUint4(width);

            //grabs B[22,23,24,25] for the height
            byte[] height = { (byte)file.ReadByte(), (byte)file.ReadByte(),
                              (byte)file.ReadByte(), (byte)file.ReadByte()};
            bmpHeader.Height = FormUint4(height);

            //current position is at Byte 26 => must go to 28
            file.Position = 28;

            //grabs B[28,29] for the BitCount
            byte[] bitCount = { (byte)file.ReadByte(), (byte)file.ReadByte()};
            bmpHeader.BitCount = FormUint2(bitCount);

            //current position is at Byte 30 => must go to 54
            file.Position = 54;

            //craete the Color[] and copy it over to the bmpHeader
            BuildPixels(ref bmpHeader.Pixels, ref file, bmpHeader.BitCount, (int) bmpHeader.Width, (int) bmpHeader.Height);
        }
Esempio n. 14
0
        private void actionPack_Click(object sender, EventArgs e)
        {
            if (!File.Exists(pathFile.Text))
            {
                MessageBox.Show($"File doesn't exist!\r\n{pathFile.Text}");
                return;
            }

            using (Scene scn = Scene.FromFile(pathFile.Text))
            {
                Tim ctr = scn.ctrvram;

                //dumping vram before the change
                if (optionDebugVram.Checked)
                {
                    //only dump if file doesn't exist (to compare to earliest version of vram)
                    if (!File.Exists(Path.Combine(pathFileParent, "test_old.bmp")))
                    {
                        ctr.SaveBMP(Path.Combine(pathFileParent, "test_old.bmp"), BMPHeader.GrayScalePalette(16));
                    }
                }

                Dictionary <string, TextureLayout> list = scn.GetTexturesList();

                foreach (string s in Directory.GetFiles(pathFolder.Text, "*.png"))
                {
                    string tag = Path.GetFileNameWithoutExtension(s);

                    Console.Write($"replacing {tag}... ");

                    if (!list.ContainsKey(tag))
                    {
                        Helpers.Panic(ctr, "unknown texture entry");
                        continue;
                    }

                    Tim newtex = ctr.GetTimTexture(list[tag]);
                    newtex.LoadDataFromBitmap(s);

                    ctr.DrawTim(newtex);

                    Console.WriteLine("done.");
                }

                if (optionDebugVram.Checked)
                {
                    ctr.SaveBMP(Path.Combine(pathFileParent, "test_new.bmp"), BMPHeader.GrayScalePalette(16));
                }


                List <Tim> tims = new List <Tim>();
                foreach (var r in CtrVrm.frames)
                {
                    tims.Add(ctr.GetTrueColorTexture(r));
                }

                string tempFile = Path.Combine(pathFileParent, "temp.tim");
                string vramFile = Path.ChangeExtension(pathFile.Text, ".vrm");

                Helpers.BackupFile(vramFile);
                File.Delete(vramFile);

                using (BinaryWriterEx bw = new BinaryWriterEx(File.Create(vramFile)))
                {
                    bw.Write((int)0x20);

                    foreach (Tim tim in tims)
                    {
                        tim.Write(tempFile);
                        byte[] x = File.ReadAllBytes(tempFile);

                        bw.Write(x.Length);
                        bw.Write(x);
                    }

                    bw.Write((int)0);

                    bw.Flush();
                    bw.Close();
                }

                File.Delete(tempFile);

                //ctr.GetTrueColorTexture(512, 0, 384, 256).Write(Path.Combine(Path.GetDirectoryName(pathFolder.Text), "x01.tim"));
                //ctr.GetTrueColorTexture(512, 256, 512, 256).Write(Path.Combine(Path.GetDirectoryName(pathFolder.Text), "x02.tim"));
            }

            GC.Collect();
            MessageBox.Show("Done.");
        }