MCPcopy Create free account
hub / github.com/DFHack/dfhack / writeLZ77data

Function writeLZ77data

depends/lodepng/lodepng.cpp:1782–1804  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

1780tree_d: the tree for distance codes.
1781*/
1782static 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*/
1807static unsigned deflateDynamic(LodePNGBitWriter* writer, Hash* hash,

Callers 2

deflateDynamicFunction · 0.85
deflateFixedFunction · 0.85

Calls 2

writeBitsReversedFunction · 0.85
writeBitsFunction · 0.85

Tested by

no test coverage detected