MCPcopy Create free account
hub / github.com/creatale/node-dv / writeLZ77data

Function writeLZ77data

deps/lodepng/lodepng.cpp:1703–1729  ·  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

1701tree_d: the tree for distance codes.
1702*/
1703static void writeLZ77data(size_t* bp, ucvector* out, const uivector* lz77_encoded,
1704 const HuffmanTree* tree_ll, const HuffmanTree* tree_d)
1705{
1706 size_t i = 0;
1707 for(i = 0; i != lz77_encoded->size; ++i)
1708 {
1709 unsigned val = lz77_encoded->data[i];
1710 addHuffmanSymbol(bp, out, HuffmanTree_getCode(tree_ll, val), HuffmanTree_getLength(tree_ll, val));
1711 if(val > 256) /*for a length code, 3 more things have to be added*/
1712 {
1713 unsigned length_index = val - FIRST_LENGTH_CODE_INDEX;
1714 unsigned n_length_extra_bits = LENGTHEXTRA[length_index];
1715 unsigned length_extra_bits = lz77_encoded->data[++i];
1716
1717 unsigned distance_code = lz77_encoded->data[++i];
1718
1719 unsigned distance_index = distance_code;
1720 unsigned n_distance_extra_bits = DISTANCEEXTRA[distance_index];
1721 unsigned distance_extra_bits = lz77_encoded->data[++i];
1722
1723 addBitsToStream(bp, out, length_extra_bits, n_length_extra_bits);
1724 addHuffmanSymbol(bp, out, HuffmanTree_getCode(tree_d, distance_code),
1725 HuffmanTree_getLength(tree_d, distance_code));
1726 addBitsToStream(bp, out, distance_extra_bits, n_distance_extra_bits);
1727 }
1728 }
1729}
1730
1731/*Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/
1732static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,

Callers 2

deflateDynamicFunction · 0.85
deflateFixedFunction · 0.85

Calls 4

addHuffmanSymbolFunction · 0.85
HuffmanTree_getCodeFunction · 0.85
HuffmanTree_getLengthFunction · 0.85
addBitsToStreamFunction · 0.85

Tested by

no test coverage detected