📄 block.c
字号:
s0=(s1+2)/BLOCK_SIZE; /* left edge */
if (!block_available_up && !block_available_left)
s0=128; /* top left corner, nothing to predict from */
for (i=0; i < BLOCK_SIZE; i++)
{
/* vertical prediction */
if (block_available_up)
s[i][0]=imgY[img_y-1][img_x+i];
/* horizontal prediction */
if (block_available_left)
s[i][1]=imgY[img_y+i][img_x-1];
}
for (j=0; j < BLOCK_SIZE; j++)
{
for (i=0; i < BLOCK_SIZE; i++)
{
img->mprr[DC_PRED][i][j]=s0; /* store DC prediction */
img->mprr[VERT_PRED][i][j]=s[j][0]; /* store vertical prediction */
img->mprr[HOR_PRED][i][j]=s[i][1]; /* store horizontal prediction */
}
}
/* Prediction according to 'diagonal' modes */
if (block_available_up && block_available_left)
{
int A = imgY[img_y-1][img_x];
int B = imgY[img_y-1][img_x+1];
int C = imgY[img_y-1][img_x+2];
int D = imgY[img_y-1][img_x+3];
int E = imgY[img_y ][img_x-1];
int F = imgY[img_y+1][img_x-1];
int G = imgY[img_y+2][img_x-1];
int H = imgY[img_y+3][img_x-1];
int I = imgY[img_y-1][img_x-1];
ia[0][0]=(H+2*G+F+2)/4;
ia[1][0]=(G+2*F+E+2)/4;
ia[2][0]=(F+2*E+I+2)/4;
ia[3][0]=(E+2*I+A+2)/4;
ia[4][0]=(I+2*A+B+2)/4;
ia[5][0]=(A+2*B+C+2)/4;
ia[6][0]=(B+2*C+D+2)/4;
for (i=0;i<4;i++)
for (j=0;j<4;j++)
img->mprr[DIAG_PRED_LR_45][i][j]=ia[j-i+3][0];
}
if (block_available_up)
{ /* Do prediction 1 */
int A = imgY[img_y-1][img_x+0];
int B = imgY[img_y-1][img_x+1];
int C = imgY[img_y-1][img_x+2];
int D = imgY[img_y-1][img_x+3];
img->mprr[DIAG_PRED_RL][0][0] = (A+B)/2; /* a */
img->mprr[DIAG_PRED_RL][1][0] = B; /* e */
img->mprr[DIAG_PRED_RL][0][1] = img->mprr[DIAG_PRED_RL][2][0] = (B+C)/2; /* b i */
img->mprr[DIAG_PRED_RL][1][1] = img->mprr[DIAG_PRED_RL][3][0] = C; /* f m */
img->mprr[DIAG_PRED_RL][0][2] = img->mprr[DIAG_PRED_RL][2][1] = (C+D)/2; /* c j */
img->mprr[DIAG_PRED_RL][3][1] =
img->mprr[DIAG_PRED_RL][1][2] =
img->mprr[DIAG_PRED_RL][2][2] =
img->mprr[DIAG_PRED_RL][3][2] =
img->mprr[DIAG_PRED_RL][0][3] =
img->mprr[DIAG_PRED_RL][1][3] =
img->mprr[DIAG_PRED_RL][2][3] =
img->mprr[DIAG_PRED_RL][3][3] = D; /* d g h k l n o p */
}
if (block_available_left)
{ /* Do prediction 5 */
int E = imgY[img_y+0][img_x-1];
int F = imgY[img_y+1][img_x-1];
int G = imgY[img_y+2][img_x-1];
int H = imgY[img_y+3][img_x-1];
img->mprr[DIAG_PRED_LR][0][0] = (E+F)/2; /* a */
img->mprr[DIAG_PRED_LR][0][1] = F; /* b */
img->mprr[DIAG_PRED_LR][1][0] = img->mprr[DIAG_PRED_LR][0][2] = (F+G)/2; /* e c */
img->mprr[DIAG_PRED_LR][1][1] = img->mprr[DIAG_PRED_LR][0][3] = G; /* f d */
img->mprr[DIAG_PRED_LR][2][0] = img->mprr[DIAG_PRED_LR][1][2] = (G+H)/2; /* i g */
img->mprr[DIAG_PRED_LR][1][3] =
img->mprr[DIAG_PRED_LR][2][1] =
img->mprr[DIAG_PRED_LR][2][2] =
img->mprr[DIAG_PRED_LR][2][3] =
img->mprr[DIAG_PRED_LR][3][0] =
img->mprr[DIAG_PRED_LR][3][1] =
img->mprr[DIAG_PRED_LR][3][2] =
img->mprr[DIAG_PRED_LR][3][3] = H;
}
}
#endif // USE_9_INTRA_MODES
/************************************************************************
*
* Routine : intrapred_luma_2()
*
* Description: 16x16 based luma prediction
*
* Input : Image parameters
*
* Output : none
*
************************************************************************/
void intrapred_luma_2()
{
int s0=0,s1,s2;
int i,j;
int s[16][2];
int ih,iv;
int ib,ic,iaa;
int mb_nr = img->current_mb_nr;
int mb_width = img->width/16;
int mb_available_up = (img->mb_y == 0) ? 0 : (img->slice_numbers[mb_nr] == img->slice_numbers[mb_nr-mb_width]);
int mb_available_left = (img->mb_x == 0) ? 0 : (img->slice_numbers[mb_nr] == img->slice_numbers[mb_nr-1]);
s1=s2=0;
/* make DC prediction */
for (i=0; i < MB_BLOCK_SIZE; i++)
{
if (mb_available_up)
s1 += imgY[img->pix_y-1][img->pix_x+i]; /* sum hor pix */
if (mb_available_left)
s2 += imgY[img->pix_y+i][img->pix_x-1]; /* sum vert pix */
}
if (mb_available_up && mb_available_left)
s0=(s1+s2+16)/(2*MB_BLOCK_SIZE); /* no edge */
if (!mb_available_up && mb_available_left)
s0=(s2+8)/MB_BLOCK_SIZE; /* upper edge */
if (mb_available_up && !mb_available_left)
s0=(s1+8)/MB_BLOCK_SIZE; /* left edge */
if (!mb_available_up && !mb_available_left)
s0=128; /* top left corner, nothing to predict from */
for (i=0; i < MB_BLOCK_SIZE; i++)
{
/* vertical prediction */
if (mb_available_up)
s[i][0]=imgY[img->pix_y-1][img->pix_x+i];
/* horizontal prediction */
if (mb_available_left)
s[i][1]=imgY[img->pix_y+i][img->pix_x-1];
}
for (j=0; j < MB_BLOCK_SIZE; j++)
{
for (i=0; i < MB_BLOCK_SIZE; i++)
{
img->mprr_2[VERT_PRED_16][j][i]=s[i][0]; /* store vertical prediction */
img->mprr_2[HOR_PRED_16 ][j][i]=s[j][1]; /* store horizontal prediction */
img->mprr_2[DC_PRED_16 ][j][i]=s0; /* store DC prediction */
}
}
if (!mb_available_up || !mb_available_left) /* edge */
return;
/* 16 bit integer plan pred */
ih=0;
iv=0;
for (i=1;i<9;i++)
{
ih += i*(imgY[img->pix_y-1][img->pix_x+7+i] - imgY[img->pix_y-1][img->pix_x+7-i]);
iv += i*(imgY[img->pix_y+7+i][img->pix_x-1] - imgY[img->pix_y+7-i][img->pix_x-1]);
}
ib=5*(ih/4)/16;
ic=5*(iv/4)/16;
iaa=16*(imgY[img->pix_y-1][img->pix_x+15]+imgY[img->pix_y+15][img->pix_x-1]);
for (j=0;j< MB_BLOCK_SIZE;j++)
{
for (i=0;i< MB_BLOCK_SIZE;i++)
{
img->mprr_2[PLANE_16][j][i]=(iaa+(i-7)*ib +(j-7)*ic + 16)/32;/* store plane prediction */
}
}
}
/************************************************************************
*
* Routine: dct_luma2()
*
* Description: For new intra pred routines
*
*
* Input: Image par, 16x16 based intra mode
*
* Output: none
*
************************************************************************/
void dct_luma2(int new_intra_mode)
{
#ifndef NO_RDQUANT
int jq0;
#endif
#ifdef NO_RDQUANT
int qp_const;
#endif
int i,j;
int ii,jj;
int i1,j1;
int M1[16][16];
int M4[4][4];
int M5[4],M6[4];
int M0[4][4][4][4];
#ifndef NO_RDQUANT
int coeff[16];
#endif
int quant_set,run,scan_pos,coeff_ctr,level;
#ifndef NO_RDQUANT
jq0=JQQ3;
#endif
#ifdef NO_RDQUANT
qp_const = JQQ3;
#endif
for (j=0;j<16;j++)
{
for (i=0;i<16;i++)
{
M1[i][j]=imgY_org[img->pix_y+j][img->pix_x+i]-img->mprr_2[new_intra_mode][j][i];
M0[i%4][i/4][j%4][j/4]=M1[i][j];
}
}
for (jj=0;jj<4;jj++)
{
for (ii=0;ii<4;ii++)
{
for (j=0;j<4;j++)
{
for (i=0;i<2;i++)
{
i1=3-i;
M5[i]= M0[i][ii][j][jj]+M0[i1][ii][j][jj];
M5[i1]= M0[i][ii][j][jj]-M0[i1][ii][j][jj];
}
M0[0][ii][j][jj]=(M5[0]+M5[1])*13;
M0[2][ii][j][jj]=(M5[0]-M5[1])*13;
M0[1][ii][j][jj]=M5[3]*17+M5[2]*7;
M0[3][ii][j][jj]=M5[3]*7-M5[2]*17;
}
/* vertical */
for (i=0;i<4;i++)
{
for (j=0;j<2;j++)
{
j1=3-j;
M5[j] = M0[i][ii][j][jj]+M0[i][ii][j1][jj];
M5[j1]= M0[i][ii][j][jj]-M0[i][ii][j1][jj];
}
M0[i][ii][0][jj]=(M5[0]+M5[1])*13;
M0[i][ii][2][jj]=(M5[0]-M5[1])*13;
M0[i][ii][1][jj]= M5[3]*17+M5[2]*7;
M0[i][ii][3][jj]= M5[3]*7 -M5[2]*17;
}
}
}
/* pick out DC coeff */
for (j=0;j<4;j++)
for (i=0;i<4;i++)
M4[i][j]= 49 * M0[0][i][0][j]/32768;
for (j=0;j<4;j++)
{
for (i=0;i<2;i++)
{
i1=3-i;
M5[i]= M4[i][j]+M4[i1][j];
M5[i1]=M4[i][j]-M4[i1][j];
}
M4[0][j]=(M5[0]+M5[1])*13;
M4[2][j]=(M5[0]-M5[1])*13;
M4[1][j]= M5[3]*17+M5[2]*7;
M4[3][j]= M5[3]*7 -M5[2]*17;
}
/* vertical */
for (i=0;i<4;i++)
{
for (j=0;j<2;j++)
{
j1=3-j;
M5[j]= M4[i][j]+M4[i][j1];
M5[j1]=M4[i][j]-M4[i][j1];
}
M4[i][0]=(M5[0]+M5[1])*13;
M4[i][2]=(M5[0]-M5[1])*13;
M4[i][1]= M5[3]*17+M5[2]*7;
M4[i][3]= M5[3]*7 -M5[2]*17;
}
/* quant */
quant_set=img->qp;
run=-1;
scan_pos=0;
#ifndef NO_RDQUANT
for (coeff_ctr=0;coeff_ctr<16;coeff_ctr++)
{
i=SNGL_SCAN[coeff_ctr][0];
j=SNGL_SCAN[coeff_ctr][1];
coeff[coeff_ctr]=M4[i][j];
}
rd_quant(QUANT_LUMA_SNG,coeff);
for (coeff_ctr=0;coeff_ctr<16;coeff_ctr++)
{
i=SNGL_SCAN[coeff_ctr][0];
j=SNGL_SCAN[coeff_ctr][1];
run++;
level=abs(coeff[coeff_ctr]);
if (level != 0)
{
img->cof[0][0][scan_pos][0][1]=sign(level,M4[i][j]);
img->cof[0][0][scan_pos][1][1]=run;
++scan_pos;
run=-1;
}
#endif
#ifdef NO_RDQUANT
for (coeff_ctr=0;coeff_ctr<16;coeff_ctr++)
{
i=SNGL_SCAN[coeff_ctr][0];
j=SNGL_SCAN[coeff_ctr][1];
run++;
level= (abs(M4[i][j]) * JQ[quant_set][0]+qp_const)/JQQ1;
if (level != 0)
{
img->cof[0][0][scan_pos][0][1]=sign(level,M4[i][j]);
img->cof[0][0][scan_pos][1][1]=run;
++scan_pos;
run=-1;
}
#endif
M4[i][j]=sign(level,M4[i][j]);
}
img->cof[0][0][scan_pos][0][1]=0;
/* invers DC transform */
for (j=0;j<4;j++)
{
for (i=0;i<4;i++)
M5[i]=M4[i][j];
M6[0]=(M5[0]+M5[2])*13;
M6[1]=(M5[0]-M5[2])*13;
M6[2]= M5[1]*7 -M5[3]*17;
M6[3]= M5[1]*17+M5[3]*7;
for (i=0;i<2;i++)
{
i1=3-i;
M4[i][j]= M6[i]+M6[i1];
M4[i1][j]=M6[i]-M6[i1];
}
}
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
M5[j]=M4[i][j];
M6[0]=(M5[0]+M5[2])*13;
M6[1]=(M5[0]-M5[2])*13;
M6[2]= M5[1]*7 -M5[3]*17;
M6[3]= M5[1]*17+M5[3]*7;
for (j=0;j<2;j++)
{
j1=3-j;
M0[0][i][0][j] = ((M6[j]+M6[j1])/8) *JQ[quant_set][1];
M0[0][i][0][j1]= ((M6[j]-M6[j1])/8) *JQ[quant_set][1];
}
}
for (j=0;j<4;j++)
{
for (i=0;i<4;i++)
{
M0[0][i][0][j] = 3 * M0[0][i][0][j]/256;
}
}
/* AC invers trans/quant for MB */
img->kac=0;
for (jj=0;jj<4;jj++)
{
for (ii=0;ii<4;ii++)
{
run=-1;
scan_pos=0;
#ifndef NO_RDQUANT
for (coeff_ctr=1;coeff_ctr<16;coeff_ctr++) /* set in AC coeff */
{
i=SNGL_SCAN[coeff_ctr][0];
j=SNGL_SCAN[coeff_ctr][1];
coeff[coeff_ctr-1]=M0[i][ii][j][jj];
}
rd_quant(QUANT_LUMA_AC,coeff);
for (coeff_ctr=1;coeff_ctr<16;coeff_ctr++) /* set in AC coeff */
{
i=SNGL_SCAN[coeff_ctr][0];
j=SNGL_SCAN[coeff_ctr][1];
run++;
level=abs(coeff[coeff_ctr-1]);
if (level != 0)
{
img->kac=1;
img->cof[ii][jj][scan_pos][0][0]=sign(level,M0[i][ii][j][jj]);
img->cof[ii][jj][scan_pos][1][0]=run;
++scan_pos;
run=-1;
}
M0[i][ii][j][jj]=sign(level*JQ[quant_set][1],M0[i][ii][j][jj]);
}
img->cof[ii][jj][scan_pos][0][0]=0;
#endif
#ifdef NO_RDQUANT
for (coeff_ctr=1;coeff_ctr<16;coeff_ctr++) /* set in AC coeff */
{
i=SNGL_SCAN[coeff_ctr][0];
j=SNGL_SCAN[coeff_ctr][1];
run++;
level= ( abs( M0[i][ii][j][jj]) * JQ[quant_set][0]+qp_const)/JQQ1;
if (level != 0)
{
img->kac=1;
img->cof[ii][jj][scan_pos][0][0]=sign(level,M0[i][ii][j][jj]);
img->cof[ii][jj][scan_pos][1][0]=run;
++scan_pos;
run=-1;
}
M0[i][ii][j][jj]=sign(level*JQ[quant_set][1],M0[i][ii][j][jj]);
}
img->cof[ii][jj][scan_pos][0][0]=0;
#endif
/* IDCT horizontal */
for (j=0;j<4;j++)
{
for (i=0;i<4;i++)
{
M5[i]=M0[i][ii][j][jj];
}
M6[0]=(M5[0]+M5[2])*13;
M6[1]=(M5[0]-M5[2])*13;
M6[2]=M5[1]*7 -M5[3]*17;
M6[3]=M5[1]*17+M5[3]*7;
for (i=0;i<2;i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -