MCPcopy Create free account
hub / github.com/creatale/node-dv / huffmanDecodeSymbol

Function huffmanDecodeSymbol

deps/lodepng/lodepng.cpp:955–973  ·  view source on GitHub ↗

returns the code, or (unsigned)(-1) if error happened inbitlength is the length of the complete buffer, in bits (so its byte length times 8) */

Source from the content-addressed store, hash-verified

953inbitlength is the length of the complete buffer, in bits (so its byte length times 8)
954*/
955static unsigned huffmanDecodeSymbol(const unsigned char* in, size_t* bp,
956 const HuffmanTree* codetree, size_t inbitlength)
957{
958 unsigned treepos = 0, ct;
959 for(;;)
960 {
961 if(*bp >= inbitlength) return (unsigned)(-1); /*error: end of input memory reached without endcode*/
962 /*
963 decode the symbol from the tree. The "readBitFromStream" code is inlined in
964 the expression below because this is the biggest bottleneck while decoding
965 */
966 ct = codetree->tree2d[(treepos << 1) + READBIT(*bp, in)];
967 ++(*bp);
968 if(ct < codetree->numcodes) return ct; /*the symbol is decoded, return it*/
969 else treepos = ct - codetree->numcodes; /*symbol not yet decoded, instead move tree position*/
970
971 if(treepos >= codetree->numcodes) return (unsigned)(-1); /*error: it appeared outside the codetree*/
972 }
973}
974#endif /*LODEPNG_COMPILE_DECODER*/
975
976#ifdef LODEPNG_COMPILE_DECODER

Callers 2

getTreeInflateDynamicFunction · 0.85
inflateHuffmanBlockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected