Example #1
0
        static void BulkConvertAtxMulti(string inPath, string filter, bool recursive)
        {
            foreach (var path in Directory.GetFiles(inPath, filter, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
            {
                using (var fs = Utils.CheckDecompress(File.OpenRead(path)))
                {
                    var tex = new AlTexture();
                    tex.Read(new BinaryReader(fs));

                    if (tex.ChildTextures.Count < 2)
                    {
                        continue;
                    }
                    Console.WriteLine(path);

                    var img = new AlImage();
                    using (Stream ms = Utils.CheckDecompress(new MemoryStream(tex.ImageData)))
                    {
                        img.Read(new BinaryReader(ms));
                        if (img.PixelFormat != "BGRA")
                        {
                            Console.WriteLine("Not BGRA, skipping");
                            continue;
                        }

                        using (MemoryStream ims = new MemoryStream(img.Mipmaps[0]))
                            using (var imgConv = PngConverter.ConvertBgra32(new BinaryReader(ims), (int)img.Width, (int)img.Height))
                            {
                                foreach (var child in tex.ChildTextures)
                                {
                                    // First mip only
                                    var bounds = child.Bounds[0];
                                    using (var childImage = new Image <Bgra32>(bounds.W, bounds.H))
                                    {
                                        childImage.Mutate(ctx => ctx.DrawImage(imgConv, new Point(-bounds.X, -bounds.Y), 1f));
                                        childImage.SaveAsPng($"{Path.ChangeExtension(path, null)}_{child.Id:x8}.png");
                                    }
                                }
                            }
                    }
                }
            }
        }
Example #2
0
        static void BulkConvertAtx(string inPath, string filter, bool recursive)
        {
            foreach (var path in Directory.GetFiles(inPath, filter, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
            {
                Console.WriteLine(path);
                using (var fs = Utils.CheckDecompress(File.OpenRead(path)))
                {
                    var tex = new AlTexture();
                    tex.Read(new BinaryReader(fs));

                    var img = new AlImage();
                    using (Stream ms = Utils.CheckDecompress(new MemoryStream(tex.ImageData)))
                    {
                        img.Read(new BinaryReader(ms));
                        ConvertAig(img, path);
                    }
                }
            }
        }
Example #3
0
        static void BulkConvertAtxToPng(string inPath, string filter, bool recursive)
        {
            foreach (var path in Directory.GetFiles(inPath, filter, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
            {
                Console.WriteLine(path);
                string fileExtension;

                // Export the texture (probably KTX)
                using (var fs = Utils.CheckDecompress(File.OpenRead(path)))
                {
                    var tex = new AlTexture();
                    tex.Read(new BinaryReader(fs));

                    var img = new AlImage();
                    using (Stream ms = Utils.CheckDecompress(new MemoryStream(tex.ImageData)))
                    {
                        img.Read(new BinaryReader(ms));
                        fileExtension = ConvertAig(img, path);
                    }
                }

                if (fileExtension != ".pkm")
                {
                    continue;
                }

                // Convert main texture to PNG
                string mainPath  = Path.ChangeExtension(path, fileExtension);
                var    startInfo = new ProcessStartInfo(ETC1TOOL_PATH);
                startInfo.ArgumentList.Add(mainPath);
                startInfo.ArgumentList.Add("--decode");
                startInfo.CreateNoWindow  = false;
                startInfo.UseShellExecute = false;
                Process.Start(startInfo).WaitForExit();

                // Convert alpha texture if present
                string altPath = $"{Path.ChangeExtension(path, null)}_alt{fileExtension}";
                if (File.Exists(altPath))
                {
                    startInfo = new ProcessStartInfo(ETC1TOOL_PATH);
                    startInfo.ArgumentList.Add(altPath);
                    startInfo.ArgumentList.Add("--decode");
                    startInfo.CreateNoWindow  = false;
                    startInfo.UseShellExecute = false;
                    Process.Start(startInfo).WaitForExit();

                    var mainPngPath = Path.ChangeExtension(mainPath, ".png");
                    var altPngPath  = Path.ChangeExtension(altPath, ".png");

                    using (var mainImg = Image.Load <Rgb24>(mainPngPath))
                        using (var altImg = Image.Load <Rgb24>(altPngPath))
                        {
                            using (var mergedImg = MergeAlpha(mainImg, altImg))
                                using (FileStream newFs = File.Create(mainPngPath))
                                {
                                    mergedImg.SaveAsPng(newFs);
                                }
                        }

                    File.Delete(altPngPath);
                    File.Delete(altPath);
                }

                File.Delete(mainPath);
            }
        }