Added 4x4 SATD (Hadamard)

Taken from HM 13.0
This commit is contained in:
Marko Viitanen 2014-04-02 11:12:42 +03:00
parent cfb21c0e4c
commit 21e02e2d7d

View file

@ -368,6 +368,101 @@ double image_psnr(pixel *frame1, pixel *frame2, int32_t x, int32_t y)
return 10 * log10((pixels * PSNRMAX) / ((double)error_sum));
}
/**
* \brief Calculate SATD between two 4x4 blocks inside bigger arrays.
* From HM 13.0
*/
static unsigned satd_16bit_4x4(pixel *piOrg,pixel *piCur)
{
int32_t k, satd = 0, diff[16], m[16], d[16];
int32_t iStrideOrg = 4, iStrideCur = 4;
for( k = 0; k < 16; k+=4 ) {
diff[k+0] = piOrg[0] - piCur[0];
diff[k+1] = piOrg[1] - piCur[1];
diff[k+2] = piOrg[2] - piCur[2];
diff[k+3] = piOrg[3] - piCur[3];
piCur += iStrideCur;
piOrg += iStrideOrg;
}
/*===== hadamard transform =====*/
m[ 0] = diff[ 0] + diff[12];
m[ 1] = diff[ 1] + diff[13];
m[ 2] = diff[ 2] + diff[14];
m[ 3] = diff[ 3] + diff[15];
m[ 4] = diff[ 4] + diff[ 8];
m[ 5] = diff[ 5] + diff[ 9];
m[ 6] = diff[ 6] + diff[10];
m[ 7] = diff[ 7] + diff[11];
m[ 8] = diff[ 4] - diff[ 8];
m[ 9] = diff[ 5] - diff[ 9];
m[10] = diff[ 6] - diff[10];
m[11] = diff[ 7] - diff[11];
m[12] = diff[ 0] - diff[12];
m[13] = diff[ 1] - diff[13];
m[14] = diff[ 2] - diff[14];
m[15] = diff[ 3] - diff[15];
d[ 0] = m[ 0] + m[ 4];
d[ 1] = m[ 1] + m[ 5];
d[ 2] = m[ 2] + m[ 6];
d[ 3] = m[ 3] + m[ 7];
d[ 4] = m[ 8] + m[12];
d[ 5] = m[ 9] + m[13];
d[ 6] = m[10] + m[14];
d[ 7] = m[11] + m[15];
d[ 8] = m[ 0] - m[ 4];
d[ 9] = m[ 1] - m[ 5];
d[10] = m[ 2] - m[ 6];
d[11] = m[ 3] - m[ 7];
d[12] = m[12] - m[ 8];
d[13] = m[13] - m[ 9];
d[14] = m[14] - m[10];
d[15] = m[15] - m[11];
m[ 0] = d[ 0] + d[ 3];
m[ 1] = d[ 1] + d[ 2];
m[ 2] = d[ 1] - d[ 2];
m[ 3] = d[ 0] - d[ 3];
m[ 4] = d[ 4] + d[ 7];
m[ 5] = d[ 5] + d[ 6];
m[ 6] = d[ 5] - d[ 6];
m[ 7] = d[ 4] - d[ 7];
m[ 8] = d[ 8] + d[11];
m[ 9] = d[ 9] + d[10];
m[10] = d[ 9] - d[10];
m[11] = d[ 8] - d[11];
m[12] = d[12] + d[15];
m[13] = d[13] + d[14];
m[14] = d[13] - d[14];
m[15] = d[12] - d[15];
d[ 0] = m[ 0] + m[ 1];
d[ 1] = m[ 0] - m[ 1];
d[ 2] = m[ 2] + m[ 3];
d[ 3] = m[ 3] - m[ 2];
d[ 4] = m[ 4] + m[ 5];
d[ 5] = m[ 4] - m[ 5];
d[ 6] = m[ 6] + m[ 7];
d[ 7] = m[ 7] - m[ 6];
d[ 8] = m[ 8] + m[ 9];
d[ 9] = m[ 8] - m[ 9];
d[10] = m[10] + m[11];
d[11] = m[11] - m[10];
d[12] = m[12] + m[13];
d[13] = m[12] - m[13];
d[14] = m[14] + m[15];
d[15] = m[15] - m[14];
for (k=0; k<16; ++k) {
satd += abs(d[k]);
}
satd = ((satd+1)>>1);
return satd;
}
/**
* \brief Calculate SATD between two 8x8 blocks inside bigger arrays.
*/
@ -463,9 +558,9 @@ static unsigned satd_16bit_8x8_general(pixel *piOrg, int32_t iStrideOrg,
return sad;
}
// Function macro for defining hadamart calculating functions
// for fixed size blocks. They calculate hadamart for integer
// multiples of 8x8 with the 8x8 hadamart function.
// Function macro for defining hadamard calculating functions
// for fixed size blocks. They calculate hadamard for integer
// multiples of 8x8 with the 8x8 hadamard function.
#define SATD_NXN(n, pixel_type, suffix) \
static unsigned satd_ ## suffix ## _ ## n ## x ## n( \
pixel_type *block1, pixel_type *block2) \
@ -523,6 +618,8 @@ SAD_NXN(64, pixel, 16bit)
cost_16bit_nxn_func get_satd_16bit_nxn_func(unsigned n)
{
switch (n) {
case 4:
return &satd_16bit_4x4;
case 8:
return &satd_16bit_8x8;
case 16: