public ShpTDSprite(Stream stream) { imageCount = stream.ReadUInt16(); stream.Position += 4; var width = stream.ReadUInt16(); var height = stream.ReadUInt16(); Size = new Size(width, height); stream.Position += 4; var headers = new ImageHeader[imageCount]; Frames = headers.AsReadOnly(); for (var i = 0; i < headers.Length; i++) headers[i] = new ImageHeader(stream, this); // Skip eof and zero headers stream.Position += 16; var offsets = headers.ToDictionary(h => h.FileOffset, h => h); for (var i = 0; i < imageCount; i++) { var h = headers[i]; if (h.Format == Format.XORPrev) h.RefImage = headers[i - 1]; else if (h.Format == Format.XORLCW && !offsets.TryGetValue(h.RefOffset, out h.RefImage)) throw new InvalidDataException("Reference doesn't point to image data {0}->{1}".F(h.FileOffset, h.RefOffset)); } shpBytesFileOffset = stream.Position; shpBytes = stream.ReadBytes((int)(stream.Length - stream.Position)); foreach (var h in headers) Decompress(h); }