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 NTFP Paleta_NTFP(ref BinaryReader br, uint colores) { return(new NTFP { colors = Convertir.BGR555(br.ReadBytes((int)(colores * 2))) }); }