public TreeWalker(HuffmanTreeBase tree, IDecodingInputStream input, IDecodingOutputStream output, long seqLength) { this.tree = tree; this.input = input; this.output = output; this.seqLength = seqLength; }
public void Decode(IDecodingOutputStream outputStream, CancellationToken cancellationToken, IProgressHandler progress) { decoder.Decode(inputStream, weightsTable, outputStream, length, cancellationToken, progress); int trailingBitCount = MathHelper.ModAdv(length, 8); for (int n = 0; n < trailingBitCount; n++) { inputStream.ReadBit(out _); } }
public void Decode(IDecodingInputStream inputStream, HuffmanTreeBase tree, IDecodingOutputStream outputStream, long sequenceLength, CancellationToken cancellationToken, IProgressHandler progress) { Guard.IsNotNull(inputStream, nameof(inputStream)); Guard.IsNotNull(tree, nameof(tree)); Guard.IsNotNull(outputStream, nameof(outputStream)); Guard.IsNotNegative(sequenceLength, nameof(sequenceLength)); const int chunkSize = 0x20000 * 8; // 128Kb long progressValue = progress?.State.CastTo <CodingProgressState>()?.Value ?? 0; long streamPosition = inputStream.Position; TreeWalker walker = new TreeWalker(tree, inputStream, outputStream, sequenceLength); while (!walker.Exhausted && !inputStream.IsEmpty) { if (!tree.Walk(walker)) { throw new ArgumentException(); } // Throttling progressValue += inputStream.Position - streamPosition; streamPosition = inputStream.Position; if (progressValue >= chunkSize) { cancellationToken.ThrowIfCancellationRequested(); progress?.Report(progressValue / 8, outputStream.Path); progressValue %= 8; } } if (progress != null) { CodingProgressState progressState = (CodingProgressState)progress.State ?? new CodingProgressState(); progress.State = progressState.WithValue(progressValue); } }
public void Decode(IDecodingInputStream inputStream, WeightsTable weightsTable, IDecodingOutputStream outputStream, long sequenceLength, CancellationToken cancellationToken, IProgressHandler progress) { Guard.IsNotNull(inputStream, nameof(inputStream)); Guard.IsNotNull(weightsTable, nameof(weightsTable)); Guard.IsNotNull(outputStream, nameof(outputStream)); Guard.IsNotNegative(sequenceLength, nameof(sequenceLength)); HuffmanTreeBase tree = new HuffmanEncoder().BuildHuffmanTree(weightsTable); Decode(inputStream, tree, outputStream, sequenceLength, cancellationToken, progress); }
void IFileDecoder.Decode(IDecodingOutputStream outputStream, CancellationToken cancellationToken, IProgressHandler progress) { Trace += "->Decode;"; }