Void TEncSampleAdaptiveOffset::rdoSaoUnitAll() //得到最佳SAO_TYPE选择.并且,对offset值进行熵编码。
{
for (idxY = 0; idxY< frameHeightInCU; idxY++)//遍历LCU
{
for (idxX = 0; idxX< frameWidthInCU; idxX++)
{
// reset stats Y, Cb, Cr
calcSaoStatsCu(addr, compIdx, compIdx);//统计BO和EO各模式下,对应classIdx下滤波前的重建像素值与原始像素值的差值的总和,以及对classIdx的像素数的计数
saoComponentParamDist(); //得到亮度分量最佳SAO_TYPE
sao2ChromaParamDist(); //得到色度分量最近SAO_TYPE
for ( compIdx=0;compIdx<3;compIdx++)
encodeSaoOffset(&saoLcuParam[compIdx][addr], compIdx);
// Cost of Merge 判断是否要进行Merge
rate = m_pcEntropyCoder->getNumberOfWrittenBits();//计算码率
mergeCost = compDistortion[mergeUp+1] + (Double)rate;
//计算RDCOST,Merge的compDistortion是在函数saoComponentParamDist中完成的。
if (mergeCost < bestCost) //判断mergeCost是否小于bestCost,如果是,则merge.
{
bestCost = mergeCost;
m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
for ( compIdx=0;compIdx<3;compIdx++)
{
if( (compIdx==0 && saoParam->bSaoFlag[0]) || (compIdx>0 && saoParam->bSaoFlag[1]))
{
copySaoUnit(&saoParam->saoLcuParam[compIdx][addr], &mergeSaoParam[compIdx][mergeUp] );
}
}
}
}
}