FastLED 3.9.15
Loading...
Searching...
No Matches

◆ DecodeHuffmanQuads()

static int fl::third_party::DecodeHuffmanQuads ( int32_t * vwxy,
int nVals,
int tabIdx,
int bitsLeft,
const unsigned char * buf,
int bitOffset )
static

Definition at line 292 of file huffman.hpp.

293{
294 int i, v, w, x, y;
295 int len, maxBits, cachedBits, padBits;
296 unsigned int cache;
297 unsigned char cw, *tBase;
298
299 if (bitsLeft <= 0)
300 return 0;
301
302 tBase = (unsigned char *)quadTable + quadTabOffset[tabIdx];
303 maxBits = quadTabMaxBits[tabIdx];
304
305 /* initially fill cache with any partial byte */
306 cache = 0;
307 cachedBits = (8 - bitOffset) & 0x07;
308 if (cachedBits)
309 cache = (unsigned int)(*buf++) << (32 - cachedBits);
310 bitsLeft -= cachedBits;
311
312 i = padBits = 0;
313 while (i < (nVals - 3)) {
314 /* refill cache - assumes cachedBits <= 16 */
315 if (bitsLeft >= 16) {
316 /* load 2 new bytes into left-justified cache */
317 cache |= (unsigned int)(*buf++) << (24 - cachedBits);
318 cache |= (unsigned int)(*buf++) << (16 - cachedBits);
319 cachedBits += 16;
320 bitsLeft -= 16;
321 } else {
322 /* last time through, pad cache with zeros and drain cache */
323 if (cachedBits + bitsLeft <= 0) return i;
324 if (bitsLeft > 0) cache |= (unsigned int)(*buf++) << (24 - cachedBits);
325 if (bitsLeft > 8) cache |= (unsigned int)(*buf++) << (16 - cachedBits);
326 cachedBits += bitsLeft;
327 bitsLeft = 0;
328
329 cache &= (signed int)(int32_t)0x80000000 >> (cachedBits - 1);
330 padBits = 10;
331 cachedBits += padBits; /* okay if this is > 32 (0's automatically shifted in from right) */
332 }
333
334 /* largest maxBits = 6, plus 4 for sign bits, so make sure cache has at least 10 bits */
335 while (i < (nVals - 3) && cachedBits >= 10 ) {
336 cw = tBase[cache >> (32 - maxBits)];
337 len = GetHLenQ(cw);
338 cachedBits -= len;
339 cache <<= len;
340
341 v = GetCWVQ(cw); if(v) {ApplySign(v, cache); cache <<= 1; cachedBits--;}
342 w = GetCWWQ(cw); if(w) {ApplySign(w, cache); cache <<= 1; cachedBits--;}
343 x = GetCWXQ(cw); if(x) {ApplySign(x, cache); cache <<= 1; cachedBits--;}
344 y = GetCWYQ(cw); if(y) {ApplySign(y, cache); cache <<= 1; cachedBits--;}
345
346 /* ran out of bits - okay (means we're done) */
347 if (cachedBits < padBits)
348 return i;
349
350 *vwxy++ = v;
351 *vwxy++ = w;
352 *vwxy++ = x;
353 *vwxy++ = y;
354 i += 4;
355 }
356 }
357
358 /* decoded max number of quad values */
359 return i;
360}
#define GetCWVQ(x)
Definition huffman.hpp:59
#define GetCWWQ(x)
Definition huffman.hpp:60
#define GetHLenQ(x)
Definition huffman.hpp:58
#define ApplySign(x, s)
Definition huffman.hpp:65
#define GetCWXQ(x)
Definition huffman.hpp:61
#define GetCWYQ(x)
Definition huffman.hpp:62
const int32_t quadTabOffset[2]
Definition hufftabs.hpp:758
const unsigned char quadTable[64+16]
Definition hufftabs.hpp:743
const int32_t quadTabMaxBits[2]
Definition hufftabs.hpp:759
fl::i32 int32_t
Definition s16x16x4.h:220

References ApplySign, FL_NOEXCEPT, GetCWVQ, GetCWWQ, GetCWXQ, GetCWYQ, GetHLenQ, quadTable, quadTabMaxBits, quadTabOffset, fl::x, and fl::y.

Referenced by DecodeHuffman().

+ Here is the caller graph for this function: