示例#1
0
        internal int build_bl_tree()
        {
            scan_tree(dyn_ltree, l_desc.max_code);
            scan_tree(dyn_dtree, d_desc.max_code);
            bl_desc.build_tree(this);
            int num = 18;

            while (num >= 3 && bl_tree[ZTree.bl_order[num] * 2 + 1] == 0)
            {
                num--;
            }
            opt_len += 3 * (num + 1) + 5 + 5 + 4;
            return(num);
        }
示例#2
0
        internal void _tr_flush_block(int buf, int stored_len, bool eof)
        {
            int num = 0;
            int num2;
            int num3;

            if (level > 0)
            {
                if (data_type == 2)
                {
                    set_data_type();
                }
                l_desc.build_tree(this);
                d_desc.build_tree(this);
                num  = build_bl_tree();
                num2 = opt_len + 3 + 7 >> 3;
                num3 = static_len + 3 + 7 >> 3;
                if (num3 <= num2)
                {
                    num2 = num3;
                }
            }
            else
            {
                num2 = (num3 = stored_len + 5);
            }
            if (stored_len + 4 <= num2 && buf != -1)
            {
                _tr_stored_block(buf, stored_len, eof);
            }
            else if (num3 == num2)
            {
                send_bits(2 + (eof ? 1 : 0), 3);
                compress_block(StaticTree.static_ltree, StaticTree.static_dtree);
            }
            else
            {
                send_bits(4 + (eof ? 1 : 0), 3);
                send_all_trees(l_desc.max_code + 1, d_desc.max_code + 1, num + 1);
                compress_block(dyn_ltree, dyn_dtree);
            }
            init_block();
            if (eof)
            {
                bi_windup();
            }
        }