//16*16亮度的DC,为上面跟左面32个值的平均值。
void WelsI16x16LumaPredDc_c (uint8_t* pPred, const int32_t kiStride) {
int32_t iTmp = (kiStride << 4) - kiStride;
int32_t iSum = 0;
uint8_t i = 15;
uint8_t uiMean = 0;
/*caculate the kMean value*/
do {
iSum += pPred[-1 + iTmp] + pPred[-kiStride + i]; //前面是竖着的,后面是横着的
iTmp -= kiStride;
} while (i-- > 0);
uiMean = (16 + iSum) >> 5;
iTmp = (kiStride << 4) - kiStride;
i = 15;
do {
memset (&pPred[iTmp], uiMean, I16x16_COUNT);
iTmp -= kiStride;
} while (i-- > 0);
}
WelsI16x16LumaPredDc_c 的测试函数:
TEST (GetIntraPredictorTest, TestGetI16x16LumaPredDc) {
const int32_t kiStride = rand() % 16 + 16; //stride指在内存中每行像素所占的空间
int i;
uint8_t* pPred = new uint8_t[256];
uint8_t* pRef = new uint8_t[16 * kiStride];
for (i = 0; i < 16 * kiStride; i++) //16行,每行stride
pRef[i] = rand() % 256 + 1;
pRef += kiStride; //指向了第二行开始
int32_t iTmp = (kiStride << 4) - kiStride; //最后一行开始
int32_t iSum = 0;
i = 15;
uint8_t uiMean = 0;
do {
iSum += pRef[-1 + iTmp] + pRef[-kiStride + i]; //前面是竖着的,后面是横着的
iTmp -= kiStride;
} while (i-- > 0);
uiMean = (16 + iSum) >> 5;
WelsI16x16LumaPredDc_c (pPred, pRef, kiStride);
for (i = 0; i < 256; i++)
EXPECT_EQ (pPred[i], uiMean);
pRef -= kiStride;
delete []pRef;
delete []pPred;
}