private void Decompress(BitFile sourceFile, BitFile targetFile) { long originalSize = DecodeHeader(sourceFile); var predictor = new Predictor(); var decoder = new ArithmeticDecoder(sourceFile); while (targetFile.Length < originalSize) { double p0 = predictor.Predict(); var bit = decoder.Decode(p0); targetFile.Write(bit); predictor.Update((int)bit); } }
private void Compress(BitFile sourceFile, BitFile targetFile) { EncodeHeader(targetFile, sourceFile.Length); var predictor = new Predictor(); var encoder = new ArithmeticEncoder(targetFile); while (!sourceFile.IsEof) { var bit = sourceFile.Read(); double p0 = predictor.Predict(); // todo: remove casting encoder.Encode((int)bit, p0); predictor.Update((int)bit); } encoder.EncodeRemainingBits(); }