📄 umc_h264_mc.cpp
字号:
// interpolate copy the first 4x4 block ippiInterpolateLuma_H264_8u_C1R(pMCRef, uPitch,pDst, 16, iXType, iYType, size4x4); // 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 + 4 + SubpelMVAdjust(pMCMV, uPitch, iXType, iYType); pMCDst = pDst + 4; // interpolate copy the second 4x4 block ippiInterpolateLuma_H264_8u_C1R(pMCRef, uPitch,pMCDst, 16, iXType, iYType, size4x4); // 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*4 + SubpelMVAdjust(pMCMV, uPitch, iXType, iYType); pMCDst = pDst + DEST_PITCH*4; // interpolate copy the third 4x4 block ippiInterpolateLuma_H264_8u_C1R(pMCRef, uPitch,pMCDst, 16, iXType, iYType, size4x4); // 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*4 + 4 + SubpelMVAdjust(pMCMV, uPitch, iXType, iYType); pMCDst = pDst + DEST_PITCH*4 + 4; // interpolate copy the fourth 4x4 block ippiInterpolateLuma_H264_8u_C1R(pMCRef, uPitch,pMCDst, 16, iXType, iYType, size4x4); break; case SBTYPE_BACKWARD_4x4: // convert 1/4 pel vector to pel vector and interpolation type pMCRef = futr_frame + SubpelMVAdjust(pMVBwd, uPitch, iXType, iYType); // interpolate copy the first 4x4 block ippiInterpolateLuma_H264_8u_C1R(pMCRef, uPitch,pDst, 16, iXType, iYType, size4x4); // 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 + 4 + SubpelMVAdjust(pMCMV, uPitch, iXType, iYType); pMCDst = pDst + 4; // interpolate copy the second 4x4 block ippiInterpolateLuma_H264_8u_C1R(pMCRef, uPitch,pMCDst, 16, iXType, iYType, size4x4); // 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*4 + SubpelMVAdjust(pMCMV, uPitch, iXType, iYType); pMCDst = pDst + DEST_PITCH*4; // interpolate copy the third 4x4 block ippiInterpolateLuma_H264_8u_C1R(pMCRef, uPitch,pMCDst, 16, iXType, iYType, size4x4); // 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*4 + 4 + SubpelMVAdjust(pMCMV, uPitch, iXType, iYType); pMCDst = pDst + DEST_PITCH*4 + 4; // interpolate copy the fourth 4x4 block ippiInterpolateLuma_H264_8u_C1R(pMCRef, uPitch,pMCDst, 16, iXType, iYType, size4x4); break; case SBTYPE_BIDIR_8x8: case SBTYPE_BIDIR_8x4: case SBTYPE_BIDIR_4x8: case SBTYPE_BIDIR_4x4: { // Copy the stored 8x8 prediction data from the BiPred Mode Buffer Ipp32u uRow; Ipp8u* pBiPred = m_pCurrentFrame->pPred4BiPred + (uBlock&1)*8 + (uBlock&2)*16*4; pMCDst = pDst; for (uRow=0; uRow<8; uRow++) { memcpy(pMCDst, pBiPred, 8); pMCDst += DEST_PITCH; pBiPred += 16; } } break; case SBTYPE_DIRECT: { // Copy the stored 8x8 prediction data from the Direct Mode Buffer Ipp32u uRow; Ipp8u* pDirect = m_pCurrentFrame->pPred4DirectB + (uBlock&1)*8 + (uBlock&2)*16*4; pMCDst = pDst; for (uRow=0; uRow<8; uRow++) { memcpy(pMCDst, pDirect, 8); pMCDst += DEST_PITCH; pDirect += 16; } } break; default: break; } // advance MV pointers and source ptrs to next 8x8 block if (1 == uBlock) { // next block is lower left ref_off += uWidthIn4x4Blocks*2 - 2; uOffset += uPitch*8 - 8; pMVFwd += uWidthIn4x4Blocks*2 - 2; pMVBwd += uWidthIn4x4Blocks*2 - 2; pDst += DEST_PITCH*8 - 8; } else { // next block is to the right (except when uBlock==3, then // don't care ref_off += 2; uOffset += 8; pMVFwd += 2; pMVBwd += 2; pDst += 8; } } // for uBlock } break; default: // not supposed to be here break; } // switch} // MCOneMBLumainline Ipp8u * get_chroma_ptr(H264EncoderFrame * frame, bool is_v_plane){ return !frame ? 0 : (is_v_plane ? frame->m_pVPlane : frame->m_pUPlane);}////////////////////////////////////////////////////////////////////////////////// MCOneMBChroma//// 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.//////////////////////////////////////////////////////////////////////////////////void H264VideoEncoder::MCOneMBChroma( const Ipp32u uMB, // macroblock number Ipp32u uPitch, // pitch of source data const T_ECORE_MV *pMVFwd, // motion vectors in subpel units const T_ECORE_MV *pMVBwd, // motion vectors in subpel units Ipp8u* pDst, // put the resulting block here T_EncodeMBData *pMBData, // MB Data structure bool is_v_plane){ Ipp32u uBlock; Ipp32s iXType; Ipp32s iYType; MB_Type uMBType = pMBData->uMBType; // type of MB const Ipp8u *pMCRef; Ipp8u *pMCDst; const T_ECORE_MV *pMCMV; Ipp32s uMVOffset = m_pCurrentFrame->pMBOffsets[uMB].uFirstBlockIndex; T_RefIdx *pRefIdxL0 = &m_pCurrentFrame->pRefIdxL0[uMVOffset]; T_RefIdx *pRefIdxL1 = &m_pCurrentFrame->pRefIdxL1[uMVOffset]; H264EncoderFrame **pRefPicList0 = m_pCurrentFrame->GetRefPicList(0, LIST_0)->m_RefPicList; H264EncoderFrame **pRefPicList1 = m_pCurrentFrame->GetRefPicList(0, LIST_1)->m_RefPicList; Ipp32u uOffset = m_pCurrentFrame->pMBOffsets[uMB].uChromaOffset + m_pCurrentFrame->uv_line_shift; T_RefIdx block_ref = 0; Ipp8u * prev_frame = 0; Ipp8u * futr_frame = 0; // Detect if there are any 8x8 Direct Mode or BiPred Subblocks if ((uMBType == MBTYPE_B_8x8) && ((pMBData->SBType[0] == SBTYPE_DIRECT) || (pMBData->SBType[1] == SBTYPE_DIRECT) || (pMBData->SBType[2] == SBTYPE_DIRECT) || (pMBData->SBType[3] == SBTYPE_DIRECT) || (pMBData->SBType[0] == SBTYPE_BIDIR_8x8) || (pMBData->SBType[1] == SBTYPE_BIDIR_8x8) || (pMBData->SBType[2] == SBTYPE_BIDIR_8x8) || (pMBData->SBType[3] == SBTYPE_BIDIR_8x8) || (pMBData->SBType[0] == SBTYPE_BIDIR_8x4) || (pMBData->SBType[1] == SBTYPE_BIDIR_8x4) || (pMBData->SBType[2] == SBTYPE_BIDIR_8x4) || (pMBData->SBType[3] == SBTYPE_BIDIR_8x4) || (pMBData->SBType[0] == SBTYPE_BIDIR_4x8) || (pMBData->SBType[1] == SBTYPE_BIDIR_4x8) || (pMBData->SBType[2] == SBTYPE_BIDIR_4x8) || (pMBData->SBType[3] == SBTYPE_BIDIR_4x8) || (pMBData->SBType[0] == SBTYPE_BIDIR_4x4) || (pMBData->SBType[1] == SBTYPE_BIDIR_4x4) || (pMBData->SBType[2] == SBTYPE_BIDIR_4x4) || (pMBData->SBType[3] == SBTYPE_BIDIR_4x4) )) { // If so, then do a direct mode chroma MC first... // Direct mode & BiPred 8x8s will not be copied over below. // Motion Compensate one chroma MB MCOneBiDirMBChroma( uMB, uPitch, pMVFwd, pMVBwd, pDst, m_pCurrentFrame->pTempBuff4DirectB, is_v_plane ); } switch (uMBType) { case MBTYPE_DIRECT: case MBTYPE_BIDIR: case MBTYPE_BIDIR_BIDIR_16x8: case MBTYPE_BIDIR_BIDIR_8x16: MCOneBiDirMBChroma( uMB, uPitch, pMVFwd, pMVBwd, pDst, m_pCurrentFrame->pTempBuff4DirectB, is_v_plane ); break; case MBTYPE_INTER: case MBTYPE_FORWARD: // 1 vector for the MB // convert 1/4 pel Luma vector to pel vector and 1/8 pel interpolation type block_ref = pRefIdxL0[0]; prev_frame = get_chroma_ptr(pRefPicList0[block_ref], is_v_plane) + uOffset; prev_frame += SubpelChromaMVAdjust(pMVFwd, uPitch, iXType, iYType); if (0==iXType && 0==iYType) { // no interpolation, just copy from reference // copy the 4 chroma blocks (8 rows of 8 pels). Ipp32u uRow; for (uRow=0; uRow<8; uRow++) { memcpy(pDst, prev_frame, 8); pDst += 16; prev_frame += uPitch; } } else { // interpolate copy the 4x4 block ippiInterpolateChroma_H264_8u_C1R (prev_frame, uPitch, pDst, DEST_PITCH, iXType, iYType, size8x8); } break; case MBTYPE_BACKWARD: // 1 vector for the MB // convert 1/4 pel Luma vector to pel vector and 1/8 pel interpolation type block_ref = pRefIdxL1[0]; futr_frame = get_chroma_ptr(pRefPicList1[block_ref], is_v_plane) + uOffset; futr_frame += SubpelChromaMVAdjust(pMVBwd, uPitch, iXType, iYType); if (0==iXType && 0==iYType) { // no interpolation, just copy from reference // copy the 4 chroma blocks (8 rows of 8 pels). Ipp32u uRow; for (uRow=0; uRow<8; uRow++) { memcpy(pDst, futr_frame, 8); pDst += 16; futr_frame += uPitch; } } else { // interpolate copy the 4x4 block ippiInterpolateChroma_H264_8u_C1R (futr_frame, uPitch, pDst, DEST_PITCH, iXType, iYType, size8x8); } break; case MBTYPE_INTER_16x8: case MBTYPE_FWD_FWD_16x8: // 2 vectors for the MB (2 - 8x4 chroma blocks) block_ref = pRefIdxL0[0]; prev_frame = get_chroma_ptr(pRefPicList0[block_ref], is_v_plane) + uOffset; pMCRef = prev_frame + SubpelChromaMVAdjust(pMVFwd, uPitch, iXType, iYType); // interpolate copy the 8x4 block ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size8x4); // Do other 8x4 block pMVFwd += uWidthIn4x4Blocks * 2; // Reposition MV pointer to next 16x8 pDst += DEST_PITCH*4; block_ref = pRefIdxL0[uWidthIn4x4Blocks * 2]; prev_frame = get_chroma_ptr(pRefPicList0[block_ref], is_v_plane) + uOffset + uPitch*4; pMCRef = prev_frame + SubpelChromaMVAdjust(pMVFwd, uPitch, iXType, iYType); // interpolate copy the 8x4 block ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size8x4); break; case MBTYPE_FWD_BWD_16x8: // 2 vectors for the MB (2 - 8x4 chroma blocks) block_ref = pRefIdxL0[0]; prev_frame = get_chroma_ptr(pRefPicList0[block_ref], is_v_plane) + uOffset; pMCRef = prev_frame + SubpelChromaMVAdjust(pMVFwd, uPitch, iXType, iYType); // interpolate copy the 8x4 block ippiInterpolateChroma_H264_8u_C1R (pMCRef, uPitch, pDst, DEST_PITCH, iXType, iYType, size8x4); // Do other 8x4 block pMVBwd += uWidthIn4x4Blocks * 2; // Reposition MV pointer to next 16x8 pDst += DEST_PITCH*4; block_ref = pRefIdxL1[uWidthIn4x4Blocks * 2]; futr_frame = get_chroma_ptr(pRefPicList1[block_ref], is_v_plane) + uOffset + uPitch*4; pMCRef = futr_frame + SubpelChromaMVAdjust(pMVBwd, uPitch, iXType, iYType); // interpolate copy the 8x4 block
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -