public static void Write_WinPal(string fileout, NCLR_s palette) { int num2; if (File.Exists(fileout)) { File.Delete(fileout); } BinaryWriter writer = new BinaryWriter(File.OpenWrite(fileout)); int num = 0; for (num2 = 0; num2 < palette.pltt.palettes.Length; num2++) { num += palette.pltt.palettes[num2].colors.Length; } writer.Write(new char[] { 'R', 'I', 'F', 'F' }); writer.Write((uint)(0x10 + (num * 4))); writer.Write(new char[] { 'P', 'A', 'L', ' ' }); writer.Write(new char[] { 'd', 'a', 't', 'a' }); writer.Write((uint)0); writer.Write((ushort)0x300); writer.Write((ushort)num); for (num2 = 0; num2 < palette.pltt.palettes.Length; num2++) { for (int i = 0; i < palette.pltt.palettes[num2].colors.Length; i++) { writer.Write(palette.pltt.palettes[num2].colors[i].R); writer.Write(palette.pltt.palettes[num2].colors[i].G); writer.Write(palette.pltt.palettes[num2].colors[i].B); writer.Write((byte)0); writer.Flush(); } } writer.Close(); }
public static Bitmap[] Show(NCLR_s nclr) { Bitmap[] bitmapArray = new Bitmap[nclr.pltt.palettes.Length]; for (int i = 0; i < bitmapArray.Length; i++) { bitmapArray[i] = new Bitmap(160, 160); bool flag = false; for (int j = 0; (j < 0x10) & !flag; j++) { for (int k = 0; k < 0x10; k++) { if (nclr.pltt.palettes[i].colors.Length == (k + (0x10 * j))) { flag = true; break; } for (int m = 0; m < 10; m++) { for (int n = 0; n < 10; n++) { bitmapArray[i].SetPixel((k * 10) + n, (j * 10) + m, nclr.pltt.palettes[i].colors[k + (0x10 * j)]); } } } } } return(bitmapArray); }
public static Color[][] Read_WinPal2(string file, ColorDepth depth) { BinaryReader reader = new BinaryReader(File.OpenRead(file)); NCLR_s _s = new NCLR_s(); _s.header.id = reader.ReadChars(4); _s.header.file_size = reader.ReadUInt32(); _s.pltt.ID = reader.ReadChars(4); reader.ReadChars(4); reader.ReadUInt32(); reader.ReadUInt16(); _s.pltt.nColors = reader.ReadUInt16(); _s.pltt.depth = depth; uint num = (depth == ColorDepth.Depth4Bit) ? 0x10 : _s.pltt.nColors; _s.pltt.paletteLength = num * 2; Color[][] colorArray = new Color[(depth == ColorDepth.Depth4Bit) ? ((int)(_s.pltt.nColors / 0x10)) : 1][]; for (int i = 0; i < colorArray.Length; i++) { colorArray[i] = new Color[num]; for (int j = 0; j < num; j++) { Color color = Color.FromArgb(reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); reader.ReadByte(); colorArray[i][j] = color; } } reader.Close(); return(colorArray); }
public static NCLR_s BitmapToPalette(string bitmap, int paletteIndex = 0) { NCLR_s _s = new NCLR_s(); BinaryReader reader = new BinaryReader(File.OpenRead(bitmap)); if (new string(reader.ReadChars(2)) != "BM") { _s.header.id = "RLCN".ToCharArray(); } _s.header.endianess = 0xfeff; _s.header.constant = 0x100; _s.header.header_size = 0x10; _s.header.nSection = 1; reader.BaseStream.Position = 0x1cL; ushort num = reader.ReadUInt16(); if (num == 4) { _s.pltt.depth = ColorDepth.Depth4Bit; } else if (num == 8) { _s.pltt.depth = ColorDepth.Depth8Bit; } else { Stream stream1 = reader.BaseStream; stream1.Position += 0x10L; } _s.pltt.nColors = reader.ReadUInt32(); if (_s.pltt.nColors == 0) { _s.pltt.nColors = (uint)((num == 4) ? 0x10 : 0x100); } Stream baseStream = reader.BaseStream; baseStream.Position += 4L; _s.pltt.palettes = new NTFP[paletteIndex + 1]; _s.pltt.palettes[paletteIndex].colors = new Color[_s.pltt.nColors]; for (int i = 0; i < _s.pltt.nColors; i++) { byte[] buffer = reader.ReadBytes(4); _s.pltt.palettes[paletteIndex].colors[i] = Color.FromArgb(buffer[2], buffer[1], buffer[0]); } byte[] bytes = Convertir.ColorToBGR555(_s.pltt.palettes[paletteIndex].colors); _s.pltt.palettes[paletteIndex].colors = Convertir.BGR555(bytes); _s.pltt.ID = "TTLP".ToCharArray(); _s.pltt.paletteLength = _s.pltt.nColors * 2; _s.pltt.unknown1 = 0; _s.pltt.length = _s.pltt.paletteLength + 0x18; _s.header.file_size = _s.pltt.length + _s.header.header_size; reader.Close(); return(_s); }
public static NCLR_s Leer(BinaryReader br, int id) { NCLR_s _s = new NCLR_s { id = (uint)id }; _s.header.id = br.ReadChars(4); _s.header.endianess = br.ReadUInt16(); if (_s.header.endianess == 0xfffe) { _s.header.id.Reverse <char>(); } _s.header.constant = br.ReadUInt16(); _s.header.file_size = br.ReadUInt32(); _s.header.header_size = br.ReadUInt16(); _s.header.nSection = br.ReadUInt16(); if ((_s.header.nSection < 1) || (_s.header.nSection > 2)) { _s.pltt = Seccion_PLTT(ref br); } if ((br.BaseStream.Length != br.BaseStream.Position) && (new string(br.ReadChars(4)) == "PMCP")) { Stream baseStream = br.BaseStream; baseStream.Position -= 4L; _s.pmcp = Section_PMCP(ref br); List <NTFP> list = new List <NTFP>(); for (int i = 0; i < _s.pmcp.first_palette_num; i++) { NTFP item = new NTFP { colors = new Color[0] }; list.Add(item); } list.AddRange(_s.pltt.palettes); _s.pltt.palettes = list.ToArray(); } br.Close(); return(_s); }
public static void Escribir(NCLR_s paleta, string fileout) { BinaryWriter writer = new BinaryWriter(File.OpenWrite(fileout)); writer.Write(paleta.header.id); writer.Write(paleta.header.endianess); writer.Write(paleta.header.constant); writer.Write(paleta.header.file_size); writer.Write(paleta.header.header_size); writer.Write(paleta.header.nSection); writer.Write(paleta.pltt.ID); writer.Write(paleta.pltt.length); writer.Write((paleta.pltt.depth == ColorDepth.Depth4Bit) ? ((ushort)3) : ((ushort)4)); writer.Write((ushort)0); writer.Write((uint)0); writer.Write(paleta.pltt.paletteLength); writer.Write(0x10); for (int i = 0; i < paleta.pltt.palettes.Length; i++) { writer.Write(Convertir.ColorToBGR555(paleta.pltt.palettes[i].colors)); } writer.Flush(); writer.Close(); }