예제 #1
0
        private static void Import(BinaryFormat input, string pngPath, string output, ColorFormat format)
        {
            MmTex texture;

            if (format == ColorFormat.Indexed_A5I3)
            {
                texture = input.ConvertWith <Binary2MmTex, BinaryFormat, MmTex>();
            }
            else
            {
                texture = input.ConvertWith <Binary2MmTexA3, BinaryFormat, MmTex>();
            }

            input.Dispose();

            // Import the new PNG file
            Bitmap newImage     = (Bitmap)Image.FromFile(pngPath);
            var    quantization = new FixedPaletteQuantization(texture.Palette.GetPalette(0));

            Texim.Media.Image.ImageConverter importer = new Texim.Media.Image.ImageConverter
            {
                Format        = format,
                PixelEncoding = PixelEncoding.Lineal,
                Quantization  = quantization
            };
            (Palette _, PixelArray pixelInfo) = importer.Convert(newImage);
            texture.Pixels = pixelInfo;

            // Save the texture
            texture.ConvertWith <Binary2MmTex, MmTex, BinaryFormat>()
            .Stream.WriteTo(output);
        }
예제 #2
0
        private static void Export(BinaryFormat input, string output, ColorFormat format)
        {
            MmTex mmtex;

            if (format == ColorFormat.Indexed_A5I3)
            {
                mmtex = input.ConvertWith <Binary2MmTex, BinaryFormat, MmTex>();
            }
            else
            {
                mmtex = input.ConvertWith <Binary2MmTexA3, BinaryFormat, MmTex>();
            }

            input.Dispose();

            // To export the image:
            mmtex.Pixels.CreateBitmap(mmtex.Palette, 0).Save(output);
        }
예제 #3
0
        public static void ImportFad(string name, string pathFolder, string pathBf, string outFile)
        {
            // 1
            Node nodo = NodeFactory.FromFile(pathBf); // BinaryFormat

            // 2
            IConverter <BinaryFormat, FAD.FAD> fadConverter = new FAD.BinaryFormat2Fad();
            Node nodoScript = nodo.Transform(fadConverter);

            string[] fileArray = Directory.GetFiles(pathFolder, "*.png");

            Array.Sort(fileArray);


            foreach (var image in fileArray)
            {
                ImportImage(image.Remove(image.Length - 4) + ".YKCMP", image);
                using BinaryFormat binaryFormat = new BinaryFormat(image.Remove(image.Length - 4) + "_new.YKCMP");
                BinaryFormat compressed = binaryFormat.ConvertWith <YkcmpCompression, BinaryFormat, BinaryFormat>();
                compressed.Stream.WriteTo(image.Remove(image.Length - 4) + ".YKCMPC");
            }

            Node nodeFolder = NodeFactory.CreateContainer("Ykcmp");

            string[] ykcmpFileArray = Directory.GetFiles(pathFolder, "*.YKCMPC");
            Array.Sort(ykcmpFileArray);

            foreach (var ykcmp in ykcmpFileArray)
            {
                Node nodoYkcmp = NodeFactory.FromFile(ykcmp);
                nodeFolder.Add(nodoYkcmp);
            }

            // 3
            IConverter <FAD.FAD, BinaryFormat> binaryFormatConverter = new FAD.Fad2BinaryFormat
            {
                Container = nodeFolder
            };
            Node nodoBf = nodoScript.Transform(binaryFormatConverter);

            //4
            Console.WriteLine(@"Importing " + name + @"...");
            nodoBf.Stream.WriteTo(outFile);
        }
예제 #4
0
 public static void ExportImage(string file)
 {
     using var binaryFormat = new BinaryFormat(file);
     Images.ImageFormat image = binaryFormat.ConvertWith <Images.BinaryFormat2ImageFormat, BinaryFormat, Images.ImageFormat>();
     image.Pixels.CreateBitmap(image.Palette, 0).Save(file.Remove(file.Length - 6) + ".png");
 }