Beispiel #1
0
        public static void ImportImage(string originalFile, string pngFile)
        {
            Console.WriteLine(@"Importing " + originalFile + @"...");
            //Example taken from texim

            // Load palette to force colors when importing
            Node palette = NodeFactory.FromFile(originalFile);

            palette.Transform <Images.BinaryFormat2Palette, BinaryFormat, Palette>();

            Bitmap newImage = (Bitmap)Image.FromFile(pngFile);

            var quantization = new Texim.Processing.FixedPaletteQuantization(palette.GetFormatAs <Palette>().GetPalette(0));

            Texim.ImageConverter importer = new Texim.ImageConverter
            {
                Format        = ColorFormat.Indexed_8bpp,
                PixelEncoding = PixelEncoding.Lineal,
                Quantization  = quantization
            };

            (Palette _, PixelArray pixelInfo) = importer.Convert(newImage);
            // Save the new pixel info
            Node newPixels = new Node("pxInfo", pixelInfo);

            IConverter <PixelArray, BinaryFormat> imageConverter = new Images.ImageFormat2Binary
            {
                OriginalFile = new DataReader(new DataStream(originalFile, FileOpenMode.Read))
                {
                    DefaultEncoding = new UTF8Encoding(),
                    Endianness      = EndiannessMode.LittleEndian,
                }
            };
            Node nodoImage = newPixels.Transform(imageConverter);


            string file = originalFile.Remove(originalFile.Length - 6);

            nodoImage.GetFormatAs <BinaryFormat>().Stream.WriteTo(file + "_new.YKCMP");
        }
Beispiel #2
0
        private static void Import(string format, Node n, string dirToSave, string dataToInsert)
        {
            log.Info("Importing...");

            switch (format)
            {
            case FORMATPREFIX + "BinInfoTitle":

                Po2BinInfoTitle p2b = new Po2BinInfoTitle()
                {
                    OriginalFile = new Yarhl.IO.DataReader(n.Stream)
                    {
                        DefaultEncoding = Encoding.GetEncoding(932)
                    }
                };
                Node nodePo = NodeFactory.FromFile(dataToInsert);

                nodePo.TransformWith <Po2Binary>();
                Node nodeBin = nodePo.TransformWith(p2b)
                               .TransformWith <BinInfoTitle2Bin>();
                nodeBin.Stream.WriteTo(Path.Combine(dirToSave, n.Name.Remove(n.Name.Length - 4) + "_new.bin"));

                break;

            case FORMATPREFIX + "ALAR.ALAR3":

                // Alar original
                Node original = n.TransformWith <BinaryFormat2Alar3>();

                // Contenedor con los ficheros a insertar
                Node newContainer = NodeFactory.FromDirectory(dataToInsert, "*.*");
                foreach (var child in newContainer.Children)
                {
                    log.Info("Importing " + child.Name);
                }
                //var newAlar = newContainer.Transform<Alar3ToNodes, NodeContainerFormat, ALAR3>();

                // Modificamos el Alar original con los nuevos ficheros a insertar
                original.GetFormatAs <ALAR3>().InsertModification(newContainer);

                original.TransformWith <BinaryFormat2Alar3>()
                .Stream.WriteTo(Path.Combine(dirToSave, n.Name + "new.aar"));

                break;

            case FORMATPREFIX + "DIG":

                DIG originalDig = n.TransformWith <Binary2DIG>().GetFormatAs <DIG>();

                // Import the new PNG file
                Bitmap newImage               = (Bitmap)Image.FromFile(dataToInsert);
                var    quantization           = new FixedPaletteQuantization(originalDig.Palette.GetPalette(0));
                Texim.ImageConverter importer = new Texim.ImageConverter {
                    Format        = ColorFormat.Indexed_4bpp,
                    PixelEncoding = PixelEncoding.HorizontalTiles,
                    Quantization  = quantization
                };

                (Palette _, PixelArray pixelInfo) = importer.Convert(newImage);

                originalDig.Pixels = pixelInfo;

                BinaryFormat b = (BinaryFormat)ConvertFormat.With <Binary2DIG>(originalDig);

                Utils.Lzss(b, "-evn").Stream.WriteTo(Path.Combine(dirToSave, n.Name + "evn.dig"));

                break;
            }
            log.Info("Finished importing");
        }