MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / hufCompress

Function hufCompress

Source/ThirdParty/tinyexr.h:3072–3100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3070//
3071
3072static int hufCompress(const unsigned short raw[], int nRaw,
3073 char compressed[]) {
3074 if (nRaw == 0) return 0;
3075
3076 std::vector<long long> freq(HUF_ENCSIZE);
3077
3078 countFrequencies(freq, raw, nRaw);
3079
3080 int im = 0;
3081 int iM = 0;
3082 hufBuildEncTable(freq.data(), &im, &iM);
3083
3084 char *tableStart = compressed + 20;
3085 char *tableEnd = tableStart;
3086 hufPackEncTable(freq.data(), im, iM, &tableEnd);
3087 int tableLength = tableEnd - tableStart;
3088
3089 char *dataStart = tableEnd;
3090 int nBits = hufEncode(freq.data(), raw, nRaw, iM, dataStart);
3091 int data_length = (nBits + 7) / 8;
3092
3093 writeUInt(compressed, im);
3094 writeUInt(compressed + 4, iM);
3095 writeUInt(compressed + 8, tableLength);
3096 writeUInt(compressed + 12, nBits);
3097 writeUInt(compressed + 16, 0); // room for future extensions
3098
3099 return dataStart + data_length - compressed;
3100}
3101
3102static bool hufUncompress(const char compressed[], int nCompressed,
3103 std::vector<unsigned short> *raw) {

Callers 1

CompressPizFunction · 0.85

Calls 5

countFrequenciesFunction · 0.85
hufBuildEncTableFunction · 0.85
hufPackEncTableFunction · 0.85
hufEncodeFunction · 0.85
writeUIntFunction · 0.85

Tested by

no test coverage detected