📄 block.c
字号:
}
}
}
break;
case HOR_PRED_8:
if (!left_avail[0] || !left_avail[1])
error("unexpected HOR_PRED_8 chroma intra prediction mode",-1);
for (j=0;j<2;j++)
{
joff=j*cr_MB_y/2;
for(i=0;i<2;i++)
{
ioff=i*cr_MB_x/2;
for (jj=0; jj<cr_MB_y/2; jj++)
{
pred = imgUV[uv][left[1+jj+joff].pos_y][left[1+jj+joff].pos_x];
for (ii=0; ii<cr_MB_x/2; ii++)
img->mpr[ii+ioff][jj+joff]=pred;
}
}
}
break;
case VERT_PRED_8:
if (!up_avail)
error("unexpected VERT_PRED_8 chroma intra prediction mode",-1);
for (j=0;j<2;j++)
{
joff=j*cr_MB_y/2;
for(i=0;i<2;i++)
{
ioff=i*cr_MB_x/2;
for (ii=0; ii<cr_MB_x/2; ii++)
{
pred = imgUV[uv][up.pos_y][up.pos_x+ii+ioff];
for (jj=0; jj<cr_MB_y/2; jj++)
img->mpr[ii+ioff][jj+joff]=pred;
}
}
}
break;
default:
error("illegal chroma intra prediction mode", 600);
break;
}
}
}
/*!
***********************************************************************
* \brief
* Inverse 4x4 transformation, transforms cof to m7
***********************************************************************
*/
void itrans(struct img_par *img, //!< image parameters
int ioff, //!< index to 4x4 block
int joff, //!<
int i0, //!<
int j0,
int chroma) // D.Birinov SAMSUNG AIT
{
int i,j,i1,j1;
int m5[4];
int m6[4];
Boolean lossless_qpprime = ((img->qp + img->bitdepth_luma_qp_scale)==0 && img->lossless_qpprime_flag==1); // S.SUN 06072004
// Residue Color Transform
int residue_transform_flag = img->residue_transform_flag;// D.BIRINOV SAMSUNG AIT
// horizontal
for (j=0;j<BLOCK_SIZE && !lossless_qpprime;j++) // S.SUN 06072004
{
for (i=0;i<BLOCK_SIZE;i++)
{
m5[i]=img->cof[i0][j0][i][j];
}
m6[0]=(m5[0]+m5[2]);
m6[1]=(m5[0]-m5[2]);
m6[2]=(m5[1]>>1)-m5[3];
m6[3]=m5[1]+(m5[3]>>1);
for (i=0;i<2;i++)
{
i1=3-i;
img->m7[i][j]=m6[i]+m6[i1];
img->m7[i1][j]=m6[i]-m6[i1];
}
}
// vertical
for (i=0;i<BLOCK_SIZE && !lossless_qpprime;i++) // S.SUN 06072004
{
for (j=0;j<BLOCK_SIZE;j++)
m5[j]=img->m7[i][j];
m6[0]=(m5[0]+m5[2]);
m6[1]=(m5[0]-m5[2]);
m6[2]=(m5[1]>>1)-m5[3];
m6[3]=m5[1]+(m5[3]>>1);
for (j=0;j<2;j++)
{
j1=3-j;
// Residue Color Transform
if(!residue_transform_flag){
if(!chroma){
img->m7[i][j] =max(0,min(img->max_imgpel_value,(m6[j]+m6[j1]+((long)img->mpr[i+ioff][j+joff] <<DQ_BITS)+DQ_ROUND)>>DQ_BITS));
img->m7[i][j1]=max(0,min(img->max_imgpel_value,(m6[j]-m6[j1]+((long)img->mpr[i+ioff][j1+joff]<<DQ_BITS)+DQ_ROUND)>>DQ_BITS));
} else {
img->m7[i][j] =max(0,min(img->max_imgpel_value_uv,(m6[j]+m6[j1]+((long)img->mpr[i+ioff][j+joff] <<DQ_BITS)+DQ_ROUND)>>DQ_BITS));
img->m7[i][j1]=max(0,min(img->max_imgpel_value_uv,(m6[j]-m6[j1]+((long)img->mpr[i+ioff][j1+joff]<<DQ_BITS)+DQ_ROUND)>>DQ_BITS));
}
}
else{
img->m7[i][j] =(m6[j]+m6[j1]+DQ_ROUND)>>DQ_BITS;
img->m7[i][j1]=(m6[j]-m6[j1]+DQ_ROUND)>>DQ_BITS;
}// D.BIRINOV SAMSUNG AIT
}
}
// Residue Color Transform
if(!residue_transform_flag){
for (i=0;i<BLOCK_SIZE && lossless_qpprime;i++) // S.SUN 06072004
for (j=0;j<BLOCK_SIZE;j++)
if(!chroma)
img->m7[i][j] = max(0,min(img->max_imgpel_value,img->cof[i0][j0][i][j]+(long)img->mpr[i+ioff][j+joff]));
else
img->m7[i][j] = max(0,min(img->max_imgpel_value_uv,img->cof[i0][j0][i][j]+(long)img->mpr[i+ioff][j+joff]));
}
else{
for (i=0;i<BLOCK_SIZE && lossless_qpprime;i++)
for (j=0;j<BLOCK_SIZE;j++)
img->m7[i][j] = img->cof[i0][j0][i][j];
}// D.BIRINOV SAMSUNG AIT
}
/*!
************************************************************************
* \brief
* For mapping the q-matrix to the active id and calculate quantisation values
*
* \para Input:
* pps, sps
*
* \para Output:
* none
************************************************************************
*/
void AssignQuantParam(pic_parameter_set_rbsp_t* pps, seq_parameter_set_rbsp_t* sps)
{
int i;
// HB changes start
if(!pps->pic_scaling_matrix_present_flag && !sps->seq_scaling_matrix_present_flag)
{
for(i=0; i<8; i++)
qmatrix[i] = (i<6) ? quant_org:quant8_org;
}
else
{
if(sps->seq_scaling_matrix_present_flag) // check sps first
{
for(i=0; i<8; i++)
{
if(i<6)
{
if(!sps->seq_scaling_list_present_flag[i]) // fall-back rule A
{
if((i==0) || (i==3))
qmatrix[i] = (i==0) ? quant_intra_default:quant_inter_default;
else
qmatrix[i] = qmatrix[i-1];
}
else
{
if(sps->UseDefaultScalingMatrix4x4Flag[i])
qmatrix[i] = (i<3) ? quant_intra_default:quant_inter_default;
else
qmatrix[i] = sps->ScalingList4x4[i];
}
}
else
{
if(!sps->seq_scaling_list_present_flag[i] || sps->UseDefaultScalingMatrix8x8Flag[i-6]) // fall-back rule A
qmatrix[i] = (i==6) ? quant8_intra_default:quant8_inter_default;
else
qmatrix[i] = sps->ScalingList8x8[i-6];
}
}
}
if(pps->pic_scaling_matrix_present_flag) // then check pps
{
for(i=0; i<8; i++)
{
if(i<6)
{
if(!pps->pic_scaling_list_present_flag[i]) // fall-back rule B
{
if((i==0) || (i==3))
{
if(!sps->seq_scaling_matrix_present_flag)
qmatrix[i] = (i==0) ? quant_intra_default:quant_inter_default;
}
else
qmatrix[i] = qmatrix[i-1];
}
else
{
if(pps->UseDefaultScalingMatrix4x4Flag[i])
qmatrix[i] = (i<3) ? quant_intra_default:quant_inter_default;
else
qmatrix[i] = pps->ScalingList4x4[i];
}
}
else
{
if(!pps->pic_scaling_list_present_flag[i]) // fall-back rule B
{
if(!sps->seq_scaling_matrix_present_flag)
qmatrix[i] = (i==6) ? quant8_intra_default:quant8_inter_default;
}
else if(pps->UseDefaultScalingMatrix8x8Flag[i-6])
qmatrix[i] = (i==6) ? quant8_intra_default:quant8_inter_default;
else
qmatrix[i] = pps->ScalingList8x8[i-6];
}
}
}
}
// HB changes end
CalculateQuantParam();
if(pps->transform_8x8_mode_flag)
CalculateQuant8Param();
}
/*!
************************************************************************
* \brief
* For calculating the quantisation values at frame level
*
* \para Input:
* none
*
* \para Output:
* none
************************************************************************
*/
void CalculateQuantParam(void)
{
int i, j, k, temp;
for(k=0; k<6; k++)
for(j=0; j<4; j++)
for(i=0; i<4; i++)
{
temp = (i<<2)+j; // HB 10062004
InvLevelScale4x4Luma_Intra[k][j][i] = dequant_coef[k][j][i]*qmatrix[0][temp];
InvLevelScale4x4Chroma_Intra[0][k][j][i] = dequant_coef[k][j][i]*qmatrix[1][temp];
InvLevelScale4x4Chroma_Intra[1][k][j][i] = dequant_coef[k][j][i]*qmatrix[2][temp];
InvLevelScale4x4Luma_Inter[k][j][i] = dequant_coef[k][j][i]*qmatrix[3][temp];
InvLevelScale4x4Chroma_Inter[0][k][j][i] = dequant_coef[k][j][i]*qmatrix[4][temp];
InvLevelScale4x4Chroma_Inter[1][k][j][i] = dequant_coef[k][j][i]*qmatrix[5][temp];
}
}
/*!
***********************************************************************
* \brief
* invers transform
***********************************************************************
*/
void itrans_2(
struct img_par *img) //!< image parameters
{
int i,j,i1,j1;
int M5[4];
int M6[4];
int qp_per = (img->qp + img->bitdepth_luma_qp_scale - MIN_QP)/6;
int qp_rem = (img->qp + img->bitdepth_luma_qp_scale - MIN_QP)%6;
//int intra = IS_INTRA (&img->mb_data[img->current_mb_nr]); // HB 10062004
int qp_const = 1<<(3-qp_per);
// horizontal
for (j=0;j<4;j++)
{
for (i=0;i<4;i++)
M5[i]=img->cof[i][j][0][0];
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;
img->cof[i ][j][0][0]= M6[i]+M6[i1];
img->cof[i1][j][0][0]=M6[i]-M6[i1];
}
}
// vertical
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
M5[j]=img->cof[i][j][0][0];
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;
// HB 10062004 start
if(qp_per<4)
{
img->cof[i][j][0][0] =((((M6[j]+M6[j1])*InvLevelScale4x4Luma_Intra[qp_rem][0][0]+qp_const)>>(4-qp_per))+2)>>2;
img->cof[i][j1][0][0]=((((M6[j]-M6[j1])*InvLevelScale4x4Luma_Intra[qp_rem][0][0]+qp_const)>>(4-qp_per))+2)>>2;
}
else
{
img->cof[i][j][0][0] =((((M6[j]+M6[j1])*InvLevelScale4x4Luma_Intra[qp_rem][0][0])<<(qp_per-4))+2)>>2;
img->cof[i][j1][0][0]=((((M6[j]-M6[j1])*InvLevelScale4x4Luma_Intra[qp_rem][0][0])<<(qp_per-4))+2)>>2;
}
// HB 10062004 end
}
}
}
void itrans_sp(struct img_par *img, //!< image parameters
int ioff, //!< index to 4x4 block
int joff, //!<
int i0, //!<
int j0) //!<
{
int i,j,i1,j1;
int m5[4];
int m6[4];
int predicted_block[BLOCK_SIZE][BLOCK_SIZE],ilev;
int qp_per = (img->qp-MIN_QP)/6;
int qp_rem = (img->qp-MIN_QP)%6;
int q_bits = Q_BITS+qp_per;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -