示例#1
0
文件: paq1s.cs 项目: shitpoet/paq1s
    void compress_file(string fn, string cfn)
    {
        var bits = read_bits(fn);
        var bs   = len(bits);

        var ar = new Ar();

        for (var i = 0; i < N; i++)
        {
            m[i] = new Model(i);
        }

        foreach (var bit in bits)
        {
            var n = predict();
            ar.encode(bit, n[0], n[1]);
            update(bit);
        }

        var cbits_queue = ar.flush();

        int[] cbits = cbits_queue.ToArray();
        write_bits(cfn, cbits);

        var cbs = len(cbits);

        WriteLine($"orig size: {format_int(bs / 8)}");
        WriteLine($"comp size: {format_int(len(cbits) / 8)}");
        WriteLine($"ratio: {format_float(cbs * 100.0 / bs)}%");
        var bpc = cbs * 1.0 / (bs / 8);

        WriteLine($"{format_float(bpc)} bpc");

        var ok = check(fn, cfn, bs, cbs);

        WriteLine(ok ? "ok" : "check failed");
    }