📄 blkdec.c
字号:
_BSFastGetBits2(cbits,1,*pBitsUsed,uNextBit); // sign bit if (bIntra) decodeIntraVLCtableIndex (iIndex, iLevel, iRun, bIsLastRun, uNextBit); else decodeInterVLCtableIndex (iIndex, iLevel, iRun, bIsLastRun, uNextBit); //printf("1, bits used is %d\n", *pBitsUsed); //get level back iLevelPlusAbs = abs (*iLevel); iLevelAbs = iLevelPlusAbs + rgiLMAX [(*iRun & 0x0000003F) + (*bIsLastRun << 6)]; //hashing the table *iLevel = sign(*iLevel) * iLevelAbs; } else // vlc; Run+ { _BSFastGetBits2(cbits,1,*pBitsUsed, uNextBit ); if (!uNextBit) { iIndex = decodeSymbol_WithFastBS(pHD,cbits,&iBitsUsed); (*pBitsUsed)+=iBitsUsed; cbits<<=iBitsUsed; _BSFastGetBits2(cbits,1,*pBitsUsed, uNextBit ); // sign bit if (bIntra) decodeIntraVLCtableIndex (iIndex, iLevel, iRun, bIsLastRun, uNextBit); else decodeInterVLCtableIndex (iIndex, iLevel, iRun, bIsLastRun, uNextBit); //printf("2, bits used is %d\n", *pBitsUsed); *iRun = *iRun + rgiRMAX [(abs(*iLevel) & 0x0000001F) + (*bIsLastRun << 5)]; //get run back; RMAX tabl incl. + 1 already } else // flc { Int iMaxAC; _BSFastGetBits2(cbits,1,*pBitsUsed, *bIsLastRun); _BSFastGetBits2(cbits,NUMBITS_ESC_RUN,*pBitsUsed, *iRun);#ifndef NO_ASSERTS assert (*iRun < BLOCK_SQUARE_SIZE);#endif iLevelBits = 12; // = m_volmd.nBits; _BSFastGetBits2(cbits,1,*pBitsUsed, iMarker); #ifndef NO_ASSERTS assert(iMarker == 1);#endif _BSFastGetBits2(cbits,iLevelBits,*pBitsUsed, *iLevel); _BSFastGetBits2(cbits,1,*pBitsUsed, iMarker); #ifndef NO_ASSERTS assert(iMarker == 1);#endif iMaxAC = (1<<(iLevelBits-1)) - 1;#ifndef NO_ASSERTS assert(*iLevel!=iMaxAC+1);#endif if (*iLevel > iMaxAC) *iLevel -= (1<<iLevelBits);#ifndef NO_ASSERTS assert(*iLevel != 0);#endif } } } // Escape coding short headers. Added by KPN else { _BSFastGetBits2(cbits,1,*pBitsUsed, *bIsLastRun); _BSFastGetBits2(cbits,6,*pBitsUsed, *iRun); _BSFastGetBits2(cbits,8,*pBitsUsed, iLevelIndex); // printf("4, bits used is %d\n", *pBitsUsed); if (iLevelIndex == 0 || iLevelIndex == 128) { fprintf(stderr,"Short header mode. Levels 0 and 128 are not allowed\n"); exit(2); } if (iLevelIndex >= 0 && iLevelIndex < 128) *iLevel = iLevelIndex; else *iLevel = iLevelIndex-256; }}#endifINLINE Void decodeIntraTCOEF (Int iCoefStart, Int* rgiZigzag){ Bool bIsLastRun = FALSE; Int iRun = 0, iLevel = 0, iCoef = iCoefStart, iSignBit; Long lIndex;#ifdef USE_BSFAST _BSFAST_DECL; UInt bitsread; _BSFAST_INIT();#endif while (!bIsLastRun) { if (!main_short_video_header) {#ifdef USE_BSFAST lIndex = decodeSymbol_WithFastBS(m_pentrdecDCTIntra,_BSFastCurrentBits(), &bitsread); // MPEG-4#else lIndex = decodeSymbol(m_pentrdecDCTIntra); // MPEG-4#endif // USE_BSFAST } // Added for short headers by KPN (1998-02-07, DS) else {#ifdef USE_BSFAST lIndex = decodeSymbol_WithFastBS(m_pentrdecDCT, _BSFastCurrentBits(), &bitsread); // H.263#else lIndex = decodeSymbol(m_pentrdecDCT); // H.263#endif // USE_BSFAST }#ifdef USE_BSFAST _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#endif // Added for short headers by KPN - END if (lIndex != TCOEF_ESCAPE) {#ifdef USE_BSFAST iSignBit = _BSFastGetBits(1);#else MP4V_RETSINGLEBIT (&iSignBit); // sign bit#endif // MPEG-4 if (!main_short_video_header) decodeIntraVLCtableIndex (lIndex, &iLevel, &iRun, &bIsLastRun, iSignBit); // short header else // Added by KPN [FDS] { Bool tempBool = (Bool) bIsLastRun; decodeInterVLCtableIndex (lIndex, &iLevel, &iRun, &tempBool, iSignBit); bIsLastRun = (Int) tempBool; } } else {#ifdef USE_BSFAST decodeEscape_WithFastBS(&iLevel, &iRun, &bIsLastRun, g_rgiLMAXintra, g_rgiRMAXintra, m_pentrdecDCTIntra, TRUE,_BSFastCurrentBits(),&bitsread); _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#else decodeEscape (&iLevel, &iRun, &bIsLastRun, g_rgiLMAXintra, g_rgiRMAXintra, m_pentrdecDCTIntra, TRUE);#endif // USE_BSFAST } iCoef+=iRun; g_pIQOutput [rgiZigzag [iCoef] ^ 1] = iLevel; iCoef++; } #ifdef USE_BSFAST _BSFAST_DONE();#endif }INLINE Void decodeInterTCOEF (){ Bool bIsLastRun = FALSE; Int iRun = 0, iLevel = 0, iCoef = 0, iSignBit; Long lIndex;#ifdef ENABLE_NON_RECTANGLE_USAGE Int* rgiZigzag = (g_pVOP->bAlternateScan) ? grgiVerticalZigzag : grgiStandardZigzag;#else Int* rgiZigzag = grgiStandardZigzag;#endif#ifdef USE_BSFAST _BSFAST_DECL; UInt bitsread; _BSFAST_INIT();#endif while (!bIsLastRun) {#ifdef USE_BSFAST lIndex = decodeSymbol_WithFastBS(m_pentrdecDCT,_BSFastCurrentBits(),&bitsread); _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#else lIndex = decodeSymbol(m_pentrdecDCT);#endif // USE_BSFAST if (lIndex != TCOEF_ESCAPE) // if Huffman {#ifdef USE_BSFAST iSignBit = _BSFastGetBits(1);#else MP4V_RETSINGLEBIT (&iSignBit); // sign bit#endif decodeInterVLCtableIndex (lIndex, &iLevel, &iRun, &bIsLastRun, iSignBit);#ifndef NO_ASSERTS assert (iRun < BLOCK_SQUARE_SIZE);#endif } else {#ifdef USE_BSFAST decodeEscape_WithFastBS (&iLevel, &iRun, &bIsLastRun, g_rgiLMAXinter, g_rgiRMAXinter, m_pentrdecDCT, FALSE, _BSFastCurrentBits(),&bitsread); _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#else decodeEscape (&iLevel, &iRun, &bIsLastRun, g_rgiLMAXinter, g_rgiRMAXinter, m_pentrdecDCT, FALSE);#endif // USE_BSFAST } iCoef+=iRun; g_pIQOutput [rgiZigzag [iCoef] ^ 1] = 2*iLevel + sign(iLevel); iCoef++; } #ifdef USE_BSFAST _BSFAST_DONE();#endif}INLINE Void decodeIntraVLCtableIndex (Int iIndex, Int *iLevel, Int *iRun, Int *bIsLastRun, Int iSignBit){ *iLevel = INTRA_LEVELMASK & grgiIntraYAVCLHashingTable [iIndex]; *iRun = (INTRA_RUNMASK & grgiIntraYAVCLHashingTable [iIndex]) >> 5; *bIsLastRun = (INTRA_LASTRUNMASK & grgiIntraYAVCLHashingTable [iIndex]) >> 10; if (iSignBit) *iLevel = -(*iLevel);#ifndef NO_ASSERTS assert (*iRun < BLOCK_SQUARE_SIZE);#endif}// return islastrun, run and levelINLINE Void decodeInterVLCtableIndex (Int iIndex, Int *iLevel, Int *iRun, Bool *bIsLastRun, Int iSignBit){ Int iLocalRun = 0, iLocalLevel; Bool bLocalLastRun = FALSE; UInt *uiLevelArray = grgIfNotLastNumOfLevelAtRun; // Use this pointer inside the while#ifndef NO_ASSERTS assert (iIndex >= 0 && iIndex < 102);#endif if (iIndex >= 58) { iIndex -= 58; bLocalLastRun = TRUE; uiLevelArray = grgIfLastNumOfLevelAtRun; } while (iIndex >= 0) { iIndex -= uiLevelArray [iLocalRun]; // Can directly use uiLevelArray since we have set this up properly iLocalRun++; }#ifndef NO_ASSERTS assert (iLocalRun > 0);#endif iLocalRun--; iLocalLevel = iIndex + uiLevelArray [iLocalRun] + 1;#ifndef NO_ASSERTS assert (iLocalRun >= 0);#endif if (iSignBit) iLocalLevel = -iLocalLevel; // Restore back the values *iRun = iLocalRun; *bIsLastRun = bLocalLastRun; *iLevel = iLocalLevel;}INLINE Void decodeIntraDCmpeg (Bool bIsYBlk){ Long lSzDiffIntraDC; Int iDiffIntraDC = 0; U8 chDiffIntraDC; UInt uiDiffIntraDC;#ifdef USE_BSFAST _BSFAST_DECL; UInt bitsread; _BSFAST_INIT();#endif if (bIsYBlk)#ifdef USE_BSFAST lSzDiffIntraDC = decodeSymbol_WithFastBS(m_pentrdecIntraDCy,_BSFastCurrentBits(), &bitsread);#else lSzDiffIntraDC = decodeSymbol(m_pentrdecIntraDCy);#endif // USE_BSFAST else #ifdef USE_BSFAST lSzDiffIntraDC = decodeSymbol_WithFastBS(m_pentrdecIntraDCc,_BSFastCurrentBits(), &bitsread);#else lSzDiffIntraDC = decodeSymbol(m_pentrdecIntraDCc);#endif // USE_BSFAST#ifdef USE_BSFAST _BSFastSkipBits(bitsread); _BSFastCheckedPreload();#endif if (lSzDiffIntraDC !=0 ) { if (lSzDiffIntraDC<=8) // NBIT {#ifdef USE_BSFAST chDiffIntraDC = (U8)_BSFastGetBits (lSzDiffIntraDC); #else chDiffIntraDC = (U8) getBits (lSzDiffIntraDC); #endif if (!((1 << (lSzDiffIntraDC - 1)) & chDiffIntraDC)) iDiffIntraDC = -1 * ((0x00FF >> (8 - lSzDiffIntraDC)) & (~chDiffIntraDC)); else iDiffIntraDC = (Int) chDiffIntraDC; } else // NBIT - marker bit inserted after 8 bits {#ifdef USE_BSFAST uiDiffIntraDC = (U8)_BSFastGetBits (lSzDiffIntraDC); #else uiDiffIntraDC = (UInt) getBits (lSzDiffIntraDC);#endif if (!((1 << (lSzDiffIntraDC - 1)) & uiDiffIntraDC)) iDiffIntraDC = -1 * ((0xFFFF >> (16 - lSzDiffIntraDC)) & (~uiDiffIntraDC)); else iDiffIntraDC = (Int) uiDiffIntraDC;#ifdef USE_BSFAST _BSFastGetBits(1);#else // re-using bIsYBlk here again to aviod declaring another local variable MP4V_RETSINGLEBIT (&bIsYBlk); #endif } }#ifdef USE_BSFAST _BSFAST_DONE();#endif // Save the DC value (swizzle the array index, 0 ^ 1 = 1) g_pIQOutput [1] = iDiffIntraDC;}INLINE Void inverseDCACPred (CMBMode* pmbmd, Int iBlkIdx, Int iQP, Int iDcScaler, BlockMemory blkmPred, Int iQpPred){ UInt nBits = g_pVOL->nBits; // NBIT Int iDefVal = 1<<(nBits+2); // NBIT Int i, j; // do DC prediction if (!main_short_video_header) { // Added by KPN for short video headers if (blkmPred == NULL) g_pIQOutput [1] += DIVROUNDNEAREST(iDefVal, iDcScaler); else { g_pIQOutput [1] += DIVROUNDNEAREST(blkmPred [0], iDcScaler); // clip range after inverse pred g_pIQOutput [1] = g_pIQOutput[1] < -2048 ? -2048 : (g_pIQOutput[1] > 2047 ? 2047 : g_pIQOutput[1]); if (iBlkIdx<(A_BLOCK1 - 1) && pmbmd->m_bACPrediction) { int k; // do AC prediction if (pmbmd->m_preddir [iBlkIdx] == HORIZONTAL) { int x = 2 * BLOCK_SIZE - 1; for (i = 8, j = 8; j < x; i += 8, j++) { k = i ^ 1; g_pIQOutput [k] += (blkmPred == NULL) ? 0 : (iQP == iQpPred) ? blkmPred [j] : DIVROUNDNEAREST(blkmPred [j] * iQpPred, iQP); // clip range after inverse pred g_pIQOutput [k] = g_pIQOutput [k] < -2048 ? -2048 : (g_pIQOutput [k] > 2047 ? 2047 : g_pIQOutput [k]); } } else if (pmbmd->m_preddir [iBlkIdx] == VERTICAL) { //horizontal zigzag scan for (i = 1; i < BLOCK_SIZE; i++) { k = i ^ 1; g_pIQOutput [k] += (blkmPred == NULL) ? 0 : (iQP == iQpPred) ? blkmPred [i] : DIVROUNDNEAREST(blkmPred [i] * iQpPred, iQP); // clip range after inverse pred g_pIQOutput [k] = g_pIQOutput [k] < -2048 ? -2048 : (g_pIQOutput [k] > 2047 ? 2047 : g_pIQOutput [k]); } }#ifndef NO_ASSERTS else assert (FALSE);#endif } } }// End short video headers}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -