MCPcopy Create free account
hub / github.com/NVlabs/flip / hufCanonicalCodeTable

Function hufCanonicalCodeTable

src/cpp/tool/tinyexr.h:8518–8557  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8516 //
8517
8518 static void hufCanonicalCodeTable(long long hcode[HUF_ENCSIZE]) {
8519 long long n[59];
8520
8521 //
8522 // For each i from 0 through 58, count the
8523 // number of different codes of length i, and
8524 // store the count in n[i].
8525 //
8526
8527 for (int i = 0; i <= 58; ++i) n[i] = 0;
8528
8529 for (int i = 0; i < HUF_ENCSIZE; ++i) n[hcode[i]] += 1;
8530
8531 //
8532 // For each i from 58 through 1, compute the
8533 // numerically lowest code with length i, and
8534 // store that code in n[i].
8535 //
8536
8537 long long c = 0;
8538
8539 for (int i = 58; i > 0; --i) {
8540 long long nc = ((c + n[i]) >> 1);
8541 n[i] = c;
8542 c = nc;
8543 }
8544
8545 //
8546 // hcode[i] contains the length, l, of the
8547 // code for symbol i. Assign the next available
8548 // code of length l to the symbol and store both
8549 // l and the code in hcode[i].
8550 //
8551
8552 for (int i = 0; i < HUF_ENCSIZE; ++i) {
8553 int l = static_cast<int>(hcode[i]);
8554
8555 if (l > 0) hcode[i] = l | (n[l]++ << 6);
8556 }
8557 }
8558
8559 //
8560 // Compute Huffman codes (based on frq input) and store them in frq:

Callers 2

hufBuildEncTableFunction · 0.85
hufUnpackEncTableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected