| 3000 | // |
| 3001 | |
| 3002 | static int hufCompress(const unsigned short raw[], int nRaw, |
| 3003 | char compressed[]) { |
| 3004 | if (nRaw == 0) return 0; |
| 3005 | |
| 3006 | std::vector<long long> freq(HUF_ENCSIZE); |
| 3007 | |
| 3008 | countFrequencies(freq, raw, nRaw); |
| 3009 | |
| 3010 | int im = 0; |
| 3011 | int iM = 0; |
| 3012 | hufBuildEncTable(freq.data(), &im, &iM); |
| 3013 | |
| 3014 | char *tableStart = compressed + 20; |
| 3015 | char *tableEnd = tableStart; |
| 3016 | hufPackEncTable(freq.data(), im, iM, &tableEnd); |
| 3017 | int tableLength = tableEnd - tableStart; |
| 3018 | |
| 3019 | char *dataStart = tableEnd; |
| 3020 | int nBits = hufEncode(freq.data(), raw, nRaw, iM, dataStart); |
| 3021 | int data_length = (nBits + 7) / 8; |
| 3022 | |
| 3023 | writeUInt(compressed, im); |
| 3024 | writeUInt(compressed + 4, iM); |
| 3025 | writeUInt(compressed + 8, tableLength); |
| 3026 | writeUInt(compressed + 12, nBits); |
| 3027 | writeUInt(compressed + 16, 0); // room for future extensions |
| 3028 | |
| 3029 | return dataStart + data_length - compressed; |
| 3030 | } |
| 3031 | |
| 3032 | static bool hufUncompress(const char compressed[], int nCompressed, |
| 3033 | std::vector<unsigned short> *raw) { |
no test coverage detected