MCPcopy Create free account
hub / github.com/OpenPathGuidingLibrary/openpgl / hufBuildEncTable

Function hufBuildEncTable

third-party/tinyexr/tinyexr.h:2224–2387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2222};
2223
2224static bool hufBuildEncTable(
2225 long long *frq, // io: input frequencies [HUF_ENCSIZE], output table
2226 int *im, // o: min frq index
2227 int *iM) // o: max frq index
2228{
2229 //
2230 // This function assumes that when it is called, array frq
2231 // indicates the frequency of all possible symbols in the data
2232 // that are to be Huffman-encoded. (frq[i] contains the number
2233 // of occurrences of symbol i in the data.)
2234 //
2235 // The loop below does three things:
2236 //
2237 // 1) Finds the minimum and maximum indices that point
2238 // to non-zero entries in frq:
2239 //
2240 // frq[im] != 0, and frq[i] == 0 for all i < im
2241 // frq[iM] != 0, and frq[i] == 0 for all i > iM
2242 //
2243 // 2) Fills array fHeap with pointers to all non-zero
2244 // entries in frq.
2245 //
2246 // 3) Initializes array hlink such that hlink[i] == i
2247 // for all array entries.
2248 //
2249
2250 std::vector<int> hlink(HUF_ENCSIZE);
2251 std::vector<long long *> fHeap(HUF_ENCSIZE);
2252
2253 *im = 0;
2254
2255 while (!frq[*im]) (*im)++;
2256
2257 int nf = 0;
2258
2259 for (int i = *im; i < HUF_ENCSIZE; i++) {
2260 hlink[i] = i;
2261
2262 if (frq[i]) {
2263 fHeap[nf] = &frq[i];
2264 nf++;
2265 *iM = i;
2266 }
2267 }
2268
2269 //
2270 // Add a pseudo-symbol, with a frequency count of 1, to frq;
2271 // adjust the fHeap and hlink array accordingly. Function
2272 // hufEncode() uses the pseudo-symbol for run-length encoding.
2273 //
2274
2275 (*iM)++;
2276 frq[*iM] = 1;
2277 fHeap[nf] = &frq[*iM];
2278 nf++;
2279
2280 //
2281 // Build an array, scode, such that scode[i] contains the number

Callers 1

hufCompressFunction · 0.85

Calls 3

FHeapCompareClass · 0.85
hufCanonicalCodeTableFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected