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) */
| 945 | inbitlength is the length of the complete buffer, in bits (so its byte length times 8) |
| 946 | */ |
| 947 | static unsigned huffmanDecodeSymbol(const unsigned char* in, size_t* bp, |
| 948 | const HuffmanTree* codetree, size_t inbitlength) |
| 949 | { |
| 950 | unsigned treepos = 0, ct; |
| 951 | for(;;) |
| 952 | { |
| 953 | if(*bp >= inbitlength) return (unsigned)(-1); /*error: end of input memory reached without endcode*/ |
| 954 | /* |
| 955 | decode the symbol from the tree. The "readBitFromStream" code is inlined in |
| 956 | the expression below because this is the biggest bottleneck while decoding |
| 957 | */ |
| 958 | ct = codetree->tree2d[(treepos << 1) + READBIT(*bp, in)]; |
| 959 | ++(*bp); |
| 960 | if(ct < codetree->numcodes) return ct; /*the symbol is decoded, return it*/ |
| 961 | else treepos = ct - codetree->numcodes; /*symbol not yet decoded, instead move tree position*/ |
| 962 | |
| 963 | if(treepos >= codetree->numcodes) return (unsigned)(-1); /*error: it appeared outside the codetree*/ |
| 964 | } |
| 965 | } |
| 966 | #endif /*LODEPNG_COMPILE_DECODER*/ |
| 967 | |
| 968 | #ifdef LODEPNG_COMPILE_DECODER |
no outgoing calls
no test coverage detected