rEFIt_UEFI/libeg/lodepng.cpp
/*Create the Huffman tree given the symbol frequencies*/
Create the Huffman tree given the symbol frequencies
Create the Huffman tree given the symbol frequencies
static unsigned HuffmanTree_makeFromFrequencies(HuffmanTree* tree, const unsigned* frequencies,
                                                size_t mincodes, size_t numcodes, unsigned maxbitlen) {
  unsigned error = 0;
  while(!frequencies[numcodes - 1] && numcodes > mincodes) --numcodes; 
  tree->lengths = (unsigned*)lodepng_malloc(numcodes * sizeof(unsigned));
  if(!tree->lengths) return 83; 
  tree->maxbitlen = maxbitlen;
  tree->numcodes = (unsigned)numcodes; 
  error = lodepng_huffman_code_lengths(tree->lengths, frequencies, numcodes, maxbitlen);
  if(!error) error = HuffmanTree_makeFromLengths2(tree);
  return error;
}
static unsigned HuffmanTree_makeFromFrequencies ( HuffmanTree * tree , const unsigned * frequencies , size_t mincodes , size_t numcodes , unsigned maxbitlen ) { unsigned error = 0 ; while ( ! frequencies [ numcodes - 1 ] && numcodes > mincodes ) -- numcodes ; tree -> lengths = ( unsigned * ) lodepng_malloc ( numcodes * sizeof ( unsigned ) ) ; if ( ! tree -> lengths ) return 83 ; tree -> maxbitlen = maxbitlen ; tree -> numcodes = ( unsigned ) numcodes ; error = lodepng_huffman_code_lengths ( tree -> lengths , frequencies , numcodes , maxbitlen ) ; if ( ! error ) error = HuffmanTree_makeFromLengths2 ( tree ) ; return error ; }
Create the Huffman tree given the symbol frequencies
Create the Huffman tree given the symbol frequencies
/*trim zeroes*/ /*alloc fail*/ /*number of symbols*/