template<int log2TrSize>
static void nonPsyRdoQuant_c(
int16_t *m_resiDctCoeff, int64_t *costUncoded, int64_t *totalUncodedCost, int64_t *totalRdCost, uint32_t blkPos)
/*
参数说明:
1 残差dct变换后的因子,
2 costUncoded当前系数全部编码为0的 distortion cost衡量,数组,衡量每一个系数
3 总的cg 编码为0开销
4 当前这个cg编码为0的开销。
5 当前的cg在TB中的位置。
*/
{
const int transformShift = MAX_TR_DYNAMIC_RANGE - S265_DEPTH - log2TrSize; /* Represents scaling through forward transform */
const int scaleBits = SCALE_BITS - 2 * transformShift;
const uint32_t trSize = 1 << log2TrSize;
for (int y = 0; y < MLS_CG_SIZE; y++)
{
for (int x = 0; x < MLS_CG_SIZE; x++)
{
int64_t signCoef = m_resiDctCoeff[blkPos + x]; /* pre-quantization DCT coeff */
costUncoded[blkPos + x] = static_cast<int64_t>((double)((signCoef * signCoef) << scaleBits));
//这里本来是需要 d * d <<scaleBits + bitcosts * lambda, 编码为0,bitcost没有了。distortion 就是因子的值
*totalUncodedCost += costUncoded[blkPos + x];//总的cg编码为0,付出的代价。
*totalRdCost += costUncoded[blkPos + x]; //当前cg把所有因子编码为0的cost加起来
}
blkPos += trSize;
}
}
这个地方计算开销的时候,直接signCoeff * signCoeff <<scaleBits。
#define DELTARDCOST(d0, d, deltabits) ((((int64_t)d * d - d0) << scaleBits) + ((lambda2 * (int64_t)(deltabits)) >> 8))
正常应该按照上面的方式计算,这里少了 lambda * deltabits ,因为没有编码bits了。