Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // This program works by having a file dragged onto it. If this program is launched without a file arg, exit
            if (args.Length == 0)
            {
                return;
            }

            byte[]    tm2file  = File.ReadAllBytes(args[0]);
            byte[]    imageBuf = TM2ToBitMap.GetImageBuffer(tm2file);
            TM2Header header   = TM2Header.GetHeader(tm2file);


            unsafe
            {
                fixed(byte *ptr = imageBuf)
                {
                    using (Bitmap image = new Bitmap(header.Width, header.Height, header.Width * 4,
                                                     PixelFormat.Format32bppArgb, new IntPtr(ptr)))
                    {
                        image.Save(@"export.png");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static byte[] GetImageBuffer(byte[] tm2file)
        {
            TM2Header header = TM2Header.GetHeader(tm2file);

            byte[][] palette = Palette.GetPalette(tm2file, header);

            // TODO -- different images based on image type
            byte[] imageBuf = new byte[4 * header.Width * header.Height];
            for (int y = 0; y < header.Height; ++y)
            {
                for (int x = 0; x < header.Width; ++x)
                {
                    byte c = tm2file[0x40 + GetAddress8BppSwizzle(header.Width, header.Height, x, y)];
                    Array.Copy(palette[c], 0, imageBuf, (x * 4) + (header.Width * y) * 4, 4);
                }
            }

            return(imageBuf);
        }