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) */
| 900 | inbitlength is the length of the complete buffer, in bits (so its byte length times 8) |
| 901 | */ |
| 902 | static 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 |
no outgoing calls
no test coverage detected