private final static void gen_codes( short[] tree, // the tree to decorate int max_code, // largest code with non zero frequency short[] bl_count, // number of codes at each bit length short[] next_code){ short code = 0; // running code value int bits; // bit index int n; // code index // The distribution counts are first used to generate the code values // without bit reversal. next_code[0]=0; for (bits = 1; bits <= MAX_BITS; bits++) { next_code[bits] = code = (short)((code + bl_count[bits-1]) << 1); } // Check that the bit counts in bl_count are consistent. The last code // must be all ones. //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, // "inconsistent bit counts"); //Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); for (n = 0; n <= max_code; n++) { int len = tree[n*2+1]; if (len == 0) continue; // Now reverse the bits tree[n*2] = (short)(bi_reverse(next_code[len]++, len)); } }
dyn_dtree[Tree.d_code(dist)*2]++;
gen_bitlen(s); gen_codes(tree, max_code, s.bl_count, s.next_code);
int build_bl_tree(){ int max_blindex; // index of last bit length code of non zero freq // Determine the bit length frequencies for literal and distance trees scan_tree(dyn_ltree, l_desc.max_code); scan_tree(dyn_dtree, d_desc.max_code); // Build the bit length tree: bl_desc.build_tree(this); // opt_len now includes the length of the tree representations, except // the lengths of the bit lengths codes and the 5+5+4 bits for the counts. // Determine the number of bit length codes to send. The pkzip format // requires that at least 4 bit length codes be sent. (appnote.txt says // 3 but the actual value used is 4.) for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { if (bl_tree[Tree.bl_order[max_blindex]*2+1] != 0) break; } // Update opt_len to include the bit length tree and counts opt_len += 3*(max_blindex+1) + 5+5+4; return max_blindex; }
gen_bitlen(s); gen_codes(tree, max_code, s.bl_count, s.next_code);
int build_bl_tree(){ int max_blindex; // index of last bit length code of non zero freq // Determine the bit length frequencies for literal and distance trees scan_tree(dyn_ltree, l_desc.max_code); scan_tree(dyn_dtree, d_desc.max_code); // Build the bit length tree: bl_desc.build_tree(this); // opt_len now includes the length of the tree representations, except // the lengths of the bit lengths codes and the 5+5+4 bits for the counts. // Determine the number of bit length codes to send. The pkzip format // requires that at least 4 bit length codes be sent. (appnote.txt says // 3 but the actual value used is 4.) for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { if (bl_tree[Tree.bl_order[max_blindex]*2+1] != 0) break; } // Update opt_len to include the bit length tree and counts opt_len += 3*(max_blindex+1) + 5+5+4; return max_blindex; }
gen_bitlen(s); gen_codes(tree, max_code, s.bl_count);
int build_bl_tree(){ int max_blindex; // index of last bit length code of non zero freq // Determine the bit length frequencies for literal and distance trees scan_tree(dyn_ltree, l_desc.max_code); scan_tree(dyn_dtree, d_desc.max_code); // Build the bit length tree: bl_desc.build_tree(this); // opt_len now includes the length of the tree representations, except // the lengths of the bit lengths codes and the 5+5+4 bits for the counts. // Determine the number of bit length codes to send. The pkzip format // requires that at least 4 bit length codes be sent. (appnote.txt says // 3 but the actual value used is 4.) for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { if (bl_tree[Tree.bl_order[max_blindex]*2+1] != 0) break; } // Update opt_len to include the bit length tree and counts opt_len += 3*(max_blindex+1) + 5+5+4; return max_blindex; }
dyn_dtree[Tree.d_code(dist)*2]++;
static void gen_codes(short[] tree, // the tree to decorate int max_code, // largest code with non zero frequency short[] bl_count // number of codes at each bit length ){ short[] next_code=new short[MAX_BITS+1]; // next code value for each bit length short code = 0; // running code value int bits; // bit index int n; // code index // The distribution counts are first used to generate the code values // without bit reversal. for (bits = 1; bits <= MAX_BITS; bits++) { next_code[bits] = code = (short)((code + bl_count[bits-1]) << 1); } // Check that the bit counts in bl_count are consistent. The last code // must be all ones. //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, // "inconsistent bit counts"); //Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); for (n = 0; n <= max_code; n++) { int len = tree[n*2+1]; if (len == 0) continue; // Now reverse the bits tree[n*2] = (short)(bi_reverse(next_code[len]++, len)); } }
gen_bitlen(s); gen_codes(tree, max_code, s.bl_count);
int build_bl_tree(){ int max_blindex; // index of last bit length code of non zero freq // Determine the bit length frequencies for literal and distance trees scan_tree(dyn_ltree, l_desc.max_code); scan_tree(dyn_dtree, d_desc.max_code); // Build the bit length tree: bl_desc.build_tree(this); // opt_len now includes the length of the tree representations, except // the lengths of the bit lengths codes and the 5+5+4 bits for the counts. // Determine the number of bit length codes to send. The pkzip format // requires that at least 4 bit length codes be sent. (appnote.txt says // 3 but the actual value used is 4.) for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { if (bl_tree[Tree.bl_order[max_blindex]*2+1] != 0) break; } // Update opt_len to include the bit length tree and counts opt_len += 3*(max_blindex+1) + 5+5+4; return max_blindex; }
dyn_dtree[Tree.d_code(dist)*2]++;
static void gen_codes(short[] tree, // the tree to decorate int max_code, // largest code with non zero frequency short[] bl_count // number of codes at each bit length ){ short[] next_code=new short[MAX_BITS+1]; // next code value for each bit length short code = 0; // running code value int bits; // bit index int n; // code index // The distribution counts are first used to generate the code values // without bit reversal. for (bits = 1; bits <= MAX_BITS; bits++) { next_code[bits] = code = (short)((code + bl_count[bits-1]) << 1); } // Check that the bit counts in bl_count are consistent. The last code // must be all ones. //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, // "inconsistent bit counts"); //Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); for (n = 0; n <= max_code; n++) { int len = tree[n*2+1]; if (len == 0) continue; // Now reverse the bits tree[n*2] = (short)(bi_reverse(next_code[len]++, len)); } }
gen_bitlen(s); gen_codes(tree, max_code, s.bl_count);
int build_bl_tree(){ int max_blindex; // index of last bit length code of non zero freq // Determine the bit length frequencies for literal and distance trees scan_tree(dyn_ltree, l_desc.max_code); scan_tree(dyn_dtree, d_desc.max_code); // Build the bit length tree: bl_desc.build_tree(this); // opt_len now includes the length of the tree representations, except // the lengths of the bit lengths codes and the 5+5+4 bits for the counts. // Determine the number of bit length codes to send. The pkzip format // requires that at least 4 bit length codes be sent. (appnote.txt says // 3 but the actual value used is 4.) for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { if (bl_tree[Tree.bl_order[max_blindex]*2+1] != 0) break; } // Update opt_len to include the bit length tree and counts opt_len += 3*(max_blindex+1) + 5+5+4; return max_blindex; }
dyn_dtree[Tree.d_code(dist)*2]++;
static void gen_codes(short[] tree, // the tree to decorate int max_code, // largest code with non zero frequency short[] bl_count // number of codes at each bit length ){ short[] next_code=new short[MAX_BITS+1]; // next code value for each bit length short code = 0; // running code value int bits; // bit index int n; // code index // The distribution counts are first used to generate the code values // without bit reversal. for (bits = 1; bits <= MAX_BITS; bits++) { next_code[bits] = code = (short)((code + bl_count[bits-1]) << 1); } // Check that the bit counts in bl_count are consistent. The last code // must be all ones. //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, // "inconsistent bit counts"); //Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); for (n = 0; n <= max_code; n++) { int len = tree[n*2+1]; if (len == 0) continue; // Now reverse the bits tree[n*2] = (short)(bi_reverse(next_code[len]++, len)); } }
gen_bitlen(s); gen_codes(tree, max_code, s.bl_count, s.next_code);
int build_bl_tree(){ int max_blindex; // index of last bit length code of non zero freq // Determine the bit length frequencies for literal and distance trees scan_tree(dyn_ltree, l_desc.max_code); scan_tree(dyn_dtree, d_desc.max_code); // Build the bit length tree: bl_desc.build_tree(this); // opt_len now includes the length of the tree representations, except // the lengths of the bit lengths codes and the 5+5+4 bits for the counts. // Determine the number of bit length codes to send. The pkzip format // requires that at least 4 bit length codes be sent. (appnote.txt says // 3 but the actual value used is 4.) for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { if (bl_tree[Tree.bl_order[max_blindex]*2+1] != 0) break; } // Update opt_len to include the bit length tree and counts opt_len += 3*(max_blindex+1) + 5+5+4; return max_blindex; }