📄 transform8x8.c
字号:
//--- 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_x+i][block_y+j];
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_x+i][block_y+j];
/* Forward Residue Transform */
resTrans_R[i][j] = residue_R-residue_B;
temp = residue_B+(resTrans_R[i][j]>>1);
resTrans_B[i][j] = residue_G-temp;
resTrans_G[i][j] = temp+(resTrans_B[i][j]>>1);
}
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
img->m7[i][j] = resTrans_G[i][j];
}
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[i][j] = img->m7[i][j];
}
store_coding_state_cs_cm();
for(b4=0;b4<4;b4++)
{
block4x4_x = 4*(b4%2);
block4x4_y = 4*(b4/2);
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
img->m7[i][j] = resTrans_R[i+block4x4_x][j+block4x4_y];
}
rate += RDCost_for_4x4Blocks_Chroma (b8+4, b4, 0);
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
rec_resR[i+block4x4_x][j+block4x4_y] = img->m7[i][j];
img->m7[i][j] = resTrans_B[i+block4x4_x][j+block4x4_y];
}
rate += RDCost_for_4x4Blocks_Chroma (b8+8, b4, 1);
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
rec_resB[i+block4x4_x][j+block4x4_y] = img->m7[i][j];
}
}
reset_coding_state_cs_cm();
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
/* Inverse Residue Transform */
temp = rec_resG[i][j]-(rec_resB[i][j]>>1);
residue_G = rec_resB[i][j]+temp;
residue_B = temp - (rec_resR[i][j]>>1);
residue_R = residue_B+rec_resR[i][j];
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_x+i][block_y+j]));
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_x+i][block_y+j]));
}
//===== 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 += (imgY_org[pic_pix_y+y][x] - enc_picture->imgY[pic_pix_y+y][x])*(imgY_org[pic_pix_y+y][x] - enc_picture->imgY[pic_pix_y+y][x]);
distortion += (imgUV_org[0][pic_pix_y+y][x] - enc_picture->imgUV[0][pic_pix_y+y][x])*(imgUV_org[0][pic_pix_y+y][x] - enc_picture->imgUV[0][pic_pix_y+y][x]);
distortion += (imgUV_org[1][pic_pix_y+y][x] - enc_picture->imgUV[1][pic_pix_y+y][x])*(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%2);
block4x4_y = 4*(b4/2);
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%2)+(b4%2)][2*(b8/2)+(b4/2)] = dc_level_temp[i][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)];
cbp_chroma_block[i][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)] = cbp_chroma_block_temp[i][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)];
//--- 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_x][pic_block_y] = best_ipmode;
img->mb_data[img->current_mb_nr].intra_pred_modes8x8[4*b8] = mostProbableMode == best_ipmode ? -1 : best_ipmode < mostProbableMode ? best_ipmode : best_ipmode-1;
for(j = 0; j < 2; j++) //loop 4x4s in the subblock for 8x8 prediction setting
for(i = 0; i < 2; i++)
img->ipredmode8x8[i+img->mb_x*4+(b8%2)*2][j+img->mb_y*4+(b8/2)*2]=best_ipmode; //offsets
if (!input->rdopt)
{
// Residue Color Transform
if(!img->residue_transform_flag)
{
// get prediction and prediction error
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
img->mpr[block_x+i][block_y+j] = img->mprr_3[best_ipmode][j][i];
img->m7[i][j] = 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_x+i][block_y+j] = 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_x+i][block_y+j];
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_x+i][block_y+j];
/* Forward Residue Transform */
resTrans_R[i][j] = residue_R-residue_B;
temp = residue_B+(resTrans_R[i][j]>>1);
resTrans_B[i][j] = residue_G-temp;
resTrans_G[i][j] = temp+(resTrans_B[i][j]>>1);
}
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
img->m7[i][j] = resTrans_G[i][j];
}
nonzero = dct_luma8x8 (b8, &dummy, 1);
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
rec_resG[i][j] = img->m7[i][j];
}
for(b4=0;b4<4;b4++)
{
block4x4_x = 4*(b4%2);
block4x4_y = 4*(b4/2);
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
img->m7[i][j] = resTrans_R[i+block4x4_x][j+block4x4_y];
}
cbp_chroma_block[0][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)] = dct_chroma4x4 (0, b8+4, b4);
dc_level[0][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)] = dc_level_temp[0][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)];
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
rec_resR[i+block4x4_x][j+block4x4_y] = img->m7[i][j];
img->m7[i][j] = resTrans_B[i+block4x4_x][j+block4x4_y];
}
cbp_chroma_block[1][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)] = dct_chroma4x4 (1, b8+8, b4);
dc_level[1][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)] = dc_level_temp[1][2*(b8%2)+(b4%2)][2*(b8/2)+(b4/2)];
for (j=0; j<4; j++)
for (i=0; i<4; i++)
{
rec_resB[i+block4x4_x][j+block4x4_y] = img->m7[i][j];
}
}
for (j=0; j<8; j++)
for (i=0; i<8; i++)
{
/* Inverse Residue Transform */
temp = rec_resG[i][j]-(rec_resB[i][j]>>1);
residue_G = rec_resB[i][j]+temp;
residue_B = temp - (rec_resR[i][j]>>1);
residue_R = residue_B+rec_resR[i][j];
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_x+i][block_y+j]));
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_x+i][block_y+j]));
}
}
}
else
{
//===== restore coefficients =====
for (j=0; j<2; j++)
for (i=0; i<65;i++)
for(k=0; k<4; k++) // do 4x now
img->cofAC[b8][k][j][i]=cofAC8x8[b8][k][j][i]; // k vs. 0
// 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++)
for (x=0; x<8; x++)
{
enc_picture->imgY[pic_pix_y+y][pic_pix_x+x] = rec8x8[y][x];
img->mpr[block_x+x][block_y+y] = img->mprr_3[best_ipmode][y][x];
}
// Residue Color Transform
if(img->residue_transform_flag)
{
for(b4=0; b4<4; b4++)
{
block4x4_x = 4*(b4%2);
block4x4_y = 4*(b4/2);
for (i=0; i<2; i++)
{ //uv
//--- set reconstruction ---
for (y=0; y<4; y++)
for (x=0; x<4; x++) enc_picture->imgUV[i][pic_pix_y+y+block4x4_y][pic_pix_x+x+block4x4_x] = rec8x8_c[i][b4][y][x];
}
}
}
}
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:
* Starting point of current 8x8 block image posision
*
* \par Output:
* none
************************************************************************
*/
void intrapred_luma8x8(int img_x,int img_y, int *left_available, int *up_available, int *all_available)
{
int i,j;
int s0;
int PredPel[25]; // array of predictor pels
imgpel **imgY = enc_picture->imgY; // For MB level frame/field coding tools -- set default to imgY
int ioff = (img_x & 15);
int joff = (img_y & 15);
int mb_nr=img->current_mb_nr;
PixelPos pix_a[8];
PixelPos pix_b, pix_c, pix_d;
int block_available_up;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -