public WsaTile(Stream s, Size size, ISpriteFrame prev) { Size = size; var dataLen = s.Length - s.Position; Console.WriteLine("dataLen = {0}", dataLen); var tempData = StreamExts.ReadBytes(s, (int)dataLen); byte[] srcData = new byte[size.Width * size.Height]; // format80 decompression LCWCompression.DecodeInto(tempData, srcData); // and format40 decmporession Data = new byte[size.Width * size.Height]; if (prev == null) { Array.Clear(Data, 0, Data.Length); } else { Array.Copy(prev.Data, Data, Data.Length); } XORDeltaCompression.DecodeInto(srcData, Data, 0); }
/// <summary> /// /// </summary> /// <param name="h"></param> void Decompress(ImageHeader h) { if (h.Size.Width == 0 || h.Size.Height == 0) { return; } if (recurseDepth > imageCount) { throw new InvalidOperationException("Format20/40 headers contain infinite loop"); } switch (h.Format) { case Format.XORPrev: case Format.XORLCW: if (h.RefImage.Data == null) { ++recurseDepth; Decompress(h.RefImage); --recurseDepth; } h.Data = CopyImageData(h.RefImage.Data); XORDeltaCompression.DecodeInto(shpBytes, h.Data, (int)(h.FileOffset - shpBytesFileOffset)); break; case Format.LCW: var imageBytes = new byte[Size.Width * Size.Height]; LCWCompression.DecodeInto(shpBytes, imageBytes, (int)(h.FileOffset - shpBytesFileOffset)); h.Data = imageBytes; break; default: throw new InvalidDataException(); } }
void Decompress(ImageHeader h) { // No extra work is required for empty frames if (h.Size.Width == 0 || h.Size.Height == 0) return; if (recurseDepth > imageCount) throw new InvalidDataException("Format20/40 headers contain infinite loop"); switch (h.Format) { case Format.XORPrev: case Format.XORLCW: { if (h.RefImage.Data == null) { ++recurseDepth; Decompress(h.RefImage); --recurseDepth; } h.Data = CopyImageData(h.RefImage.Data); XORDeltaCompression.DecodeInto(shpBytes, h.Data, (int)(h.FileOffset - shpBytesFileOffset)); break; } case Format.LCW: { var imageBytes = new byte[Size.Width * Size.Height]; LCWCompression.DecodeInto(shpBytes, imageBytes, (int)(h.FileOffset - shpBytesFileOffset)); h.Data = imageBytes; break; } default: throw new InvalidDataException(); } }