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

📄 umc_h264_deblocking_mbaff.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    // set neighbour addreses
    pParams->nNeighbour[VERTICAL_DEBLOCKING] = MBAddr - 2;
    if (0 == nFieldMacroblockMode)
    {
        if ((MBAddr&1)==0)
        {
            if (pGetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr - m_WidthInMBs * 2))
                pParams->nNeighbour[HORIZONTAL_DEBLOCKING] = MBAddr - m_WidthInMBs * 2;
            else
                pParams->nNeighbour[HORIZONTAL_DEBLOCKING] = MBAddr - m_WidthInMBs * 2 + 1;
        }
        else
        {
            pParams->nNeighbour[HORIZONTAL_DEBLOCKING] = MBAddr - 1;
        }
    } else {
        if ((MBAddr&1)==0)
        {
            if (pGetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr - m_WidthInMBs * 2))
                pParams->nNeighbour[HORIZONTAL_DEBLOCKING] = MBAddr - m_WidthInMBs * 2;
            else
                pParams->nNeighbour[HORIZONTAL_DEBLOCKING] = MBAddr - m_WidthInMBs * 2 + 1;
        }
        else
        {
            if (pGetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr - m_WidthInMBs * 2))
                pParams->nNeighbour[HORIZONTAL_DEBLOCKING] = MBAddr - m_WidthInMBs * 2;
            else
                pParams->nNeighbour[HORIZONTAL_DEBLOCKING] = MBAddr - m_WidthInMBs * 2;
        }
    }

    // set deblocking flag(s)
    pParams->DeblockingFlag[VERTICAL_DEBLOCKING] = 0;
    pParams->DeblockingFlag[HORIZONTAL_DEBLOCKING] = 0;

    // save variables
    pParams->pY = pY;
    pParams->pU = pU;
    pParams->pV = pV;
    pParams->pitchPixels = pic_pitchPixels;
    pParams->nMBAddr = MBAddr;
    pParams->nMaxMVector = (nFieldMacroblockMode) ? (2) : (4);
    pParams->MBFieldCoded = nFieldMacroblockMode;

    // set slice's variables
    pParams->nAlphaC0Offset = pHeader->slice_alpha_c0_offset;
    pParams->nBetaOffset = pHeader->slice_beta_offset;

} // void H264CoreEncoder::ResetDeblockingVariablesMBAFF(DeblockingParametersMBAFF<PixType>*pParams)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockLumaVerticalMBAFF(DeblockingParametersMBAFF<PixType> *pParams)
{
    //
    // step 1. Perform complex deblocking on external edge
    //
    {
        Ipp32u MBAddr = pParams->nMBAddr;
        Ipp8u Clipping[16];
        Ipp8u Alpha[2];
        Ipp8u Beta[2];
        Ipp32s AlphaC0Offset = pParams->nAlphaC0Offset;
        Ipp32s BetaOffset = pParams->nBetaOffset;
        Ipp32s pmq_QP = m_mbinfo.mbs[MBAddr].QP;
        Ipp32s pmp_QP;
        Ipp8u *pClipTab;
        Ipp32s QP;
        Ipp32s index;
        Ipp8u *pStrength = pParams->StrengthComplex;
        Ipp32u i;

        // prepare variables
        for (i = 0;i < 2;i += 1)
        {
            // get upper neighbour block QP
            pmp_QP = m_mbinfo.mbs[pParams->nLeft[i]].QP;

            // luma variables
            QP = (pmp_QP + pmq_QP + 1) >> 1 ;

            // external edge variables
            index = IClip(0, 51, QP + BetaOffset);
            Beta[i] = getEncoderBethaTable<PixType>(index);

            index = IClip(0, 51, QP + AlphaC0Offset);
            Alpha[i] = getEncoderAlphaTable<PixType>(index);
            pClipTab = getEncoderClipTab<PixType>(index);

            // create clipping values
            Clipping[i * 4 + 0] = pClipTab[pStrength[i * 4 + 0]];
            Clipping[i * 4 + 1] = pClipTab[pStrength[i * 4 + 1]];
            Clipping[i * 4 + 2] = pClipTab[pStrength[i * 4 + 2]];
            Clipping[i * 4 + 3] = pClipTab[pStrength[i * 4 + 3]];
        }

        // perform deblocking
        if (0 == pGetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr))
        {
            ippiFilterDeblockingLuma_VerEdge_MBAFF_H264(pParams->pY,
                                                        pParams->pitchPixels * 2 * sizeof(PixType),
                                                        Alpha[0],
                                                        Beta[0],
                                                        Clipping,
                                                        pStrength,
                                                        m_PicParamSet.bit_depth_luma);
            ippiFilterDeblockingLuma_VerEdge_MBAFF_H264(pParams->pY + pParams->pitchPixels,
                                                        pParams->pitchPixels * 2 * sizeof(PixType),
                                                        Alpha[1],
                                                        Beta[1],
                                                        Clipping + 4,
                                                        pStrength + 4,
                                                        m_PicParamSet.bit_depth_luma);
        }
        else
        {
            ippiFilterDeblockingLuma_VerEdge_MBAFF_H264(pParams->pY,
                                                        pParams->pitchPixels*sizeof(PixType),
                                                        Alpha[0],
                                                        Beta[0],
                                                        Clipping,
                                                        pStrength,
                                                        m_PicParamSet.bit_depth_luma);
            ippiFilterDeblockingLuma_VerEdge_MBAFF_H264(pParams->pY + pParams->pitchPixels * 8,
                                                        pParams->pitchPixels*sizeof(PixType),
                                                        Alpha[1],
                                                        Beta[1],
                                                        Clipping + 4,
                                                        pStrength + 4,
                                                        m_PicParamSet.bit_depth_luma);
        }
    }

    //
    // step 2. Perform complex deblocking on internal edges
    //
    DeblockLuma(VERTICAL_DEBLOCKING, (DeblockingParameters<PixType>*)pParams);

} // void H264CoreEncoder::DeblockLumaVerticalMBAFF(DeblockingParametersMBAFF<PixType>*pParams)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockChromaVerticalMBAFF(DeblockingParametersMBAFF<PixType> *pParams)
{
    // do not deblocking of 4:0:0 format
    if (m_PicParamSet.chroma_format_idc)
    {
        //
        // step 1. Perform complex deblocking on external edge
        //
        {
            Ipp32u MBAddr = pParams->nMBAddr;
            Ipp8u Clipping[16];
            Ipp8u Alpha[2];
            Ipp8u Beta[2];
            Ipp32s AlphaC0Offset = pParams->nAlphaC0Offset;
            Ipp32s BetaOffset = pParams->nBetaOffset;
            Ipp32s pmq_QP = m_mbinfo.mbs[MBAddr].QP;
            Ipp32s pmp_QP;
            Ipp8u *pClipTab;
            Ipp32s QP;
            Ipp32s index;
            Ipp8u *pStrength = pParams->StrengthComplex;
            Ipp32u nPlane;

            for (nPlane = 0; nPlane < 2; nPlane += 1)
            {
                // prepare variables
                if ((0 == nPlane) ||
                    (m_PicParamSet.chroma_qp_index_offset !=
                     m_PicParamSet.second_chroma_qp_index_offset))
                {
                    Ipp32u i;
                    Ipp32s chroma_qp_offset = (0 == nPlane) ?
                                              (m_PicParamSet.chroma_qp_index_offset) :
                                              (m_PicParamSet.second_chroma_qp_index_offset);


                    for (i = 0; i < 2; i += 1)
                    {
                        // get upper neighbour block QP
                        pmp_QP = m_mbinfo.mbs[pParams->nLeft[i]].QP;

                        // external edge variables averaging???
                        QP = ENCODER_QP_SCALE_CR[IClip(0, 51, pmq_QP + chroma_qp_offset)];
                        //QP = ENCODER_QP_SCALE_CR[getChromaQP(pmp_QP, chroma_qp_offset, m_SeqParamSet.bit_depth_chroma)];

                        // external edge variables
                        index = IClip(0, 51, QP + BetaOffset);
                        Beta[i] = getEncoderBethaTable<PixType>(index);

                        index = IClip(0, 51, QP + AlphaC0Offset);
                        Alpha[i] = getEncoderAlphaTable<PixType>(index);
                        pClipTab = getEncoderClipTab<PixType>(index);

                        // create clipping values
                        Clipping[i * 4 + 0] = pClipTab[pStrength[i * 4 + 0]];
                        Clipping[i * 4 + 1] = pClipTab[pStrength[i * 4 + 1]];
                        Clipping[i * 4 + 2] = pClipTab[pStrength[i * 4 + 2]];
                        Clipping[i * 4 + 3] = pClipTab[pStrength[i * 4 + 3]];
                    }
                }

                // perform deblocking
                if (0 == pGetMBFieldDecodingFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr))
                {
                    ippiFilterDeblockingChroma_VerEdge_MBAFF_H264(((0 == nPlane) ? (pParams->pU) : (pParams->pV)),
                                                                  pParams->pitchPixels * 2 * sizeof(PixType),
                                                                  Alpha[0],
                                                                  Beta[0],
                                                                  Clipping,
                                                                  pStrength,
                                                                  m_SeqParamSet.bit_depth_chroma);
                    ippiFilterDeblockingChroma_VerEdge_MBAFF_H264(((0 == nPlane) ? (pParams->pU) : (pParams->pV)) + pParams->pitchPixels,
                                                                  pParams->pitchPixels * 2 * sizeof(PixType),
                                                                  Alpha[1],
                                                                  Beta[1],
                                                                  Clipping + 4,
                                                                  pStrength + 4,
                                                                  m_SeqParamSet.bit_depth_chroma);
                }
                else
                {
                    ippiFilterDeblockingChroma_VerEdge_MBAFF_H264(((0 == nPlane) ? (pParams->pU) : (pParams->pV)),
                                                                  pParams->pitchPixels*sizeof(PixType),
                                                                  Alpha[0],
                                                                  Beta[0],
                                                                  Clipping,
                                                                  pStrength,
                                                                  m_SeqParamSet.bit_depth_chroma);
                    ippiFilterDeblockingChroma_VerEdge_MBAFF_H264(((0 == nPlane) ? (pParams->pU) : (pParams->pV)) + pParams->pitchPixels * 4,
                                                                  pParams->pitchPixels*sizeof(PixType),
                                                                  Alpha[1],
                                                                  Beta[1],
                                                                  Clipping + 4,
                                                                  pStrength + 4,
                                                                  m_SeqParamSet.bit_depth_chroma);
                }
            }
        }

        //
        // step 2. Perform complex deblocking on internal edges
        //
        DeblockChroma(VERTICAL_DEBLOCKING, pParams);
    }

} // void H264CoreEncoder::DeblockChromaVerticalMBAFF(DeblockingParametersMBAFF<PixType>*pParams)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockLumaHorizontalMBAFF(DeblockingParametersMBAFF<PixType> *pParams)
{
    Ipp8u bTmp[16];
    Ipp32s pitchPixels = pParams->pitchPixels;

    //
    // luma deblocking
    //

    //
    // step 1. Deblock origin external edge
    //
    {
        // save internal edges strength
        CopyEdgeStrength(bTmp + 0, pParams->Strength[HORIZONTAL_DEBLOCKING] + 0);
        CopyEdgeStrength(bTmp + 4, pParams->Strength[HORIZONTAL_DEBLOCKING] + 4);
        CopyEdgeStrength(bTmp + 8, pParams->Strength[HORIZONTAL_DEBLOCKING] + 8);
        CopyEdgeStrength(bTmp + 12, pParams->Strength[HORIZONTAL_DEBLOCKING] + 12);
        // skip all internal edges
        SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 4, 0);
        SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 8, 0);
        SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 12, 0);
        // set pitch
        pParams->pitchPixels *= 2;
        // perform deblocking
        DeblockLuma(HORIZONTAL_DEBLOCKING, (DeblockingParameters<PixType>*)pParams);
    }

    //
    // step 2. Deblock extra external edge
    //
    {
        // set extra edge strength
        CopyEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING], pParams->StrengthExtra);
        // correct neighbour MB info
        pParams->nNeighbour[HORIZONTAL_DEBLOCKING] += ((pParams->nMBAddr) & 1) ? 2*m_WidthInMBs - 1: 1;
        // correct Y pointer
        pParams->pY += pitchPixels;
        // perform deblocking
        DeblockLuma(HORIZONTAL_DEBLOCKING, (DeblockingParameters<PixType>*)pParams);
        // restore values
        pParams->nNeighbour[HORIZONTAL_DEBLOCKING] -= ((pParams->nMBAddr) & 1) ? 2*m_WidthInMBs - 1: 1;
        pParams->pY -= pitchPixels;
        pParams->pitchPixels = pitchPixels;
    }

    //
    // step 3. Deblock internal edges
    //
    {
        pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING] = 0;
        // set internal edge strength
        SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 0, 0);
        CopyEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 4, bTmp + 4);
        CopyEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 8, bTmp + 8);
        CopyEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 12, bTmp + 12);
        // perform deblocking
        DeblockLuma(HORIZONTAL_DEBLOCKING, (DeblockingParameters<PixType>*)pParams);
        // restore strength
        pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING] = 1;
        CopyEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 0, bTmp + 0);
    }

⌨️ 快捷键说明

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