示例#1
0
文件: Program.cs 项目: mhvuze/tex2png
        static void SingleConvert(string path)
        {
            using (var stream = File.OpenRead(path))
            {
                var texture = new Texture(stream);

                texture.SaveBitmap(Path.ChangeExtension(path, ".png"));
            }
        }
示例#2
0
文件: Program.cs 项目: mhvuze/tex2png
        static void BatchConvert(string path)
        {
            using (var archive = new ZipArchive(File.OpenRead(path)))
            {
                foreach (var entry in archive.Entries)
                {
                    var extension = Path.GetExtension(entry.Name);

                    if (extension.Equals(".tex", StringComparison.OrdinalIgnoreCase))
                    {
                        Console.WriteLine(entry.FullName);

                        using (var stream = entry.Open())
                        {
                            var texture = new Texture(stream);
                            var directoryName = Path.GetDirectoryName(path);
                            var fullName = Path.ChangeExtension(entry.FullName, ".png");

                            texture.SaveBitmap(Path.Combine(directoryName, fullName));
                        }
                    }
                }
            }
        }
示例#3
0
文件: Texture.cs 项目: mhvuze/tex2png
        public static Texture Convert(Texture texture, Format format)
        {
            if (format != Format.Format32bppArgb)
                throw new ArgumentException();

            var src = texture.pixelData;
            var dst = new byte[texture.Width * texture.Height * format.GetBitsPerPixel() / 8];

            if (texture.Format == Format.Format4bppPvrtc)
            {
                var result = PVRTDecompressPVRTC(src, 0, texture.Width, texture.Height, dst);

                if (result != src.Length)
                    throw new ArgumentException();

                Convert32bppAbgrTo32bppArgb(dst, dst);
            }
            else if (texture.Format == Format.Format32bppAbgr)
            {
                Convert32bppAbgrTo32bppArgb(src, dst);
            }
            else if (texture.Format == Format.Format16bppRgba)
            {
                Convert16bppRgbaTo32bppArgb(src, dst);
            }
            else
            {
                throw new ArgumentException();
            }

            return new Texture(texture.Width, texture.Height, format, dst);
        }