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. */
| 1780 | tree_d: the tree for distance codes. |
| 1781 | */ |
| 1782 | static void writeLZ77data(LodePNGBitWriter* writer, const uivector* lz77_encoded, |
| 1783 | const HuffmanTree* tree_ll, const HuffmanTree* tree_d) { |
| 1784 | size_t i = 0; |
| 1785 | for(i = 0; i != lz77_encoded->size; ++i) { |
| 1786 | unsigned val = lz77_encoded->data[i]; |
| 1787 | writeBitsReversed(writer, tree_ll->codes[val], tree_ll->lengths[val]); |
| 1788 | if(val > 256) /*for a length code, 3 more things have to be added*/ { |
| 1789 | unsigned length_index = val - FIRST_LENGTH_CODE_INDEX; |
| 1790 | unsigned n_length_extra_bits = LENGTHEXTRA[length_index]; |
| 1791 | unsigned length_extra_bits = lz77_encoded->data[++i]; |
| 1792 | |
| 1793 | unsigned distance_code = lz77_encoded->data[++i]; |
| 1794 | |
| 1795 | unsigned distance_index = distance_code; |
| 1796 | unsigned n_distance_extra_bits = DISTANCEEXTRA[distance_index]; |
| 1797 | unsigned distance_extra_bits = lz77_encoded->data[++i]; |
| 1798 | |
| 1799 | writeBits(writer, length_extra_bits, n_length_extra_bits); |
| 1800 | writeBitsReversed(writer, tree_d->codes[distance_code], tree_d->lengths[distance_code]); |
| 1801 | writeBits(writer, distance_extra_bits, n_distance_extra_bits); |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | /*Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/ |
| 1807 | static unsigned deflateDynamic(LodePNGBitWriter* writer, Hash* hash, |
no test coverage detected