| 2805 | // |
| 2806 | |
| 2807 | static int hufEncode // return: output size (in bits) |
| 2808 | (const long long *hcode, // i : encoding table |
| 2809 | const unsigned short *in, // i : uncompressed input buffer |
| 2810 | const int ni, // i : input buffer size (in bytes) |
| 2811 | int rlc, // i : rl code |
| 2812 | char *out) // o: compressed output buffer |
| 2813 | { |
| 2814 | char *outStart = out; |
| 2815 | long long c = 0; // bits not yet written to out |
| 2816 | int lc = 0; // number of valid bits in c (LSB) |
| 2817 | int s = in[0]; |
| 2818 | int cs = 0; |
| 2819 | |
| 2820 | // |
| 2821 | // Loop on input values |
| 2822 | // |
| 2823 | |
| 2824 | for (int i = 1; i < ni; i++) { |
| 2825 | // |
| 2826 | // Count same values or send code |
| 2827 | // |
| 2828 | |
| 2829 | if (s == in[i] && cs < 255) { |
| 2830 | cs++; |
| 2831 | } else { |
| 2832 | sendCode(hcode[s], cs, hcode[rlc], c, lc, out); |
| 2833 | cs = 0; |
| 2834 | } |
| 2835 | |
| 2836 | s = in[i]; |
| 2837 | } |
| 2838 | |
| 2839 | // |
| 2840 | // Send remaining code |
| 2841 | // |
| 2842 | |
| 2843 | sendCode(hcode[s], cs, hcode[rlc], c, lc, out); |
| 2844 | |
| 2845 | if (lc) *out = (c << (8 - lc)) & 0xff; |
| 2846 | |
| 2847 | return (out - outStart) * 8 + lc; |
| 2848 | } |
| 2849 | |
| 2850 | // |
| 2851 | // DECODING |
no test coverage detected