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

Function hufEncode

third-party/tinyexr/tinyexr.h:2663–2704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2661//
2662
2663static int hufEncode // return: output size (in bits)
2664 (const long long *hcode, // i : encoding table
2665 const unsigned short *in, // i : uncompressed input buffer
2666 const int ni, // i : input buffer size (in bytes)
2667 int rlc, // i : rl code
2668 char *out) // o: compressed output buffer
2669{
2670 char *outStart = out;
2671 long long c = 0; // bits not yet written to out
2672 int lc = 0; // number of valid bits in c (LSB)
2673 int s = in[0];
2674 int cs = 0;
2675
2676 //
2677 // Loop on input values
2678 //
2679
2680 for (int i = 1; i < ni; i++) {
2681 //
2682 // Count same values or send code
2683 //
2684
2685 if (s == in[i] && cs < 255) {
2686 cs++;
2687 } else {
2688 sendCode(hcode[s], cs, hcode[rlc], c, lc, out);
2689 cs = 0;
2690 }
2691
2692 s = in[i];
2693 }
2694
2695 //
2696 // Send remaining code
2697 //
2698
2699 sendCode(hcode[s], cs, hcode[rlc], c, lc, out);
2700
2701 if (lc) *out = (c << (8 - lc)) & 0xff;
2702
2703 return (out - outStart) * 8 + lc;
2704}
2705
2706//
2707// DECODING

Callers 1

hufCompressFunction · 0.85

Calls 1

sendCodeFunction · 0.85

Tested by

no test coverage detected