示例#1
0
文件: Paq1.cs 项目: daywee/PAQ1
        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);
            }
        }
示例#2
0
文件: Paq1.cs 项目: daywee/PAQ1
        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();
        }