Пример #1
0
        public override void Export(Asset asset, string path)
        {
            var texture = (asset as Texture);
            var img = new IMG();
            var b = (texture.SupportingDocuments["Source"] as Bitmap);
            if (b == null) { b = texture.GetBitmap(); }

            SceneManager.Current.UpdateProgress(string.Format("Saving {0}", texture.Name));

            img.Name = texture.Name;
            img.ImportFromBitmap(b);

            SceneManager.Current.UpdateProgress(string.Format("Compressing {0} (this may take a moment)", texture.Name));
            img.Save(Path.GetDirectoryName(path) + "\\" + texture.Name + ".img");

            SceneManager.Current.UpdateProgress(string.Format("{0}.img saved!", texture.Name));
        }
Пример #2
0
        public static IMG Load(string path)
        {
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            IMG img = new IMG();

            img.Name = Path.GetFileNameWithoutExtension(path);

            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(path)))
            using (BinaryReader br = new BinaryReader(ms))
            {
                if (br.ReadByte() != 0x49 || // I
                    br.ReadByte() != 0x4D || // M
                    br.ReadByte() != 0x41 || // A
                    br.ReadByte() != 0x47 || // G
                    br.ReadByte() != 0x45 || // E
                    br.ReadByte() != 0x4D || // M
                    br.ReadByte() != 0x41 || // A
                    br.ReadByte() != 0x50)   // P
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid IMG file", path);
                    return null;
                }

                byte minor = br.ReadByte();
                byte major = br.ReadByte();

                img.version = new Version(major, minor);
                img.basicFlags = (BasicFlags)br.ReadByte();
                img.advancedFlags = (AdvancedFlags)br.ReadByte();
                img.planeFormat = (PlaneFormat)br.ReadUInt32();
                int fileSize = (int)br.ReadUInt32();
                img.width = br.ReadUInt16();
                img.height = br.ReadUInt16();

                Logger.LogToFile(Logger.LogLevel.Info, "{0} : {1} : {2} : {3}", img.version, img.basicFlags, img.advancedFlags, img.planeFormat);

                if (img.version.Minor == 1) { br.ReadUInt32(); }

                int planeCount = (img.planeFormat == PlaneFormat.Format1planeARGB ? 1 : 4);

                for (int i = 0; i < planeCount; i++)
                {
                    img.planes.Add(new Plane(i) { Output = new byte[br.ReadUInt32()] });
                }

                for (int i = planeCount - 1; i >= 0; i--)
                {
                    Plane plane = img.planes.First(p => p.Index == i);
                    plane.Output = br.ReadBytes(plane.Output.Length);
                    if (img.basicFlags.HasFlag(IMG.BasicFlags.Compressed))
                    {
                        plane.Decompress((img.advancedFlags.HasFlag(IMG.AdvancedFlags.Huffman) ? CompressionMethod.Huffman : CompressionMethod.RLE));
                    }
                }
            }

            return img;
        }
Пример #3
0
        public static IMG Load(string path)
        {
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            IMG img = new IMG()
            {
                Name = Path.GetFileNameWithoutExtension(path)
            };

            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(path)))
                using (BinaryReader br = new BinaryReader(ms))
                {
                    if (br.ReadByte() != 0x49 || // I
                        br.ReadByte() != 0x4D || // M
                        br.ReadByte() != 0x41 || // A
                        br.ReadByte() != 0x47 || // G
                        br.ReadByte() != 0x45 || // E
                        br.ReadByte() != 0x4D || // M
                        br.ReadByte() != 0x41 || // A
                        br.ReadByte() != 0x50)   // P
                    {
                        Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid IMG file", path);
                        return(null);
                    }

                    byte minor = br.ReadByte();
                    byte major = br.ReadByte();

                    img.version       = new Version(major, minor);
                    img.basicFlags    = (BasicFlags)br.ReadByte();
                    img.advancedFlags = (AdvancedFlags)br.ReadByte();
                    img.planeFormat   = (PlaneFormat)br.ReadUInt32();
                    int fileSize = (int)br.ReadUInt32();
                    img.width  = br.ReadUInt16();
                    img.height = br.ReadUInt16();

                    Logger.LogToFile(Logger.LogLevel.Info, "{0} : {1} : {2} : {3}", img.version, img.basicFlags, img.advancedFlags, img.planeFormat);

                    if (img.version.Minor == 1)
                    {
                        br.ReadUInt32();
                    }

                    int planeCount = (img.planeFormat == PlaneFormat.Format1planeARGB ? 1 : 4);

                    for (int i = 0; i < planeCount; i++)
                    {
                        img.planes.Add(new Plane(i)
                        {
                            Output = new byte[br.ReadUInt32()]
                        });
                    }

                    for (int i = 0; i < img.planes.Count; i++)
                    {
                        Plane plane = img.planes.First(p => p.Index == i);
                        plane.Output = br.ReadBytes(plane.Output.Length);
                        if (img.basicFlags.HasFlag(BasicFlags.Compressed))
                        {
                            plane.Decompress((img.advancedFlags.HasFlag(AdvancedFlags.Huffman) ? CompressionMethod.Huffman : CompressionMethod.RLE));
                        }
                    }
                }

            return(img);
        }