public Palette Dye(ColorTableEntry colorTableEntry) { var dyedPalette = new Palette(); Array.Copy(_colors, dyedPalette._colors, ColorsPerPalette); for (var i = 0; i < colorTableEntry.ColorCount; ++i) { dyedPalette._colors[i + ColorTable.PaletteStartIndex] = colorTableEntry[i]; } return(dyedPalette); }
private void Init(Stream stream) { _entries = new Dictionary <int, ColorTableEntry>(); _entriesReadOnly = new ReadOnlyDictionary <int, ColorTableEntry>(_entries); using (var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, true)) { if (!int.TryParse(reader.ReadLine(), out _colorsPerEntry)) { return; } while (!reader.EndOfStream && int.TryParse(reader.ReadLine(), out int colorNumber)) { var colors = new Color[_colorsPerEntry]; for (var i = 0; i < _colorsPerEntry && !reader.EndOfStream; ++i) { var line = reader.ReadLine(); if (line != null) { var values = line.Split(','); if (values.Length != 3 || !int.TryParse(values[0], out int r) || !int.TryParse(values[1], out int g) || !int.TryParse(values[2], out int b)) { return; } colors[i] = Color.FromArgb(r % 256, g % 256, b % 256); } else { colors[i] = Color.FromArgb(0, 0, 0, 0); } } _entries[colorNumber] = new ColorTableEntry(colors); } } }
public bool TryGetEntry(int colorNumber, out ColorTableEntry entry) => _entries.TryGetValue(colorNumber, out entry);