Beispiel #1
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();
        }
Beispiel #2
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();
        }