📄 image.c
字号:
//old_slice.nal_ref_idc = INT_MAX;
old_slice.nal_ref_idc = 4;
old_slice.idr_flag = 0;
//old_slice.pic_oder_cnt_lsb = UINT_MAX;
old_slice.pic_oder_cnt_lsb = 500;
//old_slice.delta_pic_oder_cnt_bottom = INT_MAX;
old_slice.delta_pic_oder_cnt_bottom = 0;
// old_slice.delta_pic_order_cnt[0] = INT_MAX;
// old_slice.delta_pic_order_cnt[1] = INT_MAX;
}
/*!
************************************************************************
* \brief
* save slice parameters that are needed for checking of "first VCL
* NAL unit of a picture"
************************************************************************
*/
void exit_slice()
{
old_slice.pps_id = img->currentSlice->pic_parameter_set_id;
old_slice.frame_num = img->frame_num;
old_slice.field_pic_flag = img->field_pic_flag;
/*
if(img->field_pic_flag)
{
old_slice.bottom_field_flag = img->bottom_field_flag;
}
*/
old_slice.nal_ref_idc = img->nal_reference_idc;
old_slice.idr_flag = img->idr_flag;
if (img->idr_flag)
{
old_slice.idr_pic_id = img->idr_pic_id;
}
if (active_sps->pic_order_cnt_type == 0)
{
old_slice.pic_oder_cnt_lsb = img->pic_order_cnt_lsb;
old_slice.delta_pic_oder_cnt_bottom = img->delta_pic_order_cnt_bottom;
}
/*
if (active_sps->pic_order_cnt_type == 1)
{
old_slice.delta_pic_order_cnt[0] = img->delta_pic_order_cnt[0];
old_slice.delta_pic_order_cnt[1] = img->delta_pic_order_cnt[1];
}*/
}
/*!
************************************************************************
* \brief
* detect if current slice is "first VCL NAL unit of a picture"
************************************************************************
*/
int is_new_picture()
{
int result=0;
result |= (old_slice.pps_id != img->currentSlice->pic_parameter_set_id);
result |= (old_slice.frame_num != img->frame_num);
result |= (old_slice.field_pic_flag != img->field_pic_flag);
/*
if(img->field_pic_flag && old_slice.field_pic_flag)
{
result |= (old_slice.bottom_field_flag != img->bottom_field_flag);
}
*/
result |= (old_slice.nal_ref_idc != img->nal_reference_idc);
result |= ( old_slice.idr_flag != img->idr_flag);
/*
if (img->idr_flag && old_slice.idr_flag)
{
result |= (old_slice.idr_pic_id != img->idr_pic_id);
}
*/
if (active_sps->pic_order_cnt_type == 0)
{
result |= (old_slice.pic_oder_cnt_lsb != img->pic_order_cnt_lsb);
result |= (old_slice.delta_pic_oder_cnt_bottom != img->delta_pic_order_cnt_bottom);
}
/*
if (active_sps->pic_order_cnt_type == 1)
{
result |= (old_slice.delta_pic_order_cnt[0] != img->delta_pic_order_cnt[0]);
result |= (old_slice.delta_pic_order_cnt[1] != img->delta_pic_order_cnt[1]);
}
*/
return result;
}
/*!
************************************************************************
* \brief
* decodes one slice
************************************************************************
*/
void decode_one_slice(struct img_par *img,struct inp_par *inp)
{
Boolean end_of_slice = FALSE;
int read_flag;
img->cod_counter=-1;
set_ref_pic_num();//zsj 130506参考帧设置
/*
if (img->type == B_SLICE)
compute_colocated(Co_located, listX);// Compute co-located motion info
*/
//reset_ec_flags();
while (end_of_slice == FALSE) // loop over macroblocks
{
#if TRACE
fprintf(p_trace,"\n*********** POC: %i (I/P) MB: %i Slice: %i Type %d **********\n", img->ThisPOC, img->current_mb_nr, img->current_slice_nr, img->type);
#endif
// Initializes the current macroblock
start_macroblock(img,inp, img->current_mb_nr);//初始化当前mb
// Get the syntax elements from the NAL
read_flag = read_one_macroblock(img,inp);//读语法元素从NAL中 140506zsj
decode_one_macroblock(img,inp);///解码一个宏块
/*
if(img->MbaffFrameFlag && dec_picture->mb_field[img->current_mb_nr])/// field macroblock indicator//
{
img->num_ref_idx_l0_active >>= 1;
img->num_ref_idx_l1_active >>= 1;
}
*/
ercWriteMBMODEandMV(img,inp);/* * write the encoding mode and motion vectors of current
* MB to the buffer of the error concealment module.*/
end_of_slice=exit_macroblock(img,inp,(!img->MbaffFrameFlag||img->current_mb_nr%2));
}
exit_slice();
//reset_ec_flags();
}
void decode_slice(struct img_par *img,struct inp_par *inp, int current_header)
{
Slice *currSlice = img->currentSlice;
//pic_parameter_set_rbsp_t active_pps
/*
if (active_pps->entropy_coding_mode_flag)//熵编码标志130506 zsj
{
init_contexts (img);//初始化img结构中的 img->currentSlice->mot_ctx img->currentSlice->tex_ctx;; 130506 zsj
cabac_new_slice();
}
*/
/*
if ( (active_pps->weighted_bipred_idc > 0 && (img->type == B_SLICE)) || (active_pps->weighted_pred_flag && img->type !=I_SLICE))
//加权预测标志为1并且img类型不为I_SLICE 130506 zsj
//或者双向加权预测的index大于0
fill_wp_params(img);//填充加权预测的参数130506 zsj
*/
//printf("frame picture %d %d %d\n",img->structure,img->ThisPOC,img->direct_spatial_mv_pred_flag);
// decode main slice information
if ((current_header == SOP || current_header == SOS) && currSlice->ei_flag == 0)//通过current_header来解码 zsj130506
// currSlice->ei_flag =0 if the partArr[0] contains valid information
decode_one_slice(img,inp);//解码图像zsj130506
// setMB-Nr in case this slice was lost
// if(currSlice->ei_flag)
// img->current_mb_nr = currSlice->last_mb_nr + 1;
}
/*!
************************************************************************
* \brief
* Prepare field and frame buffer after frame decoding
************************************************************************
*/
/*
void frame_postprocessing(struct img_par *img, struct inp_par *inp)
{
}
*/
/*!
************************************************************************
* \brief
* Prepare field and frame buffer after field decoding
************************************************************************
*/
/*
void field_postprocessing(struct img_par *img, struct inp_par *inp)
{
img->number /= 2;
}
*/
/*
void reset_wp_params(struct img_par *img)
{
int i,comp;
int log_weight_denom;
for (i=0; i<MAX_REFERENCE_PICTURES; i++)
{
for (comp=0; comp<3; comp++)
{
log_weight_denom = (comp == 0) ? img->luma_log2_weight_denom : img->chroma_log2_weight_denom;
img->wp_weight[0][i][comp] = 1<<log_weight_denom;
img->wp_weight[1][i][comp] = 1<<log_weight_denom;
}
}
}
void fill_wp_params(struct img_par *img)
{
int i, j, k;
int comp;
int log_weight_denom;
int tb, td;
int bframe = (img->type==B_SLICE);
int max_bwd_ref, max_fwd_ref;
int tx,DistScaleFactor;
max_fwd_ref = img->num_ref_idx_l0_active;
max_bwd_ref = img->num_ref_idx_l1_active;
if (active_pps->weighted_bipred_idc == 2 && bframe)
{
img->luma_log2_weight_denom = 5;
img->chroma_log2_weight_denom = 5;
img->wp_round_luma = 16;
img->wp_round_chroma = 16;
for (i=0; i<MAX_REFERENCE_PICTURES; i++)
{
for (comp=0; comp<3; comp++)
{
log_weight_denom = (comp == 0) ? img->luma_log2_weight_denom : img->chroma_log2_weight_denom;
img->wp_weight[0][i][comp] = 1<<log_weight_denom;
img->wp_weight[1][i][comp] = 1<<log_weight_denom;
img->wp_offset[0][i][comp] = 0;
img->wp_offset[1][i][comp] = 0;
}
}
}
if (bframe)
{
for (i=0; i<max_fwd_ref; i++)
{
for (j=0; j<max_bwd_ref; j++)
{
for (comp = 0; comp<3; comp++)
{
log_weight_denom = (comp == 0) ? img->luma_log2_weight_denom : img->chroma_log2_weight_denom;
if (active_pps->weighted_bipred_idc == 1)
{
img->wbp_weight[0][i][j][comp] = img->wp_weight[0][i][comp];
img->wbp_weight[1][i][j][comp] = img->wp_weight[1][j][comp];
}
else if (active_pps->weighted_bipred_idc == 2)
{
td = Clip3(-128,127,listX[LIST_1][j]->poc - listX[LIST_0][i]->poc);
if (td == 0 || listX[LIST_1][j]->is_long_term || listX[LIST_0][i]->is_long_term)
{
img->wbp_weight[0][i][j][comp] = 32;
img->wbp_weight[1][i][j][comp] = 32;
}
else
{
tb = Clip3(-128,127,img->ThisPOC - listX[LIST_0][i]->poc);
tx = (16384 + abs(td/2))/td;
DistScaleFactor = Clip3(-1024, 1023, (tx*tb + 32 )>>6);
img->wbp_weight[1][i][j][comp] = DistScaleFactor >> 2;
img->wbp_weight[0][i][j][comp] = 64 - img->wbp_weight[1][i][j][comp];
if (img->wbp_weight[1][i][j][comp] < -64 || img->wbp_weight[1][i][j][comp] > 128)
{
img->wbp_weight[0][i][j][comp] = 32;
img->wbp_weight[1][i][j][comp] = 32;
img->wp_offset[0][i][comp] = 0;
img->wp_offset[1][i][comp] = 0;
}
}
}
}
}
}
}
if (bframe && img->MbaffFrameFlag)
{
for (i=0; i<2*max_fwd_ref; i++)
{
for (j=0; j<2*max_bwd_ref; j++)
{
for (comp = 0; comp<3; comp++)
{
for (k=2; k<6; k+=2)
{
img->wp_offset[k+0][i][comp] = img->wp_offset[0][i/2][comp];
img->wp_offset[k+1][i][comp] = img->wp_offset[1][i/2][comp];
log_weight_denom = (comp == 0) ? img->luma_log2_weight_denom : img->chroma_log2_weight_denom;
if (active_pps->weighted_bipred_idc == 1)
{
img->wbp_weight[k+0][i][j][comp] = img->wp_weight[0][i/2][comp];
img->wbp_weight[k+1][i][j][comp] = img->wp_weight[1][j/2][comp];
}
else if (active_pps->weighted_bipred_idc == 2)
{
td = Clip3(-128,127,listX[k+LIST_1][j]->poc - listX[k+LIST_0][i]->poc);
if (td == 0 || listX[k+LIST_1][j]->is_long_term || listX[k+LIST_0][i]->is_long_term)
{
img->wbp_weight[k+0][i][j][comp] = 32;
img->wbp_weight[k+1][i][j][comp] = 32;
}
else
{
tb = Clip3(-128,127,((k==2)?img->toppoc:img->bottompoc) - listX[k+LIST_0][i]->poc);
tx = (16384 + abs(td/2))/td;
DistScaleFactor = Clip3(-1024, 1023, (tx*tb + 32 )>>6);
img->wbp_weight[k+1][i][j][comp] = DistScaleFactor >> 2;
img->wbp_weight[k+0][i][j][comp] = 64 - img->wbp_weight[k+1][i][j][comp];
if (img->wbp_weight[k+1][i][j][comp] < -64 || img->wbp_weight[k+1][i][j][comp] > 128)
{
img->wbp_weight[k+1][i][j][comp] = 32;
img->wbp_weight[k+0][i][j][comp] = 32;
img->wp_offset[k+0][i][comp] = 0;
img->wp_offset[k+1][i][comp] = 0;
}
}
}
}
}
}
}
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -