private IEnumerable <TimPalette> ReadCluts(Stream stream) { var reader = new BinaryReader(stream); var length = reader.ReadInt32(); var originX = reader.ReadInt16(); var originY = reader.ReadInt16(); int numColors = reader.ReadInt16(); int numCluts = reader.ReadInt16(); var padding = length - numCluts * numColors * 2 - 12; for (var i = 0; i < numCluts; i++) { var entries = new short[numColors]; var clut = new TimPalette { OriginX = originX, OriginY = originY, Entries = entries }; for (var j = 0; j < numColors; j++) { entries[j] = reader.ReadInt16(); } yield return(clut); } if (padding > 0) { reader.ReadBytes(padding); } }
private int[] DecodeClut(TimPalette clut) => clut.Entries.Select(i => _colorDecoder.Decode16Bit(i)).ToArray();