- // 函数功能是计算8×8块的哈达玛变换,并计算其SATD值,m2[8][8]存放最终的变换结果
- Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
- {
- Int k, i, j, jj;
- Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0;
- //把8×8块像素存放在一维数组中
- for( k = 0; k < 64; k += 8 )
- {
- diff[k+0] = piOrg[0] ;
- diff[k+1] = piOrg[1] ;
- diff[k+2] = piOrg[2] ;
- diff[k+3] = piOrg[3] ;
- diff[k+4] = piOrg[4] ;
- diff[k+5] = piOrg[5] ;
- diff[k+6] = piOrg[6] ;
- diff[k+7] = piOrg[7] ;
- piOrg += iStrideOrg; //指针指向下一行
- }
- //horizontal 水平变换,计算V=X×H,
- for (j=0; j < 8; j++)
- {
- jj = j << 3; //一次算8个,乘8换行
- m2[j][0] = diff[jj ] + diff[jj+4];
- m2[j][1] = diff[jj+1] + diff[jj+5];
- m2[j][2] = diff[jj+2] + diff[jj+6];
- m2[j][3] = diff[jj+3] + diff[jj+7];
- m2[j][4] = diff[jj ] - diff[jj+4];
- m2[j][5] = diff[jj+1] - diff[jj+5];
- m2[j][6] = diff[jj+2] - diff[jj+6];
- m2[j][7] = diff[jj+3] - diff[jj+7];
- m1[j][0] = m2[j][0] + m2[j][2];
- m1[j][1] = m2[j][1] + m2[j][3];
- m1[j][2] = m2[j][0] - m2[j][2];
- m1[j][3] = m2[j][1] - m2[j][3];
- m1[j][4] = m2[j][4] + m2[j][6];
- m1[j][5] = m2[j][5] + m2[j][7];
- m1[j][6] = m2[j][4] - m2[j][6];
- m1[j][7] = m2[j][5] - m2[j][7];
- m2[j][0] = m1[j][0] + m1[j][1];
- m2[j][1] = m1[j][0] - m1[j][1];
- m2[j][2] = m1[j][2] + m1[j][3];
- m2[j][3] = m1[j][2] - m1[j][3];
- m2[j][4] = m1[j][4] + m1[j][5];
- m2[j][5] = m1[j][4] - m1[j][5];
- m2[j][6] = m1[j][6] + m1[j][7];
- m2[j][7] = m1[j][6] - m1[j][7];
- }
- //vertical 垂直变换,计算H×V
- for (i=0; i < 8; i++)
- {
- m3[0][i] = m2[0][i] + m2[4][i];
- m3[1][i] = m2[1][i] + m2[5][i];
- m3[2][i] = m2[2][i] + m2[6][i];
- m3[3][i] = m2[3][i] + m2[7][i];
- m3[4][i] = m2[0][i] - m2[4][i];
- m3[5][i] = m2[1][i] - m2[5][i];
- m3[6][i] = m2[2][i] - m2[6][i];
- m3[7][i] = m2[3][i] - m2[7][i];
- m1[0][i] = m3[0][i] + m3[2][i];
- m1[1][i] = m3[1][i] + m3[3][i];
- m1[2][i] = m3[0][i] - m3[2][i];
- m1[3][i] = m3[1][i] - m3[3][i];
- m1[4][i] = m3[4][i] + m3[6][i];
- m1[5][i] = m3[5][i] + m3[7][i];
- m1[6][i] = m3[4][i] - m3[6][i];
- m1[7][i] = m3[5][i] - m3[7][i];
- m2[0][i] = m1[0][i] + m1[1][i];
- m2[1][i] = m1[0][i] - m1[1][i];
- m2[2][i] = m1[2][i] + m1[3][i];
- m2[3][i] = m1[2][i] - m1[3][i];
- m2[4][i] = m1[4][i] + m1[5][i];
- m2[5][i] = m1[4][i] - m1[5][i];
- m2[6][i] = m1[6][i] + m1[7][i];
- m2[7][i] = m1[6][i] - m1[7][i];
- }
- for (i = 0; i < 8; i++)
- {
- for (j = 0; j < 8; j++)
- {
- iSumHad += abs(m2[i][j]);
- }
- }
- iSumHad -= abs(m2[0][0]);
- iSumHad =(iSumHad+2)>>2; //除以系数4,并向上取整
- return(iSumHad);
- }