MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / writeLZ77data

Function writeLZ77data

dependency/densecrf/examples/lodepng.cpp:1695–1721  ·  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

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