📄 umc_h264_deblocking_mbaff.cpp
字号:
VM_ASSERT(-1 == m_pCurrentFrame->m_mbinfo.RefIdxs[1][MBAddr].RefIdxs[nNeighbourBlock]);
{
H264EncoderFrame<PixType> **pRefPicList;
Ipp32s index;
pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 0)->m_RefPicList;
// select reference index for current block
index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][MBAddr].RefIdxs[nBlock];
iRefQ = (index < 0) ?
(-1) :
(pRefPicList[index >> 1]->DeblockPicID(index & 1));
// select reference index for previous block
index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][MBAddr].RefIdxs[nNeighbourBlock];
iRefP = (index < 0) ?
(-1) :
pRefPicList[index >> 1]->DeblockPicID(index & 1);
}
VM_ASSERT((iRefP != -1) || (iRefQ != -1));
// when reference indexes are equal
if (iRefQ == iRefP)
{
H264MotionVector *pVectorQ, *pVectorP;
pVectorQ = m_pCurrentFrame->m_mbinfo.MV[0][MBAddr].MotionVectors + nBlock;
pVectorP = m_pCurrentFrame->m_mbinfo.MV[0][MBAddr].MotionVectors + nNeighbourBlock;
// compare motion vectors
if ((4 <= abs(pVectorQ->mvx - pVectorP->mvx)) ||
(2 <= 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;
}
}
}
}
} // void H264CoreEncoder::PrepareDeblockingParametersPSlice4MBAFFField(Ipp32u dir, DeblockingParameters<PixType> *pParams)
template <class PixType, class CoeffsType>
void H264CoreEncoder<PixType,CoeffsType>::PrepareDeblockingParametersBSlice4MBAFFField(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;
// calc block and neighbour block number
if (VERTICAL_DEBLOCKING == dir)
{
nBlock = idx * 4;
nNeighbourBlock = nBlock + 3;
}
else
{
nBlock = idx;
nNeighbourBlock = idx + 12;
}
{
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 >> 1]->DeblockPicID(index & 1);
}
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 >> 1]->DeblockPicID(index & 1);
}
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 >> 1]->DeblockPicID(index & 1);
}
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 >> 1]->DeblockPicID(index & 1);
}
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 H264MotionVector *pVectorPFrw, *pVectorPBck;
// select current block motion vectors
pVectorQFrw = (iRefQFrw < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[0][MBAddr].MotionVectors + nBlock;
pVectorQBck = (iRefQBck < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[1][MBAddr].MotionVectors + nBlock;
// select previous block motion vectors
if (iRefQFrw == iRefPFrw)
{
pVectorPFrw = (iRefPFrw < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[0][nNeighbour].MotionVectors + nNeighbourBlock;
pVectorPBck = (iRefPBck < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[1][nNeighbour].MotionVectors + nNeighbourBlock;
}
else
{
pVectorPFrw = (iRefPBck < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[1][nNeighbour].MotionVectors + nNeighbourBlock;
pVectorPBck = (iRefPFrw < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[0][nNeighbour].MotionVectors + nNeighbourBlock;
}
// compare motion vectors
if ((4 <= abs(pVectorQFrw->mvx - pVectorPFrw->mvx)) ||
(2 <= abs(pVectorQFrw->mvy - pVectorPFrw->mvy)) ||
(4 <= abs(pVectorQBck->mvx - pVectorPBck->mvx)) ||
(2 <= abs(pVectorQBck->mvy - pVectorPBck->mvy)))
{
pStrength[idx] = 1;
*pDeblockingFlag = 1;
}
}
// when forward and backward reference pictures of previous block are equal
else
{
const H264MotionVector *pVectorQFrw, *pVectorQBck;
const H264MotionVector *pVectorPFrw, *pVectorPBck;
// select current block motion vectors
pVectorQFrw = (iRefQFrw < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[0][MBAddr].MotionVectors + nBlock;
pVectorQBck = (iRefQBck < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[1][MBAddr].MotionVectors + nBlock;
// select previous block motion vectors
pVectorPFrw = (iRefPFrw < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[0][nNeighbour].MotionVectors + nNeighbourBlock;
pVectorPBck = (iRefPBck < 0)? &null_mv: m_pCurrentFrame->m_mbinfo.MV[1][nNeighbour].MotionVectors + nNeighbourBlock;
// compare motion vectors
if ((4 <= abs(pVectorQFrw->mvx - pVectorPFrw->mvx)) ||
(2 <= abs(pVectorQFrw->mvy - pVectorPFrw->mvy)) ||
(4 <= abs(pVectorQBck->mvx - pVectorPBck->mvx)) ||
(2 <= abs(pVectorQBck->mvy - pVectorPBck->mvy)))
{
if ((4 <= abs(pVectorQFrw->mvx - pVectorPBck->mvx)) ||
(2 <= abs(pVectorQFrw->mvy - pVectorPBck->mvy)) ||
(4 <= abs(pVectorQBck->mvx - pVectorPFrw->mvx)) ||
(2 <= abs(pVectorQBck->mvy - pVectorPFrw->mvy)))
{
pStrength[idx] = 1;
*pDeblockingFlag = 1;
}
}
}
}
// when reference indexes are different
else
{
pStrength[idx] = 1;
*pDeblockingFlag = 1;
}
}
}
}
// external edge required in strong filtering
else
{
if (HORIZONTAL_DEBLOCKING == dir)
SetEdgeStrength(pStrength + 0, 3);
else
SetEdgeStrength(pStrength + 0, 4);
*pDeblockingFlag = 1;
}
}
//
// internal edge(s)
//
{
Ipp32u idx;
// 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;
*pDeblockingFlag = 1;
}
// compare motion vectors & reference indexes
else
{
Ipp32u nBlock, nNeighbourBlock;
Ipp32s iRefQFrw, iRefQBck, iRefPFrw, iRefPBck;
// calc block and neighbour block number
if (VERTICAL_DEBLOCKING == dir)
{
nBlock = (idx & 3) * 4 + (idx >> 2);
nNeighbourBlock = nBlock - 1;
}
else
{
nBlock = idx;
nNeighbourBlock = idx - 4;
}
{
H264EncoderFrame<PixType> **pRefPicList;
Ipp32s index;
// select forward reference pictures list
pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 0)->m_RefPicList;
// select forward reference index for block(s)
index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][MBAddr].RefIdxs[nBlock];
iRefQFrw = (index < 0) ?
(-1) :
(pRefPicList[index >> 1]->DeblockPicID(index & 1));
index = m_pCurrentFrame->m_mbinfo.RefIdxs[0][MBAddr].RefIdxs[nNeighbourBlock];
iRefPFrw = (index < 0) ?
(-1) :
pRefPicList[index >> 1]->DeblockPicID(index & 1);
// select backward reference pictures list
pRefPicList = m_pCurrentFrame->GetRefPicList((m_pCurrentFrame->m_mbinfo.mbs + MBAddr)->slice_id, 1)->m_RefPicList;
// select backward reference index for block(s)
index = m_pCurrentFrame->m_mbinfo.RefIdxs[1][MBAddr].RefIdxs[nBlock];
iRefQBck = (index < 0) ?
(-1) :
(pRefPicList[index >> 1]->DeblockPicID(index & 1));
index = m_pCurrentFrame->m_mbinfo.RefIdxs[1][MBAddr].RefIdxs[nNeighbourBlock];
iRefPBck = (index < 0) ?
(-1) :
pRefPicList[index >> 1]->DeblockPicID(index & 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -