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

Function huffmanDecodeSymbol

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

900inbitlength is the length of the complete buffer, in bits (so its byte length times 8)
901*/
902static unsigned huffmanDecodeSymbol(const unsigned char* in, size_t* bp,
903 const HuffmanTree* codetree, size_t inbitlength)
904{
905 unsigned treepos = 0, ct;
906 for(;;)
907 {
908 if(*bp >= inbitlength) return (unsigned)(-1); /*error: end of input memory reached without endcode*/
909 /*
910 decode the symbol from the tree. The "readBitFromStream" code is inlined in
911 the expression below because this is the biggest bottleneck while decoding
912 */
913 ct = codetree->tree2d[(treepos << 1) + READBIT(*bp, in)];
914 (*bp)++;
915 if(ct < codetree->numcodes) return ct; /*the symbol is decoded, return it*/
916 else treepos = ct - codetree->numcodes; /*symbol not yet decoded, instead move tree position*/
917
918 if(treepos >= codetree->numcodes) return (unsigned)(-1); /*error: it appeared outside the codetree*/
919 }
920}
921#endif /*LODEPNG_COMPILE_DECODER*/
922
923#ifdef LODEPNG_COMPILE_DECODER

Callers 2

getTreeInflateDynamicFunction · 0.85
inflateHuffmanBlockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected