MCPcopy Create free account
hub / github.com/BlueAndi/Pixelix / getCode

Method getCode

lib/YAWidgets/src/LzwDecoder.cpp:337–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335}
336
337bool LzwDecoder::getCode(uint32_t& code, const ReadFromInStream& readFromInStreamFunc)
338{
339 bool isSuccessful = true;
340 uint32_t codeBitsNeeded = m_codeWidth;
341
342 code = 0U;
343
344 /* Run as long as code bits are still needed. */
345 while ((0U < codeBitsNeeded) && (true == isSuccessful))
346 {
347 /* No bits in the buffer anymore? */
348 if (0U == m_bitsInBuffer)
349 {
350 uint8_t data = 0U;
351
352 /* Read data from code stream. */
353 if (false == readFromInStreamFunc(data))
354 {
355 /* No more data is available, abort now. */
356 isSuccessful = false;
357 }
358 else
359 {
360 m_codeBuffer = data;
361 m_bitsInBuffer = 8U;
362 }
363 }
364
365 if (true == isSuccessful)
366 {
367 uint32_t bitsAvailable = (m_bitsInBuffer < codeBitsNeeded) ? m_bitsInBuffer : codeBitsNeeded;
368 uint32_t mask = (1U << bitsAvailable) - 1U; /* Mask for n bits. */
369
370 code |= (m_codeBuffer & mask) << (m_codeWidth - codeBitsNeeded);
371
372 /* Remove bits from code buffer. */
373 m_codeBuffer >>= bitsAvailable;
374 m_bitsInBuffer -= bitsAvailable;
375
376 /* Now less bits are needed. */
377 codeBitsNeeded -= bitsAvailable;
378 }
379 }
380
381 return isSuccessful;
382}
383
384bool LzwDecoder::decompress(uint32_t code, const WriteToOutStream& writeToOutStreamFunc)
385{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected