📄 vld.c
字号:
if (labs((int32)level) > (int32)incVlc[tabNum]) tabNum++; } } /* * Get total number of zero coefficients */ if (totalCoef < 16-dcSkip) { bibShowMax16bits(bitbuf, 9, &bits); totalZerosPtr = &totalZerosTab[totalZerosTabOffset[totalCoef-1]]; code = totalZerosPtr[(int)bits>>6]; if (code > 0xc0) { offset = code - 0xc0; code = totalZerosPtr[offset+(((int)bits>>3)&7)]; if (code > 0xc0) { offset = code - 0xc0; code = totalZerosPtr[offset+((int)bits&7)]; } } totalZeros = code & 15; numBits = code >> 4; bibSkipBits(bitbuf, numBits); } else totalZeros = 0; /* All coefficients are initially zero */ for (i = 0; i < 16; i+=4) { tmpCoef[i+0] = 0; tmpCoef[i+1] = 0; tmpCoef[i+2] = 0; tmpCoef[i+3] = 0; } /* * Get run of zeros before each coefficient and store coeffs. in tmpCoef */ zerosLeft = totalZeros; coefPos = totalCoef + totalZeros - 1; coefNum = totalCoef - 1; while (zerosLeft > 0 && coefNum > 0) { tmpCoef[dcSkip+coefPos] = tmpLevel[coefNum]; // select VLC for runbefore tabNum = zerosLeft <= 7 ? zerosLeft-1 : 6; bibShowMax8bits(bitbuf, 3, &bits); if (tabNum == 6 && bits == 0) { bibShowMax16bits(bitbuf, 11, &bits); if (bits == 0) return VLD_ERROR; numLeadingZeroBits = numLeadZerosTab[(int)bits>>1]; run = 7 + numLeadingZeroBits; if (run > zerosLeft) return VLD_ERROR; numBits = 4 + numLeadingZeroBits; } else { code = runBeforeTab[tabNum][(int)bits]; run = code & 15; numBits = code >> 4; } bibSkipBits(bitbuf, numBits); zerosLeft -= run; coefPos -= run + 1; coefNum--; } do { tmpCoef[dcSkip+coefPos] = tmpLevel[coefNum]; coefPos--; coefNum--; } while (coefNum >= 0); /* Inverse zig-zag scan to produce final block of coefficients */ vldInvZigZagScan4x4(tmpCoef, coef); return VLD_OK;}/* * * get2x2coefsCDC: * * Parameters: * bitbuf Bitbuffer object * coef Return pointer for 2x2 coefficients * numCoef Return pointer number of nonzero cefficients * * Function: * Decode coefficients for 2x2 DC block. * * Returns: * VLD_OK for no error, VLD_ERROR for error * */static int get2x2coefsCDC(bitbuffer_s *bitbuf, int coef[4], int *numCoef){ int tabNum; u_int32 bits; int code; int numTrailingOnes; int numLeadingZeroBits; int totalCoef; int numBits; int tmpLevel[4]; int level; int numBigCoef; u_int32 signs; int s; int i; int totalZeros; int zerosLeft; int run; int coefPos; int coefNum; static const unsigned int incVlc[7] = { 0,3,6,12,24,48,32768 /* maximum vlc = 6 */ }; /* * Decode number of coefficients and number of trailing ones */ bibShowMax16bits(bitbuf, 10, &bits); /* Compute number of leading zeros using look-up table */ numLeadingZeroBits = numLeadZerosTab[(int)bits>>(10-7)]; /* Shift excess bits away */ bits >>= 10-3-numLeadingZeroBits; /* Fetch numTrailingOnes and totalCoef */ code = numCoefTrailTabChroma[numLeadingZeroBits][(int)bits&3]; numTrailingOnes = code & 3; totalCoef = (code >> 2) & 7; numBits = (code >> 5) + 1; bibSkipBits(bitbuf, numBits); *numCoef = totalCoef; if (totalCoef == 0) return VLD_OK; /* * Decode signs for trailing ones */ numBigCoef = totalCoef - numTrailingOnes; if (numTrailingOnes != 0) { /* Get signs for trailing ones. There can be maximum of 3 of them */ bibGetMax8bits(bitbuf, numTrailingOnes, &signs); for (i = numTrailingOnes-1; i >= 0; i--) { s = ((int)signs >> i) & 1; tmpLevel[numBigCoef+i] = 1 - 2*s; } } if (numBigCoef != 0) { /* * Decode first level */ level = getCoefLevelVLC0(bitbuf); if (numTrailingOnes < 3) level += (level > 0) ? 1 : -1; tmpLevel[numBigCoef-1] = level; tabNum = (labs((int32)level) > 3) ? 2 : 1; /* * Decode rest of the levels */ for (i = numBigCoef - 2; i >= 0; i--) { level = getCoefLevelVLCN(bitbuf, tabNum); tmpLevel[i] = level; /* update VLC table number */ if (labs((int32)level) > (int32)incVlc[tabNum]) tabNum++; } } /* * Get total zeros */ if (totalCoef < 4) { bibShowMax8bits(bitbuf, 3, &bits); code = totalZerosTabChroma[totalCoef-1][(int)bits]; totalZeros = code & 15; numBits = code >> 4; bibSkipBits(bitbuf, numBits); } else totalZeros = 0; /* All coefficients are initially zero */ coef[0] = 0; coef[1] = 0; coef[2] = 0; coef[3] = 0; /* * Get run before each coefficient */ zerosLeft = totalZeros; coefPos = totalCoef + totalZeros - 1; coefNum = totalCoef - 1; while (zerosLeft > 0 && coefNum > 0) { coef[coefPos] = tmpLevel[coefNum]; bibShowMax8bits(bitbuf, 3, &bits); code = runBeforeTab[zerosLeft-1][(int)bits]; run = code & 15; numBits = code >> 4; bibSkipBits(bitbuf, numBits); zerosLeft -= run; coefPos -= run + 1; coefNum--; } do { coef[coefPos] = tmpLevel[coefNum]; coefPos--; coefNum--; } while (coefNum >= 0); return VLD_OK;}/* * * vldGetLumaDCcoeffs: * * Parameters: * bitbuf Bitbuffer object * coef Return pointer for 4x4 coefficients * numCoefUpPred Block coefficients counts of upper block * numCoefLeftPred Block coefficient counts of blocks to the left * mbAvailBits Macroblock availability flags * * Function: * Decode coefficients for 4x4 luma DC block. * * Returns: * VLD_OK for no error, negative value for error * */int vldGetLumaDCcoeffs(bitbuffer_s *bitbuf, int coef[4][4], int8 *numCoefUpPred, int8 *numCoefLeftPred, int mbAvailBits){ int j; int8 numCoef = *numCoefUpPred; int8 numCoefLP = *numCoefLeftPred; int retCode; retCode = get4x4coefs(bitbuf, coef, 0, 0, &numCoef, &numCoefLP, mbAvailBits, 0); if (retCode < 0) return retCode; if (numCoef == 0) { for (j = 0; j < 4; j++) { coef[j][0] = 0; coef[j][1] = 0; coef[j][2] = 0; coef[j][3] = 0; } } if (bibGetStatus(bitbuf) < 0) return VLD_ERROR; else return VLD_OK;}/* * * vldGetLumaCoeffs: * * Parameters: * bitbuf Bitbuffer object * mbType Macroblock type (intra/inter) * intraType Intra type (16x16 or 4x4 intra pred) * cbpY Return pointer coded block pattern * coef Return pointer for 16x4x4 coefficients * numCoefUpPred Block coefficients counts of upper block * numCoefLeftPred Block coefficient counts of blocks to the left * mbAvailBits Macroblock availability flags * * Function: * Decode coefficients for 16 4x4 luma blocks. * * Returns: * VLD_OK for no error, negative value for error * */int vldGetLumaCoeffs(bitbuffer_s *bitbuf, int mbType, int intraType, int *cbpY, int coef[4][4][4][4], int8 *numCoefUpPred, int8 *numCoefLeftPred, int mbAvailBits){ int bx, by; int blkIdxX, blkIdxY; int i, j; int cbp, cbpTemp; int dcSkip; int retCode; dcSkip = mbType == MBK_INTRA && intraType == MBK_INTRA_TYPE2 ? 1 : 0; cbp = cbpTemp = *cbpY; for (by = 0; by < 4; by+=2) { for (bx = 0; bx < 4; bx+=2) { /* Check if any of the blocks in the current 8x8 block is codec */ if ((cbpTemp & 33) != 0) { for (j = 0; j < 2; j++) { for (i = 0; i < 2; i++) { blkIdxX = bx + i; blkIdxY = by + j; retCode = get4x4coefs(bitbuf, coef[blkIdxY][blkIdxX], blkIdxX, blkIdxY, &numCoefUpPred[blkIdxX], &numCoefLeftPred[blkIdxY], mbAvailBits, dcSkip); if (retCode < 0) return retCode; if (numCoefUpPred[blkIdxX] == 0) cbp &= ~(1<<(blkIdxY*BLK_PER_MB+blkIdxX)); } } } else { numCoefUpPred[bx] = 0; numCoefUpPred[bx+1] = 0; numCoefLeftPred[by] = 0; numCoefLeftPred[by+1] = 0; } cbpTemp >>= 2; } cbpTemp >>= 4; } *cbpY = cbp; if (bibGetStatus(bitbuf) < 0) return VLD_ERROR; else return VLD_OK;}/* * * vldGetChromaDCcoeffs: * * Parameters: * bitbuf Bitbuffer object * coef Return pointer for 2x2x2 coefficients * cbpYDC Return pointer chroma DC coded block pattern * * Function: * Decode coefficients for 2 2x2 chroma DC blocks. * * Returns: * VLD_OK for no error, negative value for error * */int vldGetChromaDCcoeffs(bitbuffer_s *bitbuf, int coef[2][2][2], int *cbpDC){ int comp; int numCoef; int retCode; for (comp = 0; comp < 2; comp++) { retCode = get2x2coefsCDC(bitbuf, &coef[comp][0][0], &numCoef); if (retCode < 0) return retCode; if (numCoef == 0) *cbpDC &= ~(1<<comp); } if (bibGetStatus(bitbuf) < 0) return VLD_ERROR; else return VLD_OK;}/* * * vldGetChromaCoeffs: * * Parameters: * bitbuf Bitbuffer object * coef Return pointer for 2x2x2x4x4 coefficients * cbp Return pointer chroma coded block pattern * numCoefUpPred Block coefficients counts of upper block for U frame * numCoefUpPredV Block coefficients counts of upper block for V frame * numCoefLeftPred Block coefficient counts of blocks to the left for U frame * numCoefLeftPredV Block coefficient counts of blocks to the left for V frame * mbAvailBits Macroblock availability flags * * Function: * Decode coefficients for 8 4x4 chroma blocks. * * Returns: * VLD_OK for no error, negative value for error * */int vldGetChromaCoeffs(bitbuffer_s *bitbuf, int coef[2][2][2][4][4], int *cbp, int8 *numCoefUpPred, int8 *numCoefUpPredV, int8 *numCoefLeftPred, int8 *numCoefLeftPredV, int mbAvailBits){ int comp; int i, j; int retCode; for (comp = 0; comp < 2; comp++) { for (j = 0; j < 2; j++) { for (i = 0; i < 2; i++) { retCode = get4x4coefs(bitbuf, coef[comp][j][i], i, j, &numCoefUpPred[i], &numCoefLeftPred[j], mbAvailBits, 1); if (retCode < 0) return retCode; if (numCoefUpPred[i] == 0) *cbp &= ~(1<<(comp*4+j*2+i)); } } /* Switch to V frame */ numCoefUpPred = numCoefUpPredV; numCoefLeftPred = numCoefLeftPredV; } if (bibGetStatus(bitbuf) < 0) return VLD_ERROR; else return VLD_OK;}/* * * vldGetZeroLumaCoeffs: * * Parameters: * numCoefUpPred Block coefficient counts of upper block * numCoefLeftPred Block coefficient counts of blocks to the left * * Function: * Called when there are no luma coefficients. * Sets luma cefficient counts to zero for current MB. * * Returns: * - */void vldGetZeroLumaCoeffs(int8 *numCoefUpPred, int8 *numCoefLeftPred){ int i; for (i = 0; i < 4; i++) { numCoefUpPred[i] = 0; numCoefLeftPred[i] = 0; }}/* * * vldGetZeroChromaCoeffs: * * Parameters: * numCoefUpPredU Block coefficient counts of upper block for U frame * numCoefUpPredV Block coefficient counts of upper block for V frame * numCoefLeftPred Block coefficient counts of blocks to the left * * Function: * Called when there are no chroma coefficients. * Sets chroma cefficient counts to zero for current MB. * * Returns: * - */void vldGetZeroChromaCoeffs(int8 *numCoefUpPredU, int8 *numCoefUpPredV, int8 numCoefLeftPred[2][2]){ int i; for (i = 0; i < 2; i++) { numCoefUpPredU[i] = 0; numCoefUpPredV[i] = 0; numCoefLeftPred[0][i] = 0; numCoefLeftPred[1][i] = 0; }}/* * * vldGetAllCoeffs: * * Parameters: * numCoefUpPredY Block coefficient counts for Y frame * numCoefUpPredU Block coefficient counts for U frame * numCoefUpPredV Block coefficient counts for V frame * numCoefLeftPredY Luma block coefficient counts of blocks to the left * numCoefLeftPredC Chroma block coefficient counts of blocks to the left * * Function: * Called when all coefficients are non-zero (e.g. PCM mactroblock). * Sets cefficient counts to "all coded". * * Returns: * - */void vldGetAllCoeffs(int8 *numCoefUpPredY, int8 *numCoefUpPredU, int8 *numCoefUpPredV, int8 *numCoefLeftPredY, int8 numCoefLeftPredC[2][2]){ int i; for (i = 0; i < 4; i++) { numCoefUpPredY[i] = 16; numCoefLeftPredY[i] = 16; } for (i = 0; i < 2; i++) { numCoefUpPredU[i] = 16; numCoefUpPredV[i] = 16; numCoefLeftPredC[0][i] = 16; numCoefLeftPredC[1][i] = 16; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -