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

📄 umc_h264_deblocking.cpp

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

                        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 = ENCODER_QP_SCALE_CR[IClip(0, 51, pmq_QP + chroma_qp_offset)];
                    //QP = ENCODER_QP_SCALE_CR[getChromaQP(pmq_QP, chroma_qp_offset, m_SeqParamSet.bit_depth_chroma)];

                    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
                    if (m_PicParamSet.chroma_format_idc == 2 && HORIZONTAL_DEBLOCKING == dir)
                    {
                        // create clipping values

                        Clipping[4] = (Ipp8u) (pClipTab[pStrength[4]]);
                        Clipping[5] = (Ipp8u) (pClipTab[pStrength[5]]);
                        Clipping[6] = (Ipp8u) (pClipTab[pStrength[6]]);
                        Clipping[7] = (Ipp8u) (pClipTab[pStrength[7]]);
                        Clipping[8] = (Ipp8u) (pClipTab[pStrength[8]]);
                        Clipping[9] = (Ipp8u) (pClipTab[pStrength[9]]);
                        Clipping[10] = (Ipp8u) (pClipTab[pStrength[10]]);
                        Clipping[11] = (Ipp8u) (pClipTab[pStrength[11]]);
                        Clipping[12] = (Ipp8u) (pClipTab[pStrength[12]]);
                        Clipping[13] = (Ipp8u) (pClipTab[pStrength[13]]);
                        Clipping[14] = (Ipp8u) (pClipTab[pStrength[14]]);
                        Clipping[15] = (Ipp8u) (pClipTab[pStrength[15]]);
                    }
                    else
                    {
                        // create clipping values
                        Clipping[4] = (Ipp8u) (pClipTab[pStrength[8]]);
                        Clipping[5] = (Ipp8u) (pClipTab[pStrength[9]]);
                        Clipping[6] = (Ipp8u) (pClipTab[pStrength[10]]);
                        Clipping[7] = (Ipp8u) (pClipTab[pStrength[11]]);
                    }
                }

                // perform deblocking chroma component
                encoderIppChromaDeblocking(dir + (m_PicParamSet.chroma_format_idc&0x2),(0 == nPlane) ? (pU) : (pV),
                                           pic_pitchPixels,
                                           Alpha,
                                           Beta,
                                           Clipping,
                                           pStrength,
                                           m_SeqParamSet.bit_depth_chroma);
            }
        }
    }
} // void H264CoreEncoder::DeblockChroma(Ipp32u dir, DeblockingParameters<PixType> *pParams)

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::ResetDeblockingVariables(DeblockingParameters<PixType> *pParams)
{
    PixType *pY, *pU, *pV;
    Ipp32u offset;
    Ipp32s MBYAdjust = 0;
    Ipp32u mbXOffset, mbYOffset;
    Ipp32s pic_pitchPixels = m_pCurrentFrame->pitchPixels();
    Ipp32u MBAddr = pParams->nMBAddr;
    Ipp32u nCurrMB_X, nCurrMB_Y;
    H264LimitedSliceHeader *pHeader = m_pLimitedSliceInfo + m_pCurrentFrame->m_mbinfo.mbs[MBAddr].slice_id;

    // load planes
    pY = m_pReconstructFrame->m_pYPlane;
    pU = m_pReconstructFrame->m_pUPlane;
    pV = m_pReconstructFrame->m_pVPlane;
    if (FRM_STRUCTURE > m_pCurrentFrame->m_PictureStructureForDec)
    {
        if(m_pCurrentFrame->m_bottom_field_flag[m_field_index])
        {
            pY += pic_pitchPixels;
            pU += pic_pitchPixels;
            pV += pic_pitchPixels;
        }
        if (m_field_index)
            MBYAdjust = m_HeightInMBs;
        pic_pitchPixels *= 2;
    }

    // prepare macroblock variables
    nCurrMB_X = (MBAddr % m_WidthInMBs);
    nCurrMB_Y = (MBAddr / m_WidthInMBs)- MBYAdjust;
    Ipp32s chromaShiftX;
    Ipp32s chromaShiftY;
    switch(m_PicParamSet.chroma_format_idc) {
        case 0: //MONOCHROME
            chromaShiftX = chromaShiftY = 0;
            break;
        case 2: //422
            chromaShiftX = 3;
            chromaShiftY = 4;
            break;
        case 3: //444
            chromaShiftX = chromaShiftY = 4;
            break;
        case 1: //420
        default:
            chromaShiftX = chromaShiftY = 3;
    }
    mbXOffset = nCurrMB_X * 16;
    mbYOffset = nCurrMB_Y * 16;

    Ipp32s chromaXOffset = nCurrMB_X<<chromaShiftX;
    Ipp32s chromaYOffset = nCurrMB_Y<<chromaShiftY;
    // calc plane's offsets
    offset = mbXOffset + (mbYOffset * pic_pitchPixels);
    pY += offset;
    pU += chromaXOffset + chromaYOffset * pic_pitchPixels;
    pV += chromaXOffset + chromaYOffset * pic_pitchPixels;

    // set external edge variables
    pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING] = (nCurrMB_X != 0);
    pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING] = (nCurrMB_Y != 0);

    if (DEBLOCK_FILTER_ON_NO_SLICE_EDGES == pHeader->disable_deblocking_filter_idc)
    {
        // don't filter at slice boundaries
        if (nCurrMB_X)
        {
            if (m_pCurrentFrame->m_mbinfo.mbs[MBAddr].slice_id !=
                m_pCurrentFrame->m_mbinfo.mbs[MBAddr - 1].slice_id)
                pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING] = 0;
        }

        if (nCurrMB_Y)
        {
            if (m_pCurrentFrame->m_mbinfo.mbs[MBAddr].slice_id !=
                m_pCurrentFrame->m_mbinfo.mbs[MBAddr - m_WidthInMBs].slice_id)
                pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING] = 0;
        }
    }

    // reset external edges strength
    SetEdgeStrength(pParams->Strength[VERTICAL_DEBLOCKING], 0);
    SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING], 0);

    // set neighbour addreses
    pParams->nNeighbour[VERTICAL_DEBLOCKING] = MBAddr - 1;
    pParams->nNeighbour[HORIZONTAL_DEBLOCKING] = MBAddr - m_WidthInMBs;

    // 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->nMaxMVector = (FRM_STRUCTURE > m_pCurrentFrame->m_PictureStructureForDec) ? (2) : (4);
    pParams->MBFieldCoded = (FRM_STRUCTURE > m_pCurrentFrame->m_PictureStructureForDec);

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

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

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::PrepareDeblockingParametersISlice(DeblockingParameters<PixType> *pParams)
{
    // set deblocking flag(s)
    pParams->DeblockingFlag[VERTICAL_DEBLOCKING] = 1;
    pParams->DeblockingFlag[HORIZONTAL_DEBLOCKING] = 1;

    // calculate strengths
    if (pParams->ExternalEdgeFlag[VERTICAL_DEBLOCKING])
    {
        // deblocking with strong deblocking of external edge
        SetEdgeStrength(pParams->Strength[VERTICAL_DEBLOCKING] + 0, 4);
    }

    SetEdgeStrength(pParams->Strength[VERTICAL_DEBLOCKING] + 4, 3);
    SetEdgeStrength(pParams->Strength[VERTICAL_DEBLOCKING] + 8, 3);
    SetEdgeStrength(pParams->Strength[VERTICAL_DEBLOCKING] + 12, 3);

    if (pParams->ExternalEdgeFlag[HORIZONTAL_DEBLOCKING])
    {
        if (pParams->MBFieldCoded)
        {
            // deblocking field macroblock with external edge
            SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 0, 3);
        }
        else
        {
            // deblocking with strong deblocking of external edge
            SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 0, 4);
        }
    }

    SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 4, 3);
    SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 8, 3);
    SetEdgeStrength(pParams->Strength[HORIZONTAL_DEBLOCKING] + 12, 3);

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

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::PrepareDeblockingParametersPSlice(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:
        PrepareDeblockingParametersPSlice16(VERTICAL_DEBLOCKING, pParams);
        PrepareDeblockingParametersPSlice16(HORIZONTAL_DEBLOCKING, pParams);
        break;
/*
        // when macroblock has type inter 16 on 8
    case MBTYPE_INTER_16x8:
        PrepareDeblockingParametersPSlice8x16(VERTICAL_DEBLOCKING, pParams);
        PrepareDeblockingParametersPSlice16x8(HORIZONTAL_DEBLOCKING, pParams);
        return;

        // when macroblock has type inter 8 on 16
    case MBTYPE_INTER_8x16:
        PrepareDeblockingParametersPSlice16x8(VERTICAL_DEBLOCKING, pParams);
        PrepareDeblockingParametersPSlice8x16(HORIZONTAL_DEBLOCKING, pParams);
        return;
*/
    default:
        PrepareDeblockingParametersPSlice4(VERTICAL_DEBLOCKING, pParams);
        PrepareDeblockingParametersPSlice4(HORIZONTAL_DEBLOCKING, pParams);
        break;
    }

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

template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::PrepareDeblockingParametersPSlice4(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 iRefQ, iRefP;
                    Ipp32s nVectorDiffLimit = pParams->nMaxMVector;

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

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

⌨️ 快捷键说明

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