Ejemplo n.º 1
0
        internal int build_bl_tree()
        {
            scan_tree(dyn_ltree, treeLiterals.max_code);
            scan_tree(dyn_dtree, treeDistances.max_code);
            treeBitLengths.build_tree(this);
            int num = InternalConstants.BL_CODES - 1;

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

            if (compressionLevel > CompressionLevel.None)
            {
                if (data_type == Z_UNKNOWN)
                {
                    set_data_type();
                }
                treeLiterals.build_tree(this);
                treeDistances.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((STATIC_TREES << 1) + (eof ? 1 : 0), 3);
                send_compressed_block(StaticTree.lengthAndLiteralsTreeCodes, StaticTree.distTreeCodes);
            }
            else
            {
                send_bits((DYN_TREES << 1) + (eof ? 1 : 0), 3);
                send_all_trees(treeLiterals.max_code + 1, treeDistances.max_code + 1, num + 1);
                send_compressed_block(dyn_ltree, dyn_dtree);
            }
            _InitializeBlocks();
            if (eof)
            {
                bi_windup();
            }
        }