MCPcopy Create free account
hub / github.com/ImpulseAdventure/JPEGsnoop / DecodeScanComp

Method DecodeScanComp

ImgDecode.cpp:1604–1835  ·  view source on GitHub ↗

Decode a single component for one block of an MCU - Pull bits from the main buffer - Find matching huffman codes - Fill in the IDCT matrix (m_anDctBlock[]) - Perform the IDCT to create spatial domain INPUT: - nTblDhtDc = DHT table ID for DC component - nTblDhtAc = DHT talbe ID for AC component - nMcuX = UNUSED - nMcuY = UNUSED RETURN: - Indicate if the decode was successful POST

Source from the content-addressed store, hash-verified

1602// FIXME: Consider adding checks for DHT table like in ReadScanVal()
1603//
1604bool CimgDecode::DecodeScanComp(unsigned nTblDhtDc,unsigned nTblDhtAc,unsigned nTblDqt,unsigned nMcuX,unsigned nMcuY)
1605{
1606 nMcuX; // Unreferenced param
1607 nMcuY; // Unreferenced param
1608 unsigned nZrl;
1609 signed nVal;
1610 bool bDone = false;
1611 bool bDC = true; // Start with DC coeff
1612
1613 teRsvRet eRsvRet; // Return value from ReadScanVal()
1614
1615 unsigned nNumCoeffs = 0;
1616 //unsigned nDctMax = 0; // Maximum DCT coefficient to use for IDCT
1617 unsigned nSavedBufPos = 0;
1618 unsigned nSavedBufErr = SCANBUF_OK;
1619 unsigned nSavedBufAlign = 0;
1620
1621 // Profiling: No difference noted
1622 DecodeIdctClear();
1623
1624 while (!bDone) {
1625 BuffTopup();
1626
1627 // Note that once we perform ReadScanVal(), then GetScanBufPos() will be
1628 // after the decoded VLC
1629 // Save old file position info in case we want accurate error positioning
1630 nSavedBufPos = m_anScanBuffPtr_pos[0];
1631 nSavedBufErr = m_nScanBuffLatchErr;
1632 nSavedBufAlign = m_nScanBuffPtr_align;
1633
1634 // ReadScanVal return values:
1635 // - RSV_OK OK
1636 // - RSV_EOB End of block
1637 // - RSV_UNDERFLOW Ran out of data in buffer
1638 // - RSV_RST_TERM No huffman code found, but restart marker seen
1639 // Assume nTblDht just points to DC tables, adjust for AC
1640 // e.g. nTblDht = 0,2,4
1641 eRsvRet = ReadScanVal(bDC?0:1,bDC?nTblDhtDc:nTblDhtAc,nZrl,nVal);
1642
1643 // Handle Restart marker first.
1644 if (eRsvRet == RSV_RST_TERM) {
1645 // Assume that m_bRestartRead is TRUE
1646 // No huffman code found because either we ran out of bits
1647 // in the scan buffer or the bits padded with 1's didn't result
1648 // in a valid VLC code.
1649
1650 // Steps:
1651 // 1) Reset the decoder state (DC values)
1652 // 2) Advance the buffer pointer (might need to handle the
1653 // case of perfect alignment to byte boundary separately)
1654 // 3) Flush the Scan Buffer
1655 // 4) Clear m_bRestartRead
1656 // 5) Refill Scan Buffer with BuffTopUp()
1657 // 6) Re-invoke ReadScanVal()
1658
1659 // Step 1:
1660 DecodeRestartDcState();
1661

Callers

nothing calls this directly

Calls 1

AddLineErrMethod · 0.80

Tested by

no test coverage detected