📄 block.c
字号:
left_avail &= left[i].available ? img->intra_block[left[i].mb_addr]: 0;
left_up_avail = left[0].available ? img->intra_block[left[0].mb_addr]: 0;
}
s1=s2=0;
// make DC prediction
for (i=0; i < MB_BLOCK_SIZE; i++)
{
if (up_avail)
s1 += imgY_pred[up.pos_y][up.pos_x+i]; // sum hor pix
if (left_avail)
s2 += imgY_pred[left[i+1].pos_y][left[i+1].pos_x]; // sum vert pix
}
if (up_avail && left_avail)
s0=(s1+s2+16)/(2*MB_BLOCK_SIZE); // no edge
if (!up_avail && left_avail)
s0=(s2+8)/MB_BLOCK_SIZE; // upper edge
if (up_avail && !left_avail)
s0=(s1+8)/MB_BLOCK_SIZE; // left edge
if (!up_avail && !left_avail)
s0=img->dc_pred_value; // top left corner, nothing to predict from
for (i=0; i < MB_BLOCK_SIZE; i++)
{
// vertical prediction
if (up_avail)
s[i][0]=imgY_pred[up.pos_y][up.pos_x+i];
// horizontal prediction
if (left_avail)
s[i][1]=imgY_pred[left[i+1].pos_y][left[i+1].pos_x];
}
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 (!up_avail || !left_avail || !left_up_avail) // edge
return;
// 16 bit integer plan pred
ih=0;
iv=0;
for (i=1;i<9;i++)
{
if (i<8)
ih += i*(imgY_pred[up.pos_y][up.pos_x+7+i] - imgY_pred[up.pos_y][up.pos_x+7-i]);
else
ih += i*(imgY_pred[up.pos_y][up.pos_x+7+i] - imgY_pred[left[0].pos_y][left[0].pos_x]);
iv += i*(imgY_pred[left[8+i].pos_y][left[8+i].pos_x] - imgY_pred[left[8-i].pos_y][left[8-i].pos_x]);
}
ib=(5*ih+32)>>6;
ic=(5*iv+32)>>6;
iaa=16*(imgY_pred[up.pos_y][up.pos_x+15]+imgY_pred[left[16].pos_y][left[16].pos_x]);
for (j=0;j< MB_BLOCK_SIZE;j++)
{
for (i=0;i< MB_BLOCK_SIZE;i++)
{
img->mprr_2[PLANE_16][j][i]=max(0,min((int)img->max_imgpel_value,(iaa+(i-7)*ib +(j-7)*ic + 16)/32));// store plane prediction
}
}
}
/*!
************************************************************************
* \brief
* For calculating the quantisation values at frame level
*
* \par Input:
* none
*
* \par Output:
* none
************************************************************************
*/
void CalculateQuantParam(void)
{
int i, j, k, temp;
int present[6];
int no_q_matrix=FALSE;
if(!active_sps->seq_scaling_matrix_present_flag && !active_pps->pic_scaling_matrix_present_flag) //set to no q-matrix
no_q_matrix=TRUE;
else
{
memset(present, 0, sizeof(int)*6);
if(active_sps->seq_scaling_matrix_present_flag)
for(i=0; i<6; i++)
present[i] = active_sps->seq_scaling_list_present_flag[i];
if(active_pps->pic_scaling_matrix_present_flag)
for(i=0; i<6; i++)
{
if((i==0) || (i==3))
present[i] |= active_pps->pic_scaling_list_present_flag[i];
else
present[i] = active_pps->pic_scaling_list_present_flag[i];
}
}
if(no_q_matrix==TRUE)
{
for(k=0; k<6; k++)
for(j=0; j<4; j++)
for(i=0; i<4; i++)
{
LevelScale4x4Luma_Intra[k][j][i] = quant_coef[k][j][i];
InvLevelScale4x4Luma_Intra[k][j][i] = dequant_coef[k][j][i]<<4;
LevelScale4x4Chroma_Intra[0][k][j][i] = quant_coef[k][j][i];
InvLevelScale4x4Chroma_Intra[0][k][j][i] = dequant_coef[k][j][i]<<4;
LevelScale4x4Chroma_Intra[1][k][j][i] = quant_coef[k][j][i];
InvLevelScale4x4Chroma_Intra[1][k][j][i] = dequant_coef[k][j][i]<<4;
LevelScale4x4Luma_Inter[k][j][i] = quant_coef[k][j][i];
InvLevelScale4x4Luma_Inter[k][j][i] = dequant_coef[k][j][i]<<4;
LevelScale4x4Chroma_Inter[0][k][j][i] = quant_coef[k][j][i];
InvLevelScale4x4Chroma_Inter[0][k][j][i] = dequant_coef[k][j][i]<<4;
LevelScale4x4Chroma_Inter[1][k][j][i] = quant_coef[k][j][i];
InvLevelScale4x4Chroma_Inter[1][k][j][i] = dequant_coef[k][j][i]<<4;
}
}
else
{
for(k=0; k<6; k++)
for(j=0; j<4; j++)
for(i=0; i<4; i++)
{
temp = (i<<2)+j;
if((!present[0]) || UseDefaultScalingMatrix4x4Flag[0])
{
LevelScale4x4Luma_Intra[k][j][i] = (quant_coef[k][j][i]<<4)/Quant_intra_default[temp];
InvLevelScale4x4Luma_Intra[k][j][i] = dequant_coef[k][j][i]*Quant_intra_default[temp];
}
else
{
LevelScale4x4Luma_Intra[k][j][i] = (quant_coef[k][j][i]<<4)/ScalingList4x4[0][temp];
InvLevelScale4x4Luma_Intra[k][j][i] = dequant_coef[k][j][i]*ScalingList4x4[0][temp];
}
if(!present[1])
{
LevelScale4x4Chroma_Intra[0][k][j][i] = LevelScale4x4Luma_Intra[k][j][i];
InvLevelScale4x4Chroma_Intra[0][k][j][i] = InvLevelScale4x4Luma_Intra[k][j][i];
}
else
{
LevelScale4x4Chroma_Intra[0][k][j][i] = (quant_coef[k][j][i]<<4)/(UseDefaultScalingMatrix4x4Flag[1] ? Quant_intra_default[temp]:ScalingList4x4[1][temp]);
InvLevelScale4x4Chroma_Intra[0][k][j][i] = dequant_coef[k][j][i]*(UseDefaultScalingMatrix4x4Flag[1] ? Quant_intra_default[temp]:ScalingList4x4[1][temp]);
}
if(!present[2])
{
LevelScale4x4Chroma_Intra[1][k][j][i] = LevelScale4x4Chroma_Intra[0][k][j][i];
InvLevelScale4x4Chroma_Intra[1][k][j][i] = InvLevelScale4x4Chroma_Intra[0][k][j][i];
}
else
{
LevelScale4x4Chroma_Intra[1][k][j][i] = (quant_coef[k][j][i]<<4)/(UseDefaultScalingMatrix4x4Flag[2] ? Quant_intra_default[temp]:ScalingList4x4[2][temp]);
InvLevelScale4x4Chroma_Intra[1][k][j][i] = dequant_coef[k][j][i]*(UseDefaultScalingMatrix4x4Flag[2] ? Quant_intra_default[temp]:ScalingList4x4[2][temp]);
}
if((!present[3]) || UseDefaultScalingMatrix4x4Flag[3])
{
LevelScale4x4Luma_Inter[k][j][i] = (quant_coef[k][j][i]<<4)/Quant_inter_default[temp];
InvLevelScale4x4Luma_Inter[k][j][i] = dequant_coef[k][j][i]*Quant_inter_default[temp];
}
else
{
LevelScale4x4Luma_Inter[k][j][i] = (quant_coef[k][j][i]<<4)/ScalingList4x4[3][temp];
InvLevelScale4x4Luma_Inter[k][j][i] = dequant_coef[k][j][i]*ScalingList4x4[3][temp];
}
if(!present[4])
{
LevelScale4x4Chroma_Inter[0][k][j][i] = LevelScale4x4Luma_Inter[k][j][i];
InvLevelScale4x4Chroma_Inter[0][k][j][i] = InvLevelScale4x4Luma_Inter[k][j][i];
}
else
{
LevelScale4x4Chroma_Inter[0][k][j][i] = (quant_coef[k][j][i]<<4)/(UseDefaultScalingMatrix4x4Flag[4] ? Quant_inter_default[temp]:ScalingList4x4[4][temp]);
InvLevelScale4x4Chroma_Inter[0][k][j][i] = dequant_coef[k][j][i]*(UseDefaultScalingMatrix4x4Flag[4] ? Quant_inter_default[temp]:ScalingList4x4[4][temp]);
}
if(!present[5])
{
LevelScale4x4Chroma_Inter[1][k][j][i] = LevelScale4x4Chroma_Inter[0][k][j][i];
InvLevelScale4x4Chroma_Inter[1][k][j][i] = InvLevelScale4x4Chroma_Inter[0][k][j][i];
}
else
{
LevelScale4x4Chroma_Inter[1][k][j][i] = (quant_coef[k][j][i]<<4)/(UseDefaultScalingMatrix4x4Flag[5] ? Quant_inter_default[temp]:ScalingList4x4[5][temp]);
InvLevelScale4x4Chroma_Inter[1][k][j][i] = dequant_coef[k][j][i]*(UseDefaultScalingMatrix4x4Flag[5] ? Quant_inter_default[temp]:ScalingList4x4[5][temp]);
}
}
}
}
/*!
************************************************************************
* \brief
* For new intra pred routines
*
* \par Input:
* Image par, 16x16 based intra mode
*
* \par Output:
* none
************************************************************************
*/
int dct_luma_16x16(int new_intra_mode)
{
int qp_const;
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];
int run,scan_pos,coeff_ctr,level;
int qp_per,qp_rem,q_bits;
int ac_coef = 0;
Macroblock *currMB = &img->mb_data[img->current_mb_nr];
int b8, b4;
int* DCLevel = img->cofDC[0][0];
int* DCRun = img->cofDC[0][1];
int* ACLevel;
int* ACRun;
Boolean lossless_qpprime = ((currMB->qp + img->bitdepth_luma_qp_scale)==0 && img->lossless_qpprime_flag==1);
qp_per = (currMB->qp + img->bitdepth_luma_qp_scale - MIN_QP)/6;
qp_rem = (currMB->qp + img->bitdepth_luma_qp_scale - MIN_QP)%6;
q_bits = Q_BITS+qp_per;
qp_const = (1<<q_bits)/3;
for (j=0;j<16;j++)
{
for (i=0;i<16;i++)
{
// Residue Color Transform
if(!img->residue_transform_flag)
M1[i][j]=imgY_org[img->opix_y+j][img->opix_x+i]-img->mprr_2[new_intra_mode][j][i];
else
M1[i][j]=img->m7[i][j];
M0[i%4][i/4][j%4][j/4]=M1[i][j];
}
}
for (jj=0;jj<4 && !lossless_qpprime;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];
M0[2][ii][j][jj]=M5[0]-M5[1];
M0[1][ii][j][jj]=M5[3]*2+M5[2];
M0[3][ii][j][jj]=M5[3]-M5[2]*2;
}
// 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];
M0[i][ii][2][jj]=M5[0]-M5[1];
M0[i][ii][1][jj]=M5[3]*2+M5[2];
M0[i][ii][3][jj]=M5[3] -M5[2]*2;
}
}
}
// pick out DC coeff
for (j=0;j<4;j++)
for (i=0;i<4;i++)
M4[i][j]= M0[0][i][0][j];
for (j=0;j<4 && !lossless_qpprime;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];
M4[2][j]=M5[0]-M5[1];
M4[1][j]=M5[3]+M5[2];
M4[3][j]=M5[3]-M5[2];
}
// vertical
for (i=0;i<4 && !lossless_qpprime;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])>>1;
M4[i][2]=(M5[0]-M5[1])>>1;
M4[i][1]=(M5[3]+M5[2])>>1;
M4[i][3]=(M5[3]-M5[2])>>1;
}
// quant
run=-1;
scan_pos=0;
for (coeff_ctr=0;coeff_ctr<16;coeff_ctr++)
{
if (img->field_picture || ( mb_adaptive && img->field_mode ))
{ // Alternate scan for field coding
i=FIELD_SCAN[coeff_ctr][0];
j=FIELD_SCAN[coeff_ctr][1];
}
else
{
i=SNGL_SCAN[coeff_ctr][0];
j=SNGL_SCAN[coeff_ctr][1];
}
run++;
if(lossless_qpprime)
level= abs(M4[i][j]);
else
level= (abs(M4[i][j]) * LevelScale4x4Luma_Intra[qp_rem][0][0] + (qp_const<<1)) >> (q_bits+1);
if (input->symbol_mode == UVLC && img->qp < 10)
{
if (level > CAVLC_LEVEL_LIMIT)
{
level = CAVLC_LEVEL_LIMIT;
}
}
if (level != 0)
{
DCLevel[scan_pos] = sign(level,M4[i][j]);
DCRun [scan_pos] = run;
++scan_pos;
run=-1;
}
if(!lossless_qpprime)
M4[i][j]=sign(level,M4[i][j]);
}
DCLevel[scan_pos]=0;
// invers DC transform
for (j=0;j<4 && !lossless_qpprime;j++)
{
for (i=0;i<4;i++)
M5[i]=M4[i][j];
M6[0]=M5[0]+M5[2];
M6[1]=M5[0]-M5[2];
M6[2]=M5[1]-M5[3];
M6[3]=M5[1]+M5[3];
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 && !lossless_qpprime;i++)
{
for (j=0;j<4;j++)
M5[j]=M4[i][j];
M6[0]=M5[0]+M5[2];
M6[1]=M5[0]-M5[2];
M6[2]=M5[1]-M5[3];
M6[3]=M5[1]+M5[3];
for (j=0;j<2;j++)
{
j1=3-j;
if(qp_per<6)
{
M0[0][i][0][j] = ((M6[j]+M6[j1])*InvLevelScale4x4Luma_Intra[qp_rem][0][0]+(1<<(5-qp_per)))>>(6-qp_per);
M0[0][i][0][j1] = ((M6[j]-M6[j1])*InvLevelScale4x4Luma_Intra[qp_rem][0][0]+(1<<(5-qp_per)))>>(6-qp_per);
}
else
{
M0[0][i][0][j] = ((M6[j]+M6[j1])*InvLevelScale4x4Luma_Intra[qp_rem][0][0])<<(qp_per-6);
M0[0][i][0][j1] = ((M6[j]-M6[j1])*InvLevelScale4x4Luma_Intra[qp_rem][0][0])<<(qp_per-6);
}
}
}
// AC inverse trans/quant for MB
for (jj=0;jj<4;jj++)
{
for (ii=0;ii<4;ii++)
{
run = -1;
scan_pos = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -