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

Function hufBuildDecTable

third-party/tinyexr/tinyexr.h:2535–2617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2533//
2534
2535static bool hufBuildDecTable(const long long *hcode, // i : encoding table
2536 int im, // i : min index in hcode
2537 int iM, // i : max index in hcode
2538 HufDec *hdecod) // o: (allocated by caller)
2539// decoding table [HUF_DECSIZE]
2540{
2541 //
2542 // Init hashtable & loop on all codes.
2543 // Assumes that hufClearDecTable(hdecod) has already been called.
2544 //
2545
2546 for (; im <= iM; im++) {
2547 long long c = hufCode(hcode[im]);
2548 int l = hufLength(hcode[im]);
2549
2550 if (c >> l) {
2551 //
2552 // Error: c is supposed to be an l-bit code,
2553 // but c contains a value that is greater
2554 // than the largest l-bit number.
2555 //
2556
2557 // invalidTableEntry();
2558 return false;
2559 }
2560
2561 if (l > HUF_DECBITS) {
2562 //
2563 // Long code: add a secondary entry
2564 //
2565
2566 HufDec *pl = hdecod + (c >> (l - HUF_DECBITS));
2567
2568 if (pl->len) {
2569 //
2570 // Error: a short code has already
2571 // been stored in table entry *pl.
2572 //
2573
2574 // invalidTableEntry();
2575 return false;
2576 }
2577
2578 pl->lit++;
2579
2580 if (pl->p) {
2581 unsigned int *p = pl->p;
2582 pl->p = new unsigned int[pl->lit];
2583
2584 for (unsigned int i = 0; i < pl->lit - 1u; ++i) pl->p[i] = p[i];
2585
2586 delete[] p;
2587 } else {
2588 pl->p = new unsigned int[1];
2589 }
2590
2591 pl->p[pl->lit - 1] = im;
2592 } else if (l) {

Callers 1

hufUncompressFunction · 0.85

Calls 2

hufCodeFunction · 0.85
hufLengthFunction · 0.85

Tested by

no test coverage detected