| 2857 | // |
| 2858 | |
| 2859 | static bool hufDecode(const long long *hcode, // i : encoding table |
| 2860 | const HufDec *hdecod, // i : decoding table |
| 2861 | const char *in, // i : compressed input buffer |
| 2862 | int ni, // i : input size (in bits) |
| 2863 | int rlc, // i : run-length code |
| 2864 | int no, // i : expected output size (in bytes) |
| 2865 | unsigned short *out) // o: uncompressed output buffer |
| 2866 | { |
| 2867 | long long c = 0; |
| 2868 | int lc = 0; |
| 2869 | unsigned short *outb = out; // begin |
| 2870 | unsigned short *oe = out + no; // end |
| 2871 | const char *ie = in + (ni + 7) / 8; // input byte size |
| 2872 | |
| 2873 | // |
| 2874 | // Loop on input bytes |
| 2875 | // |
| 2876 | |
| 2877 | while (in < ie) { |
| 2878 | getChar(c, lc, in); |
| 2879 | |
| 2880 | // |
| 2881 | // Access decoding table |
| 2882 | // |
| 2883 | |
| 2884 | while (lc >= HUF_DECBITS) { |
| 2885 | const HufDec pl = hdecod[(c >> (lc - HUF_DECBITS)) & HUF_DECMASK]; |
| 2886 | |
| 2887 | if (pl.len) { |
| 2888 | // |
| 2889 | // Get short code |
| 2890 | // |
| 2891 | |
| 2892 | lc -= pl.len; |
| 2893 | // std::cout << "lit = " << pl.lit << std::endl; |
| 2894 | // std::cout << "rlc = " << rlc << std::endl; |
| 2895 | // std::cout << "c = " << c << std::endl; |
| 2896 | // std::cout << "lc = " << lc << std::endl; |
| 2897 | // std::cout << "in = " << in << std::endl; |
| 2898 | // std::cout << "out = " << out << std::endl; |
| 2899 | // std::cout << "oe = " << oe << std::endl; |
| 2900 | if (!getCode(pl.lit, rlc, c, lc, in, ie, out, outb, oe)) { |
| 2901 | return false; |
| 2902 | } |
| 2903 | } else { |
| 2904 | if (!pl.p) { |
| 2905 | return false; |
| 2906 | } |
| 2907 | // invalidCode(); // wrong code |
| 2908 | |
| 2909 | // |
| 2910 | // Search long code |
| 2911 | // |
| 2912 | |
| 2913 | unsigned int j; |
| 2914 | |
| 2915 | for (j = 0; j < pl.lit; j++) { |
| 2916 | int l = hufLength(hcode[pl.p[j]]); |
no test coverage detected