private bool ProcessCode(int code, byte[] buffer, int offset, int count, ref int read) { if (code < this._codeTable.Count) { LzwDecompressStream.Sequence sequence = this._codeTable[code]; if (sequence.IsStopCode) { return(false); } if (sequence.IsClearCode) { this.InitCodeTable(); return(true); } this._remainingBytes = LzwDecompressStream.CopySequenceToBuffer(sequence.Bytes, buffer, offset, count, ref read); if (this._prevCode >= 0) { this._codeTable.Add(this._codeTable[this._prevCode].Append(sequence.Bytes[0])); } } else { LzwDecompressStream.Sequence sequence1 = this._codeTable[this._prevCode]; LzwDecompressStream.Sequence local = sequence1; //int num = (int)local.Bytes[0]; LzwDecompressStream.Sequence sequence2 = (local).Append(/*(byte)num*/ local.Bytes[0]); this._codeTable.Add(sequence2); this._remainingBytes = LzwDecompressStream.CopySequenceToBuffer(sequence2.Bytes, buffer, offset, count, ref read); } this._prevCode = code; return(true); }
private void FlushRemainingBytes(byte[] buffer, int offset, int count, ref int read) { if (this._remainingBytes == null) { return; } this._remainingBytes = LzwDecompressStream.CopySequenceToBuffer(this._remainingBytes, buffer, offset, count, ref read); }
private static async Task DecompressAllFramesAsync(string path) { using (var fileStream = File.OpenRead(path)) { var gif = await GifDataStream.ReadAsync(fileStream); for (int i = 0; i < gif.Frames.Count; i++) { var frame = gif.Frames[i]; fileStream.Seek(frame.ImageData.CompressedDataStartOffset, SeekOrigin.Begin); using (var ms = new MemoryStream()) { await GifHelpers.CopyDataBlocksToStreamAsync(fileStream, ms); using (var lzwStream = new LzwDecompressStream(ms.GetBuffer(), frame.ImageData.LzwMinimumCodeSize)) using (var indOutStream = File.OpenWrite($"{path}.{i}.ind")) { await lzwStream.CopyToAsync(indOutStream); } } } } }
private async Task<Stream> GetIndexStreamAsync(GifFrame frame, CancellationToken cancellationToken) { var data = frame.ImageData; cancellationToken.ThrowIfCancellationRequested(); _sourceStream.Seek(data.CompressedDataStartOffset, SeekOrigin.Begin); using (var ms = new MemoryStream(_indexStreamBuffer)) { await GifHelpers.CopyDataBlocksToStreamAsync(_sourceStream, ms, cancellationToken).ConfigureAwait(false); } var lzwStream = new LzwDecompressStream(_indexStreamBuffer, data.LzwMinimumCodeSize); return lzwStream; }