MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / writeLZ77data

Function writeLZ77data

src/lodepng.cpp:1642–1668  ·  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

1640tree_d: the tree for distance codes.
1641*/
1642static void writeLZ77data(size_t* bp, ucvector* out, const uivector* lz77_encoded,
1643 const HuffmanTree* tree_ll, const HuffmanTree* tree_d)
1644{
1645 size_t i = 0;
1646 for(i = 0; i < lz77_encoded->size; i++)
1647 {
1648 unsigned val = lz77_encoded->data[i];
1649 addHuffmanSymbol(bp, out, HuffmanTree_getCode(tree_ll, val), HuffmanTree_getLength(tree_ll, val));
1650 if(val > 256) /*for a length code, 3 more things have to be added*/
1651 {
1652 unsigned length_index = val - FIRST_LENGTH_CODE_INDEX;
1653 unsigned n_length_extra_bits = LENGTHEXTRA[length_index];
1654 unsigned length_extra_bits = lz77_encoded->data[++i];
1655
1656 unsigned distance_code = lz77_encoded->data[++i];
1657
1658 unsigned distance_index = distance_code;
1659 unsigned n_distance_extra_bits = DISTANCEEXTRA[distance_index];
1660 unsigned distance_extra_bits = lz77_encoded->data[++i];
1661
1662 addBitsToStream(bp, out, length_extra_bits, n_length_extra_bits);
1663 addHuffmanSymbol(bp, out, HuffmanTree_getCode(tree_d, distance_code),
1664 HuffmanTree_getLength(tree_d, distance_code));
1665 addBitsToStream(bp, out, distance_extra_bits, n_distance_extra_bits);
1666 }
1667 }
1668}
1669
1670/*Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/
1671static 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