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) */
| 917 | inbitlength is the length of the complete buffer, in bits (so its byte length times 8) |
| 918 | */ |
| 919 | static unsigned huffmanDecodeSymbol(const unsigned char* in, size_t* bp, |
| 920 | const HuffmanTree* codetree, size_t inbitlength) |
| 921 | { |
| 922 | unsigned treepos = 0, ct; |
| 923 | for(;;) |
| 924 | { |
| 925 | if(*bp >= inbitlength) return (unsigned)(-1); /*error: end of input memory reached without endcode*/ |
| 926 | /* |
| 927 | decode the symbol from the tree. The "readBitFromStream" code is inlined in |
| 928 | the expression below because this is the biggest bottleneck while decoding |
| 929 | */ |
| 930 | ct = codetree->tree2d[(treepos << 1) + READBIT(*bp, in)]; |
| 931 | (*bp)++; |
| 932 | if(ct < codetree->numcodes) return ct; /*the symbol is decoded, return it*/ |
| 933 | else treepos = ct - codetree->numcodes; /*symbol not yet decoded, instead move tree position*/ |
| 934 | |
| 935 | if(treepos >= codetree->numcodes) return (unsigned)(-1); /*error: it appeared outside the codetree*/ |
| 936 | } |
| 937 | } |
| 938 | #endif /*LODEPNG_COMPILE_DECODER*/ |
| 939 | |
| 940 | #ifdef LODEPNG_COMPILE_DECODER |
no outgoing calls
no test coverage detected