📄 transform8x8.c
字号:
if (img->AdaptiveRounding)
{
for (j=block_y; j<block_y + 8; j++)
memcpy(&fadjust8x8[1][j][block_x],&img->fadjust8x8[1][j][block_x], 8 * sizeof(int));
}
//--- flag if dct-coefficients must be coded ---
nonzero = c_nz;
//--- set best mode update minimum cost ---
min_rdcost = rdcost;
best_ipmode = ipmode;
}
reset_coding_state_cs_cm();
}
else
{
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
residue_B = imgUV_org[0][pic_opix_y+j][pic_opix_x+i] - img->mprr_c[0][c_ipmode][block_y+j][block_x+i];
residue_G = imgY_org[pic_opix_y+j][pic_opix_x+i] - img->mprr_3[ipmode][j][i];
residue_R = imgUV_org[1][pic_opix_y+j][pic_opix_x+i] - img->mprr_c[1][c_ipmode][block_y+j][block_x+i];
/* Forward Residue Transform */
resTrans_R[j][i] = residue_R-residue_B;
temp = residue_B+(resTrans_R[j][i]>>1);
resTrans_B[j][i] = residue_G-temp;
resTrans_G[j][i] = temp+(resTrans_B[j][i]>>1);
}
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
img->m7[j][i] = resTrans_G[j][i];
}
//store_coding_state_cs_cm();
rate = (int) RDCost_for_8x8IntraBlocks (&c_nz, b8, ipmode, lambda, min_rdcost, mostProbableMode);
reset_coding_state_cs_cm();
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
rec_resG[j][i] = img->m7[j][i];
}
for(b4=0;b4<4;b4++)
{
block4x4_x = 4*(b4 & 0x01);
block4x4_y = 4*(b4 >> 1);
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
img->m7[j][i] = resTrans_B[j+block4x4_y][i+block4x4_x];
}
rate += RDCost_for_4x4Blocks_Chroma (b8+4, b4, 0);
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
rec_resB[j+block4x4_y][i+block4x4_x] = img->m7[j][i];
img->m7[j][i] = resTrans_R[j+block4x4_y][i+block4x4_x];
}
rate += RDCost_for_4x4Blocks_Chroma (b8+8, b4, 1);
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
rec_resR[j+block4x4_y][i+block4x4_x] = img->m7[j][i];
}
}
reset_coding_state_cs_cm();
for (j=0; j<8; j++)
{
for (i=0; i<8; i++)
{
/* Inverse Residue Transform */
temp = rec_resG[j][i]-(rec_resB[j][i]>>1);
residue_G = rec_resB[j][i]+temp;
residue_B = temp - (rec_resR[j][i]>>1);
residue_R = residue_B+rec_resR[j][i];
enc_picture->imgUV[0][pic_pix_y+j][pic_pix_x+i] = min(img->max_imgpel_value_uv,max(0,residue_B+(int)img->mprr_c[0][c_ipmode][block_y+j][block_x+i]));
enc_picture->imgY[pic_pix_y+j][pic_pix_x+i] = min(img->max_imgpel_value,max(0,residue_G+(int)img->mprr_3[ipmode][j][i]));
enc_picture->imgUV[1][pic_pix_y+j][pic_pix_x+i] = min(img->max_imgpel_value_uv,max(0,residue_R+(int)img->mprr_c[1][c_ipmode][block_y+j][block_x+i]));
}
}
//===== get distortion (SSD) of 8x8 block =====
distortion = 0;
for (y=0; y<8; y++)
for (x=pic_pix_x; x<pic_pix_x+8; x++)
{
distortion += img->quad[imgY_org [pic_pix_y+y][x] - enc_picture->imgY [pic_pix_y+y][x]];
distortion += img->quad[imgUV_org[0][pic_pix_y+y][x] - enc_picture->imgUV[0][pic_pix_y+y][x]];
distortion += img->quad[imgUV_org[1][pic_pix_y+y][x] - enc_picture->imgUV[1][pic_pix_y+y][x]];
}
rdcost = (double)distortion + lambda*(double)rate;
if (rdcost < min_rdcost)
{
//--- set coefficients ---
for (j=0; j<2; j++)
for (i=0; i<65;i++)
for(k=0; k<4; k++) //do 4x now
cofAC8x8[b8][k][j][i]=img->cofAC[b8][k][j][i]; //k vs 0
for(b4=0; b4<4; b4++)
{
block4x4_x = 4*(b4 & 0x01);
block4x4_y = 4*(b4 >> 1);
for (j=0; j<2; j++)
for (i=0; i<18;i++) cofAC8x8_chroma[0][b4][j][i]=img->cofAC[b8+4][b4][j][i];
for (j=0; j<2; j++)
for (i=0; i<18;i++) cofAC8x8_chroma[1][b4][j][i]=img->cofAC[b8+8][b4][j][i];
for (i=0; i<2; i++)
{ //uv
dc_level[i][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)] = dc_level_temp[i][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)];
cbp_chroma_block[i][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)] = cbp_chroma_block_temp[i][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)];
//--- set reconstruction ---
for (y=0; y<4; y++)
for (x=0; x<4; x++) rec8x8_c[i][b4][y][x] = enc_picture->imgUV[i][pic_pix_y+y+block4x4_y][pic_pix_x+x+block4x4_x];
}
}
//--- set reconstruction ---
for (y=0; y<8; y++)
for (x=0; x<8; x++)
rec8x8[y][x] = enc_picture->imgY[pic_pix_y+y][pic_pix_x+x];
//--- flag if dct-coefficients must be coded ---
nonzero = c_nz;
//--- set best mode update minimum cost ---
min_rdcost = rdcost;
best_ipmode = ipmode;
}
}
}
}
}
//===== set intra mode prediction =====
img->ipredmode8x8[pic_block_y][pic_block_x] = best_ipmode;
currMB->intra_pred_modes8x8[4*b8] = (mostProbableMode == best_ipmode)
? -1
: (best_ipmode < mostProbableMode ? best_ipmode : best_ipmode-1);
for(j = img->mb_y*4+(b8 >> 1)*2; j < img->mb_y*4+(b8 >> 1)*2 + 2; j++) //loop 4x4s in the subblock for 8x8 prediction setting
memset(&img->ipredmode8x8[j][img->mb_x*4+(b8 & 0x01)*2], best_ipmode, 2 * sizeof(char));
if (!input->rdopt)
{
// Residue Color Transform
if(!img->residue_transform_flag)
{
// get prediction and prediction error
for (j=0; j<8; j++)
{
memcpy(&img->mpr[block_y+j][block_x],img->mprr_3[best_ipmode][j], 8 * sizeof(imgpel));
for (i=0; i<8; i++)
{
img->m7[j][i] = imgY_orig[pic_opix_y+j][pic_opix_x+i] - img->mprr_3[best_ipmode][j][i];
}
}
nonzero = dct_luma8x8 (b8, &dummy, 1);
}
else
{
for (j=0; j<8; j++)
{
for (i=0; i<8; i++)
{
img->mpr[block_y+j][block_x+i] = img->mprr_3[best_ipmode][j][i];
residue_B = imgUV_org[0][pic_opix_y+j][pic_opix_x+i] - img->mprr_c[0][c_ipmode][block_y+j][block_x+i];
residue_G = imgY_org[pic_opix_y+j][pic_opix_x+i] - img->mprr_3[best_ipmode][j][i];
residue_R = imgUV_org[1][pic_opix_y+j][pic_opix_x+i] - img->mprr_c[1][c_ipmode][block_y+j][block_x+i];
/* Forward Residue Transform */
resTrans_R[j][i] = residue_R-residue_B;
temp = residue_B+(resTrans_R[j][i]>>1);
resTrans_B[j][i] = residue_G-temp;
resTrans_G[j][i] = temp+(resTrans_B[j][i]>>1);
}
}
for (j=0; j<8; j++)
{
for (i=0; i<8; i++)
img->m7[j][i] = resTrans_G[j][i];
}
nonzero = dct_luma8x8 (b8, &dummy, 1);
for (j=0; j<8; j++)
{
for (i=0; i<8; i++)
rec_resG[j][i] = img->m7[j][i];
}
for(b4=0;b4<4;b4++)
{
block4x4_x = 4*(b4 & 0x01);
block4x4_y = 4*(b4 >> 1);
for (j=0; j<4; j++)
{
for (i=0; i<4; i++)
img->m7[j][i] = resTrans_B[j+block4x4_y][i+block4x4_x];
}
cbp_chroma_block[0][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)] = dct_chroma4x4 (0, b8+4, b4);
dc_level [0][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)] = dc_level_temp[0][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)];
for (j=0; j<4; j++)
{
for (i=0; i<4; i++)
{
rec_resB[j+block4x4_y][i+block4x4_x] = img->m7[j][i];
img->m7[j][i] = resTrans_R[j+block4x4_y][i+block4x4_x];
}
}
cbp_chroma_block[1][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)] = dct_chroma4x4 (1, b8+8, b4);
dc_level [1][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)] = dc_level_temp[1][2*(b8 & 0x01)+(b4 & 0x01)][2*(b8 >> 1)+(b4 >> 1)];
for (j=0; j<4; j++)
{
for (i=0; i<4; i++)
rec_resR[j+block4x4_y][i+block4x4_x] = img->m7[j][i];
}
}
for (j=0; j<8; j++)
{
for (i=0; i<8; i++)
{
/* Inverse Residue Transform */
temp = rec_resG[j][i]-(rec_resB[j][i]>>1);
residue_G = rec_resB[j][i]+temp;
residue_B = temp - (rec_resR[j][i]>>1);
residue_R = residue_B+rec_resR[j][i];
enc_picture->imgUV[0][pic_pix_y+j][pic_pix_x+i] = min(img->max_imgpel_value_uv,max(0,residue_B+(int)img->mprr_c[0][c_ipmode][block_y+j][block_x+i]));
enc_picture->imgY[pic_pix_y+j][pic_pix_x+i] = min(img->max_imgpel_value,max(0,residue_G+(int)img->mprr_3[best_ipmode][j][i]));
enc_picture->imgUV[1][pic_pix_y+j][pic_pix_x+i] = min(img->max_imgpel_value_uv,max(0,residue_R+(int)img->mprr_c[1][c_ipmode][block_y+j][block_x+i]));
}
}
}
}
else
{
//===== restore coefficients =====
for(k=0; k<4; k++) // do 4x now
{
for (j=0; j<2; j++)
memcpy(img->cofAC[b8][k][j],cofAC8x8[b8][k][j], 65 * sizeof(int));
}
if (img->AdaptiveRounding)
{
for (j=0; j<8; j++)
memcpy(&img->fadjust8x8[1][block_y+j][block_x], &fadjust8x8[1][block_y+j][block_x], 8 * sizeof(int));
}
// Residue Color Transform
if(img->residue_transform_flag)
for(b4=0; b4<4; b4++){
for (j=0; j<2; j++)
for (i=0; i<18;i++)
img->cofAC[b8+4][b4][j][i]=cofAC8x8_chroma[0][b4][j][i];
for (j=0; j<2; j++)
for (i=0; i<18;i++)
img->cofAC[b8+8][b4][j][i]=cofAC8x8_chroma[1][b4][j][i];
}
//===== restore reconstruction and prediction (needed if single coeffs are removed) =====
for (y=0; y<8; y++)
{
memcpy(&enc_picture->imgY[pic_pix_y+y][pic_pix_x], rec8x8[y], 8 * sizeof(imgpel));
memcpy(& img->mpr[block_y+y][block_x], img->mprr_3[best_ipmode][y], 8 * sizeof(imgpel));
}
// Residue Color Transform
if(img->residue_transform_flag)
{
for(b4=0; b4<4; b4++)
{
block4x4_x = 4*(b4 & 0x01);
block4x4_y = 4*(b4>>1);
for (i=0; i<2; i++)
{ //uv
//--- set reconstruction ---
for (y=0; y<4; y++)
memcpy(&enc_picture->imgUV[i][pic_pix_y + block4x4_y + y][pic_pix_x + block4x4_x], rec8x8_c[i][b4][y], 4 * sizeof(imgpel));
}
}
}
}
return nonzero;
}
// Notation for comments regarding prediction and predictors.
// The pels of the 4x4 block are labelled a..p. The predictor pels above
// are labelled A..H, from the left I..P, and from above left X, as follows:
//
// Z A B C D E F G H I J K L M N O P
// Q a1 b1 c1 d1 e1 f1 g1 h1
// R a2 b2 c2 d2 e2 f2 g2 h2
// S a3 b3 c3 d3 e3 f3 g3 h3
// T a4 b4 c4 d4 e4 f4 g4 h4
// U a5 b5 c5 d5 e5 f5 g5 h5
// V a6 b6 c6 d6 e6 f6 g6 h6
// W a7 b7 c7 d7 e7 f7 g7 h7
// X a8 b8 c8 d8 e8 f8 g8 h8
// Predictor array index definitions
#define P_Z (PredPel[0])
#define P_A (PredPel[1])
#define P_B (PredPel[2])
#define P_C (PredPel[3])
#define P_D (PredPel[4])
#define P_E (PredPel[5])
#define P_F (PredPel[6])
#define P_G (PredPel[7])
#define P_H (PredPel[8])
#define P_I (PredPel[9])
#define P_J (PredPel[10])
#define P_K (PredPel[11])
#define P_L (PredPel[12])
#define P_M (PredPel[13])
#define P_N (PredPel[14])
#define P_O (PredPel[15])
#define P_P (PredPel[16])
#define P_Q (PredPel[17])
#define P_R (PredPel[18])
#define P_S (PredPel[19])
#define P_T (PredPel[20])
#define P_U (PredPel[21])
#define P_V (PredPel[22])
#define P_W (PredPel[23])
#define P_X (PredPel[24])
/*!
************************************************************************
* \brief
* Make intra 8x8 prediction according to all 9 prediction modes.
* The routine uses left and upper neighbouring points from
* previous coded blocks to do this (if available). Notice that
* inaccessible neighbouring points are signalled with a negative
* value in the predmode array .
*
* \par Input:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -