write the lz77-encoded data, which has lit, len and dist codes, to compressed stream using huffman trees. tree_ll: the tree for lit and len codes. tree_d: the tree for distance codes. */
| 1664 | tree_d: the tree for distance codes. |
| 1665 | */ |
| 1666 | static void writeLZ77data(size_t* bp, ucvector* out, const uivector* lz77_encoded, |
| 1667 | const HuffmanTree* tree_ll, const HuffmanTree* tree_d) |
| 1668 | { |
| 1669 | size_t i = 0; |
| 1670 | for(i = 0; i < lz77_encoded->size; i++) |
| 1671 | { |
| 1672 | unsigned val = lz77_encoded->data[i]; |
| 1673 | addHuffmanSymbol(bp, out, HuffmanTree_getCode(tree_ll, val), HuffmanTree_getLength(tree_ll, val)); |
| 1674 | if(val > 256) /*for a length code, 3 more things have to be added*/ |
| 1675 | { |
| 1676 | unsigned length_index = val - FIRST_LENGTH_CODE_INDEX; |
| 1677 | unsigned n_length_extra_bits = LENGTHEXTRA[length_index]; |
| 1678 | unsigned length_extra_bits = lz77_encoded->data[++i]; |
| 1679 | |
| 1680 | unsigned distance_code = lz77_encoded->data[++i]; |
| 1681 | |
| 1682 | unsigned distance_index = distance_code; |
| 1683 | unsigned n_distance_extra_bits = DISTANCEEXTRA[distance_index]; |
| 1684 | unsigned distance_extra_bits = lz77_encoded->data[++i]; |
| 1685 | |
| 1686 | addBitsToStream(bp, out, length_extra_bits, n_length_extra_bits); |
| 1687 | addHuffmanSymbol(bp, out, HuffmanTree_getCode(tree_d, distance_code), |
| 1688 | HuffmanTree_getLength(tree_d, distance_code)); |
| 1689 | addBitsToStream(bp, out, distance_extra_bits, n_distance_extra_bits); |
| 1690 | } |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | /*Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/ |
| 1695 | static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash, |
no test coverage detected