Create the Huffman tree given the symbol frequencies*/
| 1044 | |
| 1045 | /*Create the Huffman tree given the symbol frequencies*/ |
| 1046 | static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigned* frequencies, |
| 1047 | size_t mincodes, size_t numcodes, unsigned maxbitlen) { |
| 1048 | unsigned error = 0; |
| 1049 | while(!frequencies[numcodes - 1] && numcodes > mincodes) --numcodes; /*trim zeroes*/ |
| 1050 | tree->lengths = (unsigned*)lodepng_malloc(numcodes * sizeof(unsigned)); |
| 1051 | if(!tree->lengths) return 83; /*alloc fail*/ |
| 1052 | tree->maxbitlen = maxbitlen; |
| 1053 | tree->numcodes = (unsigned)numcodes; /*number of symbols*/ |
| 1054 | |
| 1055 | error = lodepng_huffman_code_lengths(tree->lengths, frequencies, numcodes, maxbitlen); |
| 1056 | if(!error) error = HuffmanTree_makeFromLengths2(tree); |
| 1057 | return error; |
| 1058 | } |
| 1059 | #endif /*LODEPNG_COMPILE_ENCODER*/ |
| 1060 | |
| 1061 | /*get the literal and length code tree of a deflated block with fixed tree, as per the deflate specification*/ |
no test coverage detected