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

📄 umc_h264_deblocking.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                            pFields = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->slice_id, 0)->m_Prediction;
                            iRefP = pRefPicList[index]->DeblockPicID(pRefPicList[index]->GetNumberByParity(pFields[index]));
                        }
                        else
                            iRefP = -1;
                    }
                    // frame coded image
                    else
                    {
                        H264EncoderFrame<PixType> **pRefPicList;
                        Ipp32s index;

                        // select reference index for previous block
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][nNeighbour].RefIdxs[nNeighbourBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->slice_id, 0)->m_RefPicList;
                            iRefP = pRefPicList[index]->DeblockPicID(0);
                        }
                        else
                            iRefP = -1;
                    }

                    VM_ASSERT((iRefP != -1) || (iRefQ != -1));

                    // when reference indexes are equal
                    if (iRefQ == iRefP)
                    {
                        H264MotionVector *pVectorP;

                        pVectorP = m_pCurrentFrame->m_mbinfo.MV[0][nNeighbour].MotionVectors + nNeighbourBlock;

                        // compare motion vectors
                        if ((4 <= abs(pVectorQ->mvx - pVectorP->mvx)) ||
                            (nVectorDiffLimit <= abs(pVectorQ->mvy - pVectorP->mvy)))
                        {
                            pStrength[idx] = 1;
                            *pDeblockingFlag = 1;
                        }
                        else
                            pStrength[idx] = 0;
                    }
                    // when reference indexes are different
                    else
                    {
                        pStrength[idx] = 1;
                        *pDeblockingFlag = 1;
                    }
                }
            }
        }
        // external edge required in strong filtering
        else
        {
            if ((HORIZONTAL_DEBLOCKING == dir) &&
                (pParams->MBFieldCoded))
                SetEdgeStrength(pStrength + 0, 3);
            else
                SetEdgeStrength(pStrength + 0, 4);
            *pDeblockingFlag = 1;
        }
    }

    //
    // internal edge(s)
    //
    {
        Ipp32u idx;

        // reset all strengths
        SetEdgeStrength(pStrength + 4, 0);
        SetEdgeStrength(pStrength + 8, 0);
        SetEdgeStrength(pStrength + 12, 0);

        // set deblocking flag
        if (cbp_luma & 0x1fffe)
            *pDeblockingFlag = 1;

        // cicle of edge(s)
        // we do all edges in one cicle
        for (idx = 4;idx < 16;idx += 1)
        {
            Ipp32u blkQ;

            blkQ = ENCODER_INTERNAL_BLOCKS_MASK[dir][idx - 4];

            if (cbp_luma & blkQ)
                pStrength[idx] = 2;
        }
    }

} // void H264CoreEncoder::PrepareDeblockingParametersPSlice16(Ipp32u dir, DeblockingParameters<PixType> *pParams)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::PrepareDeblockingParametersBSlice(DeblockingParameters<PixType> *pParams)
{
    Ipp32u MBAddr = pParams->nMBAddr;
    Ipp32u mbtype = (m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->mbtype;

    // when this macroblock is intra coded
    if (IS_INTRA_MBTYPE(mbtype))
    {
        PrepareDeblockingParametersISlice(pParams);
        return;
    }

    // try simplest function to prepare deblocking parameters
    switch (mbtype)
    {
        // when macroblock has type inter 16 on 16
    case MBTYPE_INTER:
    case MBTYPE_FORWARD:
    case MBTYPE_BACKWARD:
    case MBTYPE_BIDIR:
        PrepareDeblockingParametersBSlice16(VERTICAL_DEBLOCKING, pParams);
        PrepareDeblockingParametersBSlice16(HORIZONTAL_DEBLOCKING, pParams);
        break;

        // when macroblock has type inter 16 on 8
    case MBTYPE_INTER_16x8:
    case MBTYPE_FWD_FWD_16x8:
    case MBTYPE_BWD_BWD_16x8:
    case MBTYPE_FWD_BWD_16x8:
    case MBTYPE_BWD_FWD_16x8:
    case MBTYPE_BIDIR_FWD_16x8:
    case MBTYPE_BIDIR_BWD_16x8:
    case MBTYPE_FWD_BIDIR_16x8:
    case MBTYPE_BWD_BIDIR_16x8:
    case MBTYPE_BIDIR_BIDIR_16x8:
        PrepareDeblockingParametersBSlice8x16(VERTICAL_DEBLOCKING, pParams);
        PrepareDeblockingParametersBSlice16x8(HORIZONTAL_DEBLOCKING, pParams);
        return;

        // when macroblock has type inter 8 on 16
    case MBTYPE_INTER_8x16:
    case MBTYPE_FWD_FWD_8x16:
    case MBTYPE_BWD_BWD_8x16:
    case MBTYPE_FWD_BWD_8x16:
    case MBTYPE_BWD_FWD_8x16:
    case MBTYPE_BIDIR_FWD_8x16:
    case MBTYPE_BIDIR_BWD_8x16:
    case MBTYPE_FWD_BIDIR_8x16:
    case MBTYPE_BWD_BIDIR_8x16:
    case MBTYPE_BIDIR_BIDIR_8x16:
        PrepareDeblockingParametersBSlice16x8(VERTICAL_DEBLOCKING, pParams);
        PrepareDeblockingParametersBSlice8x16(HORIZONTAL_DEBLOCKING, pParams);
        return;

    default:
        PrepareDeblockingParametersBSlice4(VERTICAL_DEBLOCKING, pParams);
        PrepareDeblockingParametersBSlice4(HORIZONTAL_DEBLOCKING, pParams);
        break;
    }

} // void H264CoreEncoder::PrepareDeblockingParametersBSlice(DeblockingParameters<PixType> *pParams)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::PrepareDeblockingParametersBSlice4(Ipp32u dir, DeblockingParameters<PixType> *pParams)
{
    Ipp32u MBAddr = pParams->nMBAddr;
    Ipp32u cbp_luma = (m_mbinfo.mbs + MBAddr)->cbp_luma;
    Ipp8u *pStrength = pParams->Strength[dir];
    Ipp32u *pDeblockingFlag = &(pParams->DeblockingFlag[dir]);

    //
    // external edge
    //
    if (pParams->ExternalEdgeFlag[dir])
    {
        Ipp32u nNeighbour;

        // select neighbour addres
        nNeighbour = pParams->nNeighbour[dir];

        // when neighbour macroblock isn't intra
        if (!IS_INTRA_MBTYPE((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->mbtype))
        {
            H264MacroblockLocalInfo *pNeighbour;
            Ipp32u idx;

            // select neighbour
            pNeighbour = m_mbinfo.mbs + nNeighbour;

            // cicle on blocks
            for (idx = 0;idx < 4;idx += 1)
            {
                Ipp32u blkQ, blkP;

                blkQ = ENCODER_EXTERNAL_BLOCK_MASK[dir][CURRENT_BLOCK][idx];
                blkP = ENCODER_EXTERNAL_BLOCK_MASK[dir][NEIGHBOUR_BLOCK][idx];

                // when one of couple of blocks has coeffs
                if ((cbp_luma & blkQ) ||
                    (pNeighbour->cbp_luma & blkP))
                {
                    pStrength[idx] = 2;
                    *pDeblockingFlag = 1;
                }
                // compare motion vectors & reference indexes
                else
                {
                    Ipp32u nBlock, nNeighbourBlock;
                    Ipp32s iRefQFrw, iRefPFrw, iRefQBck, iRefPBck;
                    Ipp32s nVectorDiffLimit = pParams->nMaxMVector;

                    // calc block and neighbour block number
                    if (VERTICAL_DEBLOCKING == dir)
                    {
                        nBlock = idx * 4;
                        nNeighbourBlock = nBlock + 3;
                    }
                    else
                    {
                        nBlock = idx;
                        nNeighbourBlock = idx + 12;
                    }

                    // field coded image
                    if (FRM_STRUCTURE > m_pCurrentFrame->m_PictureStructureForDec)
                    {
                        H264EncoderFrame<PixType> **pRefPicList;
                        Ipp32s index;
                        Ipp8s *pFields;

                        // select reference index for current block
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][MBAddr].RefIdxs[nBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 0)->m_RefPicList;
                            // select reference fields number array
                            pFields = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 0)->m_Prediction;
                            iRefQFrw = pRefPicList[index]->DeblockPicID(pRefPicList[index]->GetNumberByParity(pFields[index]));
                        }
                        else
                            iRefQFrw = -1;
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[1][MBAddr].RefIdxs[nBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 1)->m_RefPicList;
                            // select reference fields number array
                            pFields = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 1)->m_Prediction;
                            iRefQBck = pRefPicList[index]->DeblockPicID(pRefPicList[index]->GetNumberByParity(pFields[index]));
                        }
                        else
                            iRefQBck = -1;

                        // select reference index for previous block
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][nNeighbour].RefIdxs[nNeighbourBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->slice_id, 0)->m_RefPicList;
                            // select reference fields number array
                            pFields = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->slice_id, 0)->m_Prediction;
                            iRefPFrw = pRefPicList[index]->DeblockPicID(pRefPicList[index]->GetNumberByParity(pFields[index]));
                        }
                        else
                            iRefPFrw = -1;
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[1][nNeighbour].RefIdxs[nNeighbourBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->slice_id, 1)->m_RefPicList;
                            // select reference fields number array
                            pFields = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->slice_id, 1)->m_Prediction;
                            iRefPBck = pRefPicList[index]->DeblockPicID(pRefPicList[index]->GetNumberByParity(pFields[index]));
                        }
                        else
                            iRefPBck = -1;
                    }
                    // frame coded image
                    else
                    {
                        H264EncoderFrame<PixType> **pRefPicList;
                        Ipp32s index;

                        // select reference index for current block
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][MBAddr].RefIdxs[nBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 0)->m_RefPicList;
                            iRefQFrw = pRefPicList[index]->DeblockPicID(0);
                        }
                        else
                            iRefQFrw = -1;
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[1][MBAddr].RefIdxs[nBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 1)->m_RefPicList;
                            iRefQBck = pRefPicList[index]->DeblockPicID(0);
                        }
                        else
                            iRefQBck = -1;

                        // select reference index for previous block
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][nNeighbour].RefIdxs[nNeighbourBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->slice_id, 0)->m_RefPicList;
                            iRefPFrw = pRefPicList[index]->DeblockPicID(0);
                        }
                        else
                            iRefPFrw = -1;
                        index = m_pCurrentFrame->m_mbinfo.RefIdxs[1][nNeighbour].RefIdxs[nNeighbourBlock];
                        if (0 <= index)
                        {
                            pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + nNeighbour)->slice_id, 1)->m_RefPicList;
                            iRefPBck = pRefPicList[index]->DeblockPicID(0);
                        }
                        else
                            iRefPBck = -1;
                    }

                    // when reference indexes are equal
                    if (((iRefQFrw == iRefPFrw) && (iRefQBck == iRefPBck)) ||
                        ((iRefQFrw == iRefPBck) && (iRefQBck == iRefPFrw)))
                    {
                        // set initial value of strength
                        pStrength[idx] = 0;

                        // when forward and backward reference pictures of previous block are different
                        if (iRefPFrw != iRefPBck)
                        {
                            const H264MotionVector *pVectorQFrw, *pVectorQBck;
                            const H264MotionVect

⌨️ 快捷键说明

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