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

📄 umc_h264_deblocking.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#endif // defined(_IPP_STDCALL_CDECL)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockFrame(H264EncoderThreadPrivateSlice<PixType, CoeffsType> *curr_slice,
                                                       Ipp32u uFirstMB, Ipp32u uNumMB)
{
    // update slice info
    UpdateLimitedSliceInfo(curr_slice);

   // perform deblocking process on every macroblock
   for (Ipp32u i = uFirstMB; i < uFirstMB+uNumMB; i++) DeblockMacroblockMSlice(i);
} // void H264CoreEncoder::DeblockFrame(Ipp32u uFirstMB, Ipp32u uNumMB)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockSlice(H264EncoderThreadPrivateSlice<PixType, CoeffsType> *curr_slice,
                                                       Ipp32u uFirstMB, Ipp32u unumMBs, bool bLast)
{
    DeblockingFunction pDeblocking = NULL;

    // no filtering edges of this slice
    if (DEBLOCK_FILTER_OFF == curr_slice->m_disable_deblocking_filter_idc)
        return;

    // update slice info
    UpdateLimitedSliceInfo(curr_slice);

    // MBAFF case
    if (m_SliceHeader.MbaffFrameFlag)
    {
        // select optimized deblocking function
        switch (curr_slice->m_slice_type)
        {
        case INTRASLICE:
            pDeblocking = &H264CoreEncoder::DeblockMacroblockISliceMBAFF;
            break;

        case PREDSLICE:
            pDeblocking = &H264CoreEncoder::DeblockMacroblockPSliceMBAFF;
            break;

        case BPREDSLICE:
            pDeblocking = &H264CoreEncoder::DeblockMacroblockBSliceMBAFF;
            break;

        default:
            pDeblocking = NULL;
            break;
        }
    }
    // non-MBAFF case
    else
    {
        // select optimized deblocking function
        switch (curr_slice->m_slice_type)
        {
        case INTRASLICE:
            pDeblocking = &H264CoreEncoder::DeblockMacroblockISlice;
            break;

        case PREDSLICE:
            pDeblocking = &H264CoreEncoder::DeblockMacroblockPSlice;
            break;

        case BPREDSLICE:
            pDeblocking = &H264CoreEncoder::DeblockMacroblockBSlice;
            break;

        default:
            pDeblocking = NULL;
            break;
        }
    }

    if (NULL == pDeblocking)
        return;

   // perform deblocking process on every macroblock
   Ipp32u i;
   for (i = uFirstMB; i < uFirstMB + unumMBs; i++) (this->*(pDeblocking))(i);

} // void H264CoreEncoder::DeblockSlice(H264EncoderThreadPrivateSlice<PixType, CoeffsType> *curr_slice, Ipp32u uFirstMB, Ipp32u unumMBs)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockMacroblockMSlice(Ipp32u MBAddr)
{
    H264LimitedSliceHeader *pHeader = m_pLimitedSliceInfo + m_pCurrentFrame->m_mbinfo.mbs[MBAddr].slice_id;

    // when deblocking isn't required
    if (DEBLOCK_FILTER_OFF == pHeader->disable_deblocking_filter_idc)
        return;

    // select optimized deblocking function
    switch (pHeader->slice_type)
    {
    case INTRASLICE:
        DeblockMacroblockISlice(MBAddr);
        break;

    case PREDSLICE:
        DeblockMacroblockPSlice(MBAddr);
        break;

    case BPREDSLICE:
        DeblockMacroblockBSlice(MBAddr);
        break;

    default:
        // illegal case. it should never hapen.
        break;
    }

} // void H264CoreEncoder::DeblockMacroblockMSlice(Ipp32u MBAddr)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockMacroblockISlice(Ipp32u MBAddr)
{
    __align(16)
    DeblockingParameters<PixType> params;

    // prepare deblocking parameters
    params.nMBAddr = MBAddr;
    ResetDeblockingVariables(&params);
    PrepareDeblockingParametersISlice(&params);

    // perform deblocking
    //!!!Chroma must be called first because luma clears strength for 8x8 transform.
    DeblockChroma(VERTICAL_DEBLOCKING, &params);
    DeblockChroma(HORIZONTAL_DEBLOCKING, &params);
    DeblockLuma(VERTICAL_DEBLOCKING, &params);
    DeblockLuma(HORIZONTAL_DEBLOCKING, &params);

} // void H264CoreEncoder::DeblockMacroblockISlice(Ipp32u MBAddr)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockMacroblockPSlice(Ipp32u MBAddr)
{
    __align(16)
    DeblockingParameters<PixType> params;

    // prepare deblocking parameters
    params.nMBAddr = MBAddr;
    ResetDeblockingVariables(&params);
    PrepareDeblockingParametersPSlice(&params);

    // perform deblocking
    //!!!Chroma must be called first because luma clears strength for 8x8 transform.
    DeblockChroma(VERTICAL_DEBLOCKING, &params);
    DeblockChroma(HORIZONTAL_DEBLOCKING, &params);
    DeblockLuma(VERTICAL_DEBLOCKING, &params);
    DeblockLuma(HORIZONTAL_DEBLOCKING, &params);

} // void H264CoreEncoder::DeblockMacroblockPSlice(Ipp32u MBAddr)

template <class PixType, class CoeffsType> void H264CoreEncoder<PixType,CoeffsType>::DeblockMacroblockBSlice(Ipp32u MBAddr)
{
    __align(16)
    DeblockingParameters<PixType> params;

    // prepare deblocking parameters
    params.nMBAddr = MBAddr;
    ResetDeblockingVariables(&params);
    PrepareDeblockingParametersBSlice(&params);

    // perform deblocking
    //!!!Chroma must be called first because luma clears strength for 8x8 transform.
    DeblockChroma(VERTICAL_DEBLOCKING, &params);
    DeblockChroma(HORIZONTAL_DEBLOCKING, &params);
    DeblockLuma(VERTICAL_DEBLOCKING, &params);
    DeblockLuma(HORIZONTAL_DEBLOCKING, &params);

} // void H264CoreEncoder::DeblockMacroblockBSlice(Ipp32u MBAddr)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockLuma(Ipp32u dir, DeblockingParameters<PixType> *pParams)
{
    PixType *pY = pParams->pY;
    Ipp32s pic_pitchPixels = pParams->pitchPixels;
    Ipp32s 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;

    //
    // luma deblocking
    //

    if (pParams->DeblockingFlag[dir])
    {
        Ipp8u *pClipTab;
        Ipp32s QP;
        Ipp32s index;
        Ipp8u *pStrength = pParams->Strength[dir];

        //
        // correct strengths for high profile
        //
        if (pGetMB8x8TSFlag(m_pCurrentFrame->m_mbinfo.mbs + MBAddr))
        {
            SetEdgeStrength(pStrength + 4, 0); // 16 bits????
            SetEdgeStrength(pStrength + 12, 0);
        }

        if (pParams->ExternalEdgeFlag[dir])
        {
            Ipp32s pmp_QP;

            // get neighbour block QP
            pmp_QP = m_mbinfo.mbs[pParams->nNeighbour[dir]].QP;

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

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

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

            // create clipping values
            Clipping[0] = pClipTab[pStrength[0]];
            Clipping[1] = pClipTab[pStrength[1]];
            Clipping[2] = pClipTab[pStrength[2]];
            Clipping[3] = pClipTab[pStrength[3]];

        }

        // internal edge variables
        QP = pmq_QP;

        index = IClip(0, 51, QP + BetaOffset);
        Beta[1] = getEncoderBethaTable<PixType>(index);

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

        // create clipping values
        {
            Ipp32u edge;

            for (edge = 1;edge < 4;edge += 1)
            {
                if (*((Ipp32u *) (pStrength + edge * 4)))
                {
                    // create clipping values
                    Clipping[edge * 4 + 0] = pClipTab[pStrength[edge * 4 + 0]];
                    Clipping[edge * 4 + 1] = pClipTab[pStrength[edge * 4 + 1]];
                    Clipping[edge * 4 + 2] = pClipTab[pStrength[edge * 4 + 2]];
                    Clipping[edge * 4 + 3] = pClipTab[pStrength[edge * 4 + 3]];
                }
            }
        }

        // perform deblocking
        encoderIppLumaDeblocking(dir, pY,
                                 pic_pitchPixels,
                                 Alpha,
                                 Beta,
                                 Clipping,
                                 pStrength,
                                 m_PicParamSet.bit_depth_luma);
    }

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

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::DeblockChroma(Ipp32u dir, DeblockingParameters<PixType> *pParams)
{
    // do no deblocking of 4:0:0 format
    if (m_PicParamSet.chroma_format_idc)
    {
        PixType *pU = pParams->pU;
        PixType *pV = pParams->pV;
        Ipp32s pic_pitchPixels = pParams->pitchPixels;
        Ipp32s 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;

        //
        // chroma deblocking
        //

        if (pParams->DeblockingFlag[dir])

        {
            Ipp8u *pClipTab;
            Ipp32s QP;
            Ipp32s index;
            Ipp8u *pStrength = pParams->Strength[dir];
            Ipp32s nPlane;

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

                    if (pParams->ExternalEdgeFlag[dir])
                    {
                        Ipp32s pmp_QP;

                        // get left block QP
                        pmp_QP = m_mbinfo.mbs[pParams->nNeighbour[dir]].QP;

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

                        index = IClip(0, 51, QP + BetaOffset);
                        Beta[0] = getEncoderBethaTable<PixType>(index);

⌨️ 快捷键说明

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