⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_h264_mc.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        int ref_off = 0;        for (uBlock=0; uBlock<4; uBlock++)        {            block_ref = pRefIdxL0[ref_off];            prev_frame = block_ref >=0 ? get_chroma_ptr(pRefPicList0[block_ref], is_v_plane) + uOffset : 0;            block_ref = pRefIdxL1[ref_off];            futr_frame = block_ref >=0 ? get_chroma_ptr(pRefPicList1[block_ref], is_v_plane) + uOffset : 0;            switch (pMBData->SBType[uBlock])            {                case SBTYPE_8x8:                case SBTYPE_FORWARD_8x8:                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + SubpelChromaMVAdjust(pMVFwd, uPitch, iXType, iYType);                    // interpolate copy the 4x4 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size4x4);                    break;                case SBTYPE_BACKWARD_8x8:                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + SubpelChromaMVAdjust(pMVBwd, uPitch, iXType, iYType);                    // interpolate copy the 4x4 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size4x4);                    break;                case SBTYPE_8x4:                case SBTYPE_FORWARD_8x4:                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + SubpelChromaMVAdjust(pMVFwd, uPitch, iXType, iYType);                    // interpolate copy the first 4x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size4x2);                    // Update MV, Ref & Dst pointers for block 1                    pMCMV = pMVFwd + uWidthIn4x4Blocks;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + uPitch*2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + DEST_PITCH*2;                    // interpolate copy the second 4x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size4x2);                    break;                case SBTYPE_BACKWARD_8x4:                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + SubpelChromaMVAdjust(pMVBwd, uPitch, iXType, iYType);                    // interpolate copy the first 4x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size4x2);                    // Update MV, Ref & Dst pointers for block 1                    pMCMV = pMVBwd + uWidthIn4x4Blocks;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + uPitch*2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + DEST_PITCH*2;                    // interpolate copy the second 4x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size4x2);                    break;                case SBTYPE_4x8:                case SBTYPE_FORWARD_4x8:                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + SubpelChromaMVAdjust(pMVFwd, uPitch, iXType, iYType);                    // interpolate copy the first 2x4 block                    //(*m_MCCopyChroma)(pMCRef, pDst, uPitch, DEST_PITCH, 2, 4, iXType, iYType);                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size2x4);                    // Update MV, Ref & Dst pointers for block 1                    pMCMV = pMVFwd + 1;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + 2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + 2;                    // interpolate copy the second 2x4 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size2x4);                    break;                case SBTYPE_BACKWARD_4x8:                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + SubpelChromaMVAdjust(pMVBwd, uPitch, iXType, iYType);                    // interpolate copy the first 2x4 block                    //(*m_MCCopyChroma)(pMCRef, pDst, uPitch, DEST_PITCH, 2, 4, iXType, iYType);                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size2x4);                    // Update MV, Ref & Dst pointers for block 1                    pMCMV = pMVBwd + 1;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + 2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + 2;                    // interpolate copy the second 2x4 block                    //(*m_MCCopyChroma)(pMCRef, pMCDst, uPitch, DEST_PITCH, 2, 4, iXType, iYType);                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size2x4);                    break;                case SBTYPE_4x4:                case SBTYPE_FORWARD_4x4:                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + SubpelChromaMVAdjust(pMVFwd, uPitch, iXType, iYType);                    // interpolate copy the first 2x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size2x2);                    // Update MV, Ref & Dst pointers for block 1                    pMCMV = pMVFwd + 1;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + 2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + 2;                    // interpolate copy the second 2x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size2x2);                    // Update MV, Ref & Dst pointers for block 2                    pMCMV = pMVFwd + uWidthIn4x4Blocks;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + uPitch*2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + DEST_PITCH*2;                    // interpolate copy the third 2x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size2x2);                    // Update MV, Ref & Dst pointers for block 3                    pMCMV = pMVFwd + uWidthIn4x4Blocks + 1;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = prev_frame + uPitch*2 + 2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + DEST_PITCH*2 + 2;                    // interpolate copy the fourth 4x4 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size2x2);                    break;                case SBTYPE_BACKWARD_4x4:                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + SubpelChromaMVAdjust(pMVBwd, uPitch, iXType, iYType);                    // interpolate copy the first 2x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size2x2);                    // Update MV, Ref & Dst pointers for block 1                    pMCMV = pMVBwd + 1;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + 2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + 2;                    // interpolate copy the second 2x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size2x2);                    // Update MV, Ref & Dst pointers for block 2                    pMCMV = pMVBwd + uWidthIn4x4Blocks;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + uPitch*2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + DEST_PITCH*2;                    // interpolate copy the third 2x2 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size2x2);                    // Update MV, Ref & Dst pointers for block 3                    pMCMV = pMVBwd + uWidthIn4x4Blocks + 1;                    // convert 1/4 pel vector to pel vector and interpolation type                    pMCRef = futr_frame + uPitch*2 + 2 + SubpelChromaMVAdjust(pMCMV, uPitch, iXType, iYType);                    pMCDst = pDst + DEST_PITCH*2 + 2;                    // interpolate copy the fourth 4x4 block                    ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pMCDst, DEST_PITCH, iXType, iYType, size2x2);                    break;                case SBTYPE_DIRECT:                case SBTYPE_BIDIR_8x8:                case SBTYPE_BIDIR_8x4:                case SBTYPE_BIDIR_4x8:                case SBTYPE_BIDIR_4x4:                    // Do nothing in these cases because it was detected above and the entire block was done first...                break;                default:                break;            }            pMVFwd += (uBlock & 1) ? (uWidthIn4x4Blocks * 2 - 2) : 2; // Every 4th MV in the MB            pMVBwd += (uBlock & 1) ? (uWidthIn4x4Blocks * 2 - 2) : 2; // Every 4th MV in the MB            ref_off += (uBlock & 1) ? (uWidthIn4x4Blocks * 2 - 2) : 2; // Every 4th MV in the MB            uOffset += m_EncBlockOffsetInc[uBlock+16];            // advance dest buffer pointer by 4 after block 0 and 2; and by            // 3*DEST_PITCH+12 (row pitch is DEST_PITCH) after block 1.            pDst += 4 + (uBlock&1)*(3*DEST_PITCH+8);        }        }        break;    default:        // not supposed to be here        break;    }   // switch}   // MCOneMBChroma////////////////////////////////////////////////////////////////////////////////// C_DirectB_PredictOneMB_Cr//// Predict chroma values of current direct B mode macroblock by interpolating// from previous and future references.//////////////////////////////////////////////////////////////////////////////////void  DirectB_PredictOneMB_Cr(    Ipp8u *const        pDirB,      // pointer to current direct mode MB buffer    const Ipp8u *const  pPrev,      // pointer to previous ref plane buffer    const Ipp8u *const  pFutr,      // pointer to future ref plane buffer    const Ipp32u        uRefPitch,  // reference buffers pitch    const Ipp32u        uInterpType,// 0 = Skip, 1 = Default, 2 = Implicit Weighted    const Ipp32s        W0,    const Ipp32s        W1,    const IppiSize & roiSize){    if (!uInterpType)    {        for (Ipp32s i = 0, k = 0; i < roiSize.height; i ++, k += uRefPitch)            memcpy(pDirB + i * 16, pPrev + k, roiSize.width * sizeof(Ipp8u));    }    else if (uInterpType == 2)    {        for (Ipp32s i = 0, k = 0; i < roiSize.height; i ++, k += uRefPitch)            for (Ipp32s j = 0; j < roiSize.width; j ++)            {                pDirB[i * 16 + j] = (Ipp8u) ((pPrev[k + j] * W0 + pFutr[k + j] * W1 + 32) >> 6);            }    } else  {        for (Ipp32s i = 0, k = 0; i < roiSize.height; i ++, k += uRefPitch)            for (Ipp32s j = 0; j < roiSize.width; j ++)            {                pDirB[i * 16 + j]                    = (Ipp8u) ((pPrev[k + j] + pFutr[k + j] + 1) >> 1);            }    }} // C_DirectB_PredictOneMB_Cr////////////////////////////////////////////////////////////////////////////////// MCOneBiDirMBChroma////  Copy all 4 4x4 chroma blocks from reference source using the input motion//  vectors to locate and compute the reference pels using interpolation as//  required. The vectors are in subpel units. Results are stored in the output//  buffer in a 16x16 block, with a row pitch of DEST_PITCH.//////////////////////////////////////////////////////////////////////////////////#define TRUNCATE_LO(val, lim, tmp)      \    (tmp) = (lim);                      \    if ((tmp) < (val))                  \        (val) = (Ipp8s) (tmp);#define TRUNCATE_HI(val, lim, tmp)      \    (tmp) = (lim);                      \    if ((tmp) > (val))                  \        (val) = (Ipp8s) (tmp);bool  H264VideoEncoder::CDirectBOneMB_Interp_Cr(    const Ipp32u uMB,           // macroblock number    const Ipp32u uPitch,        // pitch of source data    const T_ECORE_MV *pMVL0,// Fwd motion vectors in subpel units    const T_ECORE_MV *pMVL1,// Bwd motion vectors in subpel units    Ipp8u* pDst,                // put the resulting block here with pitch of 16    Ipp8u* tempBuff,            // the pointer to the working buffer    bool   is_v_plane,    int    block_offset    )       // pointer to future frame buffer{    int posx, posy, lo, hi;    int w1, w0;    Ipp32s intMVx, intMVy;    const Ipp32u uMBx = m_pCurrentFrame->uMBxpos;    const Ipp32u uMBy = m_pCurrentFrame->uMBypos;    const Ipp32u uRefPitch = m_pCurrentFrame->uPitch;    Ipp32u uPredPitch = 16;    const Ipp32s uFrmWidth = uWidthInMBs << 4;    const Ipp32s uFrmHeight = uHeightInMBs << 4;    Ipp8u *const pInterpBuf1 = tempBuff;//m_pCurrentFrame->pTempBuff4DirectB;    Ipp8u *const pInterpBuf2 = pDst;//m_pCurrentFrame->pMBEncodeBuffer + 256;    T_EncodeMBOffsets* pMBOffset = &m_pCurrentFrame->pMBOffsets[uMB];    T_RefIdx *pRefIdxL0 = &m_pCurrentFrame->pRefIdxL0[pMBOffset->uFirstBlockIndex];    T_RefIdx *pRefIdxL1 = &m_pCurrentFrame->pRefIdxL1[pMBOffset->uFirstBlockIndex];    Ipp32u uInterpType = m_pCurrentFrame->use_implicit_weighted_bipred ? 2 : 1;    const Ipp8u* pRefBlk;    Ipp8u * pPrev = 0;    Ipp8u * pFutr = 0;    int offset = pMBOffset->uChromaOffset + m_pCurrentFrame->uv_line_shift;    H264EncoderFrame **pRefPicList1 = m_pCurrentFrame->GetRefPicList(0, LIST_1)->m_RefPicList;    H264EncoderFrame **pRefPicList0 = m_pCurrentFrame->GetRefPicList(0, LIST_0)->m_RefPicList;    posx = uMBx;    posy = uMBy;    int sb = 0;    if (block_offset != -1)        sb = block_offset;    for (; sb < 4; sb++)    {        int sb_row = sb & 2;        int sb_col = (sb & 1)*2;        int sb_pos = sb_row*uWidthIn4x4Blocks + sb_col;        int sb_offset = sb_row*32 + 2*sb_col;        T_RefIdx ref_idx_l0 = pRefIdxL0[sb_pos];        if (ref_idx_l0 != -1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -