Esempio n. 1
0
        public EmguImage[] GetSpriteImage()
        {
            if (this.NumSubfiles != 9 || this[0] == null || this[1] == null || this[3] == null)
            {
                throw new FormatException("The pack does not contain a sprite image.");
            }

            this[0].Position = this[1].Position = this[3].Position = 0;
            Nclr nclr = new Nclr(this[0]);
            Ncgr ncgr = new Ncgr(this[1]);
            Ncer ncer = new Ncer(this[3]);

            this[0].Position = this[1].Position = this[3].Position = 0;

            EmguImage[] images = new EmguImage[ncer.NumFrames];
            for (int i = 0; i < ncer.NumFrames; i++)
            {
                images[i] = ncer.CreateBitmap(i, ncgr, nclr);
            }
            return(images);
        }
Esempio n. 2
0
        private static void SpriteInfo(string spriteFile, string imgFile, string palFile, string outputDir)
        {
            Console.WriteLine("Reading {0} as NCLR palette...", palFile);
            Nclr palette = new Nclr(palFile);

            Console.WriteLine("Reading {0} as NCGR image...", imgFile);
            Ncgr image = new Ncgr(imgFile);

            Console.WriteLine("Reading {0} as NCER sprite...", spriteFile);
            Ncer sprite = new Ncer(spriteFile);

            if (!string.IsNullOrEmpty(outputDir) && !Directory.Exists(outputDir))
                Directory.CreateDirectory(outputDir);

            for (int i = 0; i < sprite.NumFrames; i++) {
                if (!string.IsNullOrEmpty(outputDir)) {
                    string outputFile = Path.Combine(outputDir, "Sprite" + i.ToString() + ".png");
                    if (File.Exists(outputFile))
                        File.Delete(outputFile);
                    sprite.CreateBitmap(i, image, palette).Save(outputFile);
                }
            }
        }
Esempio n. 3
0
        private static void ImportTestSprite(string sprFile, string imgFile, string palFile)
        {
            FileStream   oldPalStr = new FileStream(palFile, FileMode.Open);
            FileStream   oldImgStr = new FileStream(imgFile, FileMode.Open);
            FileStream   oldSprStr = new FileStream(sprFile, FileMode.Open);
            MemoryStream newPalStr = new MemoryStream();
            MemoryStream newImgLinealStr = new MemoryStream();
            MemoryStream newImgTiledStr = new MemoryStream();
            MemoryStream newSprStr = new MemoryStream();

            Nclr nclr = new Nclr(oldPalStr);
            Ncgr ncgr = new Ncgr(oldImgStr);
            Ncer ncer = new Ncer(oldSprStr);

            SpriteImporter importer = new SpriteImporter();
            importer.Format = ColorFormat.Indexed_4bpp;
            importer.ObjectMode    = ObjMode.Normal;
            importer.PaletteMode   = PaletteMode.Palette16_16;
            importer.TileSize      = new System.Drawing.Size(64, 64);
            importer.Quantization     = new NdsQuantization() {
                BackdropColor = new Color(248, 0, 248, 255),
                Format = ColorFormat.Indexed_4bpp
            };
            importer.Reducer  = new SimilarDistanceReducer();
            importer.Splitter = new NdsSplitter(1);

            for (int i = 0; i < ncer.NumFrames; i++) {
                EmguImage bmp = ncer.CreateBitmap(i, ncgr, nclr);
                bmp.Save(sprFile + i.ToString() + ".png");
                importer.AddFrame(bmp);
            }

            importer.Generate(newPalStr, newImgLinealStr, newImgTiledStr, newSprStr);

            /*
            if (!Compare(oldPalStr, newPalStr)) {
                string newPalFile = palFile + ".new";
                WriteStream(newPalFile, newPalStr);
                Console.WriteLine("Palette different... Written to {0}", newPalFile);
            }
            if (!Compare(oldImgStr, newImgStr)) {
                string newImgFile = imgFile + ".new";
                WriteStream(newImgFile, newImgStr);
                Console.WriteLine("Image different...   Written to {0}", newImgFile);
            }
            if (!Compare(oldSprStr, newSprStr)) {
                string newSprFile = sprFile + ".new";
                WriteStream(newSprFile, newSprStr);
                Console.WriteLine("Sprite different...  Written to {0}", newSprFile);
            }
            */

            newPalStr.Position = newImgLinealStr.Position = newImgTiledStr.Position = newSprStr.Position = 0;
            nclr = new Nclr(newPalStr);
            ncgr = new Ncgr(newImgTiledStr);
            ncer = new Ncer(newSprStr);
            for (int i = 0; i < ncer.NumFrames; i++)
                ncer.CreateBitmap(i, ncgr, nclr).Save(sprFile + i.ToString() + "m.png");

            oldPalStr.Close();
            oldImgStr.Close();
            oldSprStr.Close();
            newPalStr.Close();
            newImgTiledStr.Close();
            newImgLinealStr.Close();
            newSprStr.Close();
        }
Esempio n. 4
0
        public static Npck FromSpriteImage(EmguImage[] images, int[] frames, Npck original)
        {
            SpriteImporter importer      = new SpriteImporter();
            MemoryStream   nclrStr       = new MemoryStream();
            MemoryStream   ncgrLinealStr = new MemoryStream();
            MemoryStream   ncgrTiledStr  = new MemoryStream();
            MemoryStream   ncerStr       = new MemoryStream();

            // Create sprites images to import
            // those sprite that have not been exported (they didn't have text)
            if (original[0] != null)
            {
                Nclr nclr = new Nclr(original[0]);
                Ncgr ncgr = new Ncgr(original[1] == null ? original[2] : original[1]);
                Ncer ncer = new Ncer(original[3]);

                // Set old settings
                importer.DispCnt          = ncgr.RegDispcnt;
                importer.Quantization     = new ManyFixedPaletteQuantization(nclr.GetPalettes());
                importer.OriginalPalettes = nclr.GetPalettes();
                importer.Format           = nclr.Format;
                if (nclr.Format == ColorFormat.Indexed_8bpp)
                {
                    importer.PaletteMode = PaletteMode.Palette256_1;
                }
                else
                {
                    importer.PaletteMode = PaletteMode.Palette16_16;
                }

                int idx = 0;
                for (int i = 0; i < ncer.NumFrames; i++)
                {
                    if (frames.Contains(i))
                    {
                        importer.AddFrame(images[idx++]);
                    }
                    else if (ncer != null)
                    {
                        importer.AddFrame(ncer.CreateBitmap(i, ncgr, nclr), ncer.GetFrame(i));
                    }
                }
            }
            else
            {
                foreach (EmguImage img in images)
                {
                    importer.AddFrame(img);
                }
            }

            // TEMP: Check if the files were present
            if (original[0] == null)
            {
                Console.Write("(Warning: No palette) ");
            }
            if (original[1] == null)
            {
                //Console.Write("(Warning: No HImage) ");
                ncgrTiledStr = null;
            }
            if (original[2] == null)
            {
                //Console.Write("(Warning: No LImage) ");
                ncgrLinealStr = null;
            }
            if (original[3] == null)
            {
                Console.Write("(Warning: No sprite) ");
            }
            if (original[5] == null)
            {
                Console.Write("(Warning: No animation) ");
            }

            importer.Generate(nclrStr, ncgrLinealStr, ncgrTiledStr, ncerStr);

            nclrStr.Position = 0;
            ncerStr.Position = 0;
            if (ncgrTiledStr != null)
            {
                ncgrTiledStr.Position = 0;
            }
            if (ncgrLinealStr != null)
            {
                ncgrLinealStr.Position = 0;
            }

            return(Npck.FromSpriteStreams(ncerStr, ncgrLinealStr, ncgrTiledStr, nclrStr, original[5]));
        }
Esempio n. 5
0
        public EmguImage[] GetSpriteImage()
        {
            if (this.NumSubfiles != 9 || this[0] == null || this[1] == null || this[3] == null)
                throw new FormatException("The pack does not contain a sprite image.");

            this[0].Position = this[1].Position = this[3].Position = 0;
            Nclr nclr = new Nclr(this[0]);
            Ncgr ncgr = new Ncgr(this[1]);
            Ncer ncer = new Ncer(this[3]);
            this[0].Position = this[1].Position = this[3].Position = 0;

            EmguImage[] images = new EmguImage[ncer.NumFrames];
            for (int i = 0; i < ncer.NumFrames; i++)
                images[i] = ncer.CreateBitmap(i, ncgr, nclr);
            return images;
        }
Esempio n. 6
0
        public static Npck FromSpriteImage(EmguImage[] images, int[] frames, Npck original)
        {
            SpriteImporter importer = new SpriteImporter();
            MemoryStream nclrStr = new MemoryStream();
            MemoryStream ncgrLinealStr = new MemoryStream();
            MemoryStream ncgrTiledStr = new MemoryStream();
            MemoryStream ncerStr = new MemoryStream();

            // Create sprites images to import
            // those sprite that have not been exported (they didn't have text)
            if (original[0] != null) {
                Nclr nclr = new Nclr(original[0]);
                Ncgr ncgr = new Ncgr(original[1] == null ? original[2] : original[1]);
                Ncer ncer = new Ncer(original[3]);

                // Set old settings
                importer.DispCnt = ncgr.RegDispcnt;
                importer.Quantization = new ManyFixedPaletteQuantization(nclr.GetPalettes());
                importer.OriginalPalettes = nclr.GetPalettes();
                importer.Format = nclr.Format;
                if (nclr.Format == ColorFormat.Indexed_8bpp)
                    importer.PaletteMode = PaletteMode.Palette256_1;
                else
                    importer.PaletteMode = PaletteMode.Palette16_16;

                int idx = 0;
                for (int i = 0; i < ncer.NumFrames; i++) {
                    if (frames.Contains(i))
                        importer.AddFrame(images[idx++]);
                    else if (ncer != null)
                        importer.AddFrame(ncer.CreateBitmap(i, ncgr, nclr), ncer.GetFrame(i));
                }
            } else {
                foreach (EmguImage img in images)
                    importer.AddFrame(img);
            }

            // TEMP: Check if the files were present
            if (original[0] == null)
                Console.Write("(Warning: No palette) ");
            if (original[1] == null) {
                //Console.Write("(Warning: No HImage) ");
                ncgrTiledStr = null;
            }
            if (original[2] == null) {
                //Console.Write("(Warning: No LImage) ");
                ncgrLinealStr = null;
            }
            if (original[3] == null)
                Console.Write("(Warning: No sprite) ");
            if (original[5] == null)
                Console.Write("(Warning: No animation) ");

            importer.Generate(nclrStr, ncgrLinealStr, ncgrTiledStr, ncerStr);

            nclrStr.Position = 0;
            ncerStr.Position = 0;
            if (ncgrTiledStr != null)
                ncgrTiledStr.Position = 0;
            if (ncgrLinealStr != null)
                ncgrLinealStr.Position = 0;

            return Npck.FromSpriteStreams(ncerStr, ncgrLinealStr, ncgrTiledStr, nclrStr, original[5]);
        }