MCPcopy Create free account
hub / github.com/RenderKit/embree / hufCompress

Function hufCompress

tutorials/common/image/tinyexr.h:3002–3030  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3000//
3001
3002static 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
3032static bool hufUncompress(const char compressed[], int nCompressed,
3033 std::vector<unsigned short> *raw) {

Callers 1

CompressPizFunction · 0.85

Calls 6

countFrequenciesFunction · 0.85
hufBuildEncTableFunction · 0.85
hufPackEncTableFunction · 0.85
hufEncodeFunction · 0.85
writeUIntFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected