private static void PaletteInfo(string file, string outputDir) { Console.WriteLine("Reading {0} as NCLR palette...", file); Nclr palette = new Nclr(file); Console.WriteLine("\t* Version: {0}", palette.NitroData.VersionS); Console.WriteLine("\t* Contains PCMP section: {0}", palette.NitroData.Blocks.ContainsType("PCMP")); Console.WriteLine("\t* Number of palettes: {0}", palette.NumPalettes); if (!string.IsNullOrEmpty(outputDir) && !Directory.Exists(outputDir)) Directory.CreateDirectory(outputDir); for (int i = 0; i < palette.NumPalettes; i++) { Console.WriteLine("\t+ Palette {0}: {1} colors", i, palette.GetPalette(i).Length); if (!string.IsNullOrEmpty(outputDir)) { string outputFile = Path.Combine(outputDir, "Palette" + i.ToString() + ".png"); if (File.Exists(outputFile)) File.Delete(outputFile); palette.CreateBitmap(i).Save(outputFile); } } }
public void SetOriginalSettings(Stream mapStr, Stream imgStr, Stream palStr, bool changePalette = false) { // Set original palette settings if (palStr != null) { Nclr nclr = new Nclr(palStr); this.ExtendedPalette = nclr.Extended; if (!changePalette) this.Quantization = new FixedPaletteQuantization(nclr.GetPalette(0)); } // Set original image settings if the file is not compressed if (imgStr != null && imgStr.ReadByte() == 0x52) { imgStr.Position -= 1; Ncgr ncgr = new Ncgr(imgStr); this.DispCnt = ncgr.RegDispcnt; this.UnknownChar = ncgr.Unknown; this.Format = ncgr.Format; this.IncludeCpos = ncgr.HasCpos; this.PixelEncoding = ncgr.PixelEncoding; } // Set original map settings if (mapStr != null && mapStr.ReadByte() == 0x52) { mapStr.Position -= 1; Nscr nscr = new Nscr(mapStr); this.BgMode = nscr.BgMode; this.PaletteMode = nscr.PaletteMode; this.TileSize = nscr.TileSize; } }