Exemple #1
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);
                }
            }
        }
        public static Ncgr LoadNgcr(string argumentosImg)
        {
            string[] argSplit = argumentosImg.Split(',');

            BinaryReader leitorNclr = new BinaryReader(new MemoryStream(BinaryManager.GetFile(argSplit[1])));

            Nclr nclr = new Nclr(leitorNclr, argSplit[1]);

            BinaryReader leitorNgcr = new BinaryReader(new MemoryStream(BinaryManager.GetFile(argSplit[0])));
            Ncgr         ncgr;


            if (argumentosImg.Contains(".nscr"))
            {
                BinaryReader leitorNscr = new BinaryReader(new MemoryStream(BinaryManager.GetFile(argSplit[2])));
                Nscr         nscr       = new Nscr(leitorNscr, argSplit[2]);
                ncgr = new Ncgr(leitorNgcr, nclr, nscr, argSplit[0], argSplit[3]);
            }
            else if (argumentosImg.Contains(".ncer"))
            {
                BinaryReader leitorNscer = new BinaryReader(new MemoryStream(BinaryManager.GetFile(argSplit[2])));
                Ncer         ncer        = new Ncer(leitorNscer, argSplit[2]);
                ncgr = new Ncgr(leitorNgcr, nclr, ncer, argSplit[0], argSplit[3]);
            }
            else
            {
                ncgr = new Ncgr(leitorNgcr, nclr, argSplit[0], argSplit[2]);
            }

            return(ncgr);
        }
        public Ncgr(BinaryReader br, Nclr nclr, Ncer ncer, string diretorio, string exportPath) : base(br, diretorio)
        {
            if (Errors.Count == 0 && nclr.Errors.Count == 0 && ncer.Errors.Count == 0)
            {
                ArquivoNcer = ncer;
                ArquivoNclr = nclr;
                SetNgcrProperties(br, exportPath);
                //CarregarImagemNCGRComNCER();
            }
            else
            {
                AllErrors.AddRange(Errors);
                AllErrors.AddRange(nclr.Errors);
                AllErrors.AddRange(ncer.Errors);
            }

            br.Close();
        }
Exemple #4
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();
        }
Exemple #5
0
        public void Generate(Stream paletteStr, Stream imgLinealStr, Stream imgTiledStr, Stream spriteStr)
        {
            Pixel[]   pixelsLin;
            Pixel[]   pixelsHori;
            Color[][] palettes;
            this.CreateData(out pixelsLin, out pixelsHori, out palettes);

            // Get frame list
            Frame[] frames = new Frame[this.frameData.Count];
            for (int i = 0; i < this.frameData.Count; i++)
            {
                frames[i] = this.frameData[i].Item1;
            }

            // Create palette format
            Nclr nclr = new Nclr()
            {
                Extended = false,
                Format   = this.Format
            };

            nclr.SetPalette(palettes);

            // Create image format
            Ncgr ncgrLineal = new Ncgr()
            {
                RegDispcnt  = this.DispCnt,
                Unknown     = this.UnknownChar,
                InvalidSize = true
            };

            ncgrLineal.Width  = (pixelsLin.Length > 256) ? 256 : pixelsLin.Length;
            ncgrLineal.Height = (int)Math.Ceiling(pixelsLin.Length / (double)ncgrLineal.Width);
            ncgrLineal.SetData(pixelsLin, PixelEncoding.Lineal, this.Format, this.TileSize);

            Ncgr ncgrTiled = new Ncgr()
            {
                RegDispcnt  = this.DispCnt,
                Unknown     = this.UnknownChar,
                InvalidSize = true
            };

            ncgrTiled.Width  = ncgrLineal.Width;
            ncgrTiled.Height = ncgrLineal.Height;
            if (ncgrTiled.Height % this.TileSize.Height != 0)
            {
                ncgrTiled.Height += this.TileSize.Height - (ncgrTiled.Height % this.TileSize.Height);
            }
            ncgrTiled.SetData(pixelsHori, PixelEncoding.HorizontalTiles, this.Format, this.TileSize);

            // Create sprite format
            Ncer ncer = new Ncer()
            {
                TileSize          = 128,
                IsRectangularArea = this.UseRectangularArea
            };

            ncer.SetFrames(frames);

            // Write data
            if (paletteStr != null)
            {
                nclr.Write(paletteStr);
            }
            if (imgLinealStr != null)
            {
                ncgrLineal.Write(imgLinealStr);
            }
            if (imgTiledStr != null)
            {
                ncgrTiled.Write(imgTiledStr);
            }
            if (spriteStr != null)
            {
                ncer.Write(spriteStr);
            }
        }