MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / deflateDynamic

Function deflateDynamic

samples/shared/lodepng.cpp:1695–1938  ·  view source on GitHub ↗

Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/

Source from the content-addressed store, hash-verified

1693
1694/*Deflate for a block of type "dynamic", that is, with freely, optimally, created huffman trees*/
1695static unsigned deflateDynamic(ucvector* out, size_t* bp, Hash* hash,
1696 const unsigned char* data, size_t datapos, size_t dataend,
1697 const LodePNGCompressSettings* settings, unsigned final)
1698{
1699 unsigned error = 0;
1700
1701 /*
1702 A block is compressed as follows: The PNG data is lz77 encoded, resulting in
1703 literal bytes and length/distance pairs. This is then huffman compressed with
1704 two huffman trees. One huffman tree is used for the lit and len values ("ll"),
1705 another huffman tree is used for the dist values ("d"). These two trees are
1706 stored using their code lengths, and to compress even more these code lengths
1707 are also run-length encoded and huffman compressed. This gives a huffman tree
1708 of code lengths "cl". The code lenghts used to describe this third tree are
1709 the code length code lengths ("clcl").
1710 */
1711
1712 /*The lz77 encoded data, represented with integers since there will also be length and distance codes in it*/
1713 uivector lz77_encoded;
1714 HuffmanTree tree_ll; /*tree for lit,len values*/
1715 HuffmanTree tree_d; /*tree for distance codes*/
1716 HuffmanTree tree_cl; /*tree for encoding the code lengths representing tree_ll and tree_d*/
1717 uivector frequencies_ll; /*frequency of lit,len codes*/
1718 uivector frequencies_d; /*frequency of dist codes*/
1719 uivector frequencies_cl; /*frequency of code length codes*/
1720 uivector bitlen_lld; /*lit,len,dist code lenghts (int bits), literally (without repeat codes).*/
1721 uivector bitlen_lld_e; /*bitlen_lld encoded with repeat codes (this is a rudemtary run length compression)*/
1722 /*bitlen_cl is the code length code lengths ("clcl"). The bit lengths of codes to represent tree_cl
1723 (these are written as is in the file, it would be crazy to compress these using yet another huffman
1724 tree that needs to be represented by yet another set of code lengths)*/
1725 uivector bitlen_cl;
1726 size_t datasize = dataend - datapos;
1727
1728 /*
1729 Due to the huffman compression of huffman tree representations ("two levels"), there are some anologies:
1730 bitlen_lld is to tree_cl what data is to tree_ll and tree_d.
1731 bitlen_lld_e is to bitlen_lld what lz77_encoded is to data.
1732 bitlen_cl is to bitlen_lld_e what bitlen_lld is to lz77_encoded.
1733 */
1734
1735 unsigned BFINAL = final;
1736 size_t numcodes_ll, numcodes_d, i;
1737 unsigned HLIT, HDIST, HCLEN;
1738
1739 uivector_init(&lz77_encoded);
1740 HuffmanTree_init(&tree_ll);
1741 HuffmanTree_init(&tree_d);
1742 HuffmanTree_init(&tree_cl);
1743 uivector_init(&frequencies_ll);
1744 uivector_init(&frequencies_d);
1745 uivector_init(&frequencies_cl);
1746 uivector_init(&bitlen_lld);
1747 uivector_init(&bitlen_lld_e);
1748 uivector_init(&bitlen_cl);
1749
1750 /*This while loop never loops due to a break at the end, it is here to
1751 allow breaking out of it to the cleanup phase on error conditions.*/
1752 while(!error)

Callers 1

lodepng_deflatevFunction · 0.85

Calls 14

uivector_initFunction · 0.85
HuffmanTree_initFunction · 0.85
encodeLZ77Function · 0.85
uivector_resizeFunction · 0.85
uivector_resizevFunction · 0.85
uivector_push_backFunction · 0.85
HuffmanTree_getLengthFunction · 0.85
addBitsToStreamFunction · 0.85
addHuffmanSymbolFunction · 0.85
HuffmanTree_getCodeFunction · 0.85
writeLZ77dataFunction · 0.85

Tested by

no test coverage detected