public (IEnumerable <IndexData> indeces, IList <Color> palette) Load(byte[] input, byte[] paletteData) { var palette = _paletteFormat.Load(paletteData).ToList(); var result = new List <IndexData>(); using (var br = new BinaryReaderX(new MemoryStream(input), false, _byteOrder)) while (br.BaseStream.Position < br.BaseStream.Length || !br.IsFirstNibble) { switch (_indexDepth) { case 4: result.Add(new IndexData(br.ReadNibble())); break; case 8: result.Add(new IndexData(br.ReadByte())); break; default: throw new InvalidOperationException($"IndexDepth {_indexDepth} not supported."); } } return(result, palette); }
public Palette(byte[] paletteData, IImageFormat paletteFormat, int indexDepth = 8, ByteOrder byteOrder = ByteOrder.LittleEndian) { if (indexDepth % 4 != 0) { throw new Exception("IndexDepth has to be dividable by 4."); } this.byteOrder = byteOrder; BitDepth = indexDepth; FormatName = "Paletted " + paletteFormat.FormatName; this.paletteFormat = paletteFormat; paletteBytes = paletteData; colors = paletteFormat.Load(paletteData).ToList(); }
public AI(int alpha, int indexSize, byte[] paletteData, IImageFormat paletteFormat, ByteOrder byteOrder = ByteOrder.LittleEndian) { if ((alpha + indexSize) % 8 != 0) { throw new Exception("Alpha + IndexSize has to be dividable by 8."); } this.byteOrder = byteOrder; this.alpha = alpha; this.indexSize = indexSize; BitDepth = alpha + indexSize; FormatName = $"A{alpha}I{indexSize}"; this.paletteFormat = paletteFormat; paletteBytes = paletteData; colors = paletteFormat.Load(paletteData).ToList(); }