📄 image.c
字号:
}
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(ImageParameters *img,struct inp_par *inp)
{
Boolean end_of_slice = FALSE;
Macroblock *currMB = NULL;
img->cod_counter=-1;
set_interpret_mb_mode(img->type);
if( IS_INDEPENDENT(img) )
{
change_plane_JV( img->colour_plane_id );
}
set_ref_pic_num();
if (img->type == B_SLICE)
{
if( IS_INDEPENDENT(img) )
{
compute_colocated_JV(Co_located, listX);
}
else
{
compute_colocated(Co_located, listX);
}
}
//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, &currMB);
// Get the syntax elements from the NAL
read_one_macroblock(img, currMB);
decode_one_macroblock(img, currMB, dec_picture);
if(img->MbaffFrameFlag && dec_picture->motion.mb_field[img->current_mb_nr])
{
img->num_ref_idx_l0_active >>= 1;
img->num_ref_idx_l1_active >>= 1;
}
ercWriteMBMODEandMV(currMB, img,inp);
end_of_slice=exit_macroblock(img,(!img->MbaffFrameFlag||img->current_mb_nr%2));
}
exit_slice();
//reset_ec_flags();
}
void decode_slice(ImageParameters *img,struct inp_par *inp, int current_header)
{
Slice *currSlice = img->currentSlice;
if (active_pps->entropy_coding_mode_flag)
{
init_contexts (img);
cabac_new_slice();
}
if ( (active_pps->weighted_bipred_idc > 0 && (img->type == B_SLICE)) || (active_pps->weighted_pred_flag && img->type !=I_SLICE))
fill_wp_params(img);
//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)
decode_one_slice(img,inp);
// 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(ImageParameters *img)
{
}
/*!
************************************************************************
* \brief
* Prepare field and frame buffer after field decoding
************************************************************************
*/
void field_postprocessing(ImageParameters *img)
{
img->number /= 2;
}
void reset_wp_params(ImageParameters *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(ImageParameters *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 = iClip3(-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 = iClip3(-128,127,img->ThisPOC - listX[LIST_0][i]->poc);
tx = (16384 + iabs(td/2))/td;
DistScaleFactor = iClip3(-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][j][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>>1][comp];
img->wp_offset[k+1][j][comp] = img->wp_offset[1][j>>1][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>>1][comp];
img->wbp_weight[k+1][i][j][comp] = img->wp_weight[1][j>>1][comp];
}
else if (active_pps->weighted_bipred_idc == 2)
{
td = iClip3(-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 = iClip3(-128,127,((k==2)?img->toppoc:img->bottompoc) - listX[k+LIST_0][i]->poc);
tx = (16384 + iabs(td/2))/td;
DistScaleFactor = iClip3(-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][j][comp] = 0;
}
}
}
}
}
}
}
}
}
/*!
************************************************************************
* \brief
* Error tracking: if current frame is lost or any reference frame of
* current frame is lost, current frame is incorrect.
************************************************************************
*/
void Error_tracking(void)
{
int i;
if(img->redundant_pic_cnt == 0)
{
Is_primary_correct = Is_redundant_correct = 1;
}
if(img->redundant_pic_cnt == 0 && img->type != I_SLICE)
{
for(i=0;i<img->num_ref_idx_l0_active;i++)
{
if(ref_flag[i] == 0) // any reference of primary slice is incorrect
{
Is_primary_correct = 0; // primary slice is incorrect
}
}
}
else if(img->redundant_pic_cnt != 0 && img->type != I_SLICE)
{
if(ref_flag[redundant_slice_ref_idx] == 0) // reference of redundant slice is incorrect
{
Is_redundant_correct = 0; // redundant slice is incorrect
}
}
}
/*!
************************************************************************
* \brief
* copy StorablePicture *src -> StorablePicture *dst
* for 4:4:4 Independent mode
************************************************************************
*/
void copy_dec_picture_JV( StorablePicture *dst, StorablePicture *src )
{
dst->top_poc = src->top_poc;
dst->bottom_poc = src->bottom_poc;
dst->frame_poc = src->frame_poc;
dst->qp = src->qp;
dst->slice_qp_delta = src->slice_qp_delta;
dst->chroma_qp_offset[0] = src->chroma_qp_offset[0];
dst->chroma_qp_offset[1] = src->chroma_qp_offset[1];
dst->poc = src->poc;
dst->slice_type = src->slice_type;
dst->used_for_reference = src->used_for_reference;
dst->idr_flag = src->idr_flag;
dst->no_output_of_prior_pics_flag = src->no_output_of_prior_pics_flag;
dst->long_term_reference_flag = src->long_term_reference_flag;
dst->adaptive_ref_pic_buffering_flag = src->adaptive_ref_pic_buffering_flag;
dst->dec_ref_pic_marking_buffer = src->dec_ref_pic_marking_buffer;
dst->MbaffFrameFlag = src->MbaffFrameFlag;
dst->PicWidthInMbs = src->PicWidthInMbs;
dst->pic_num = src->pic_num;
dst->frame_num = src->frame_num;
dst->recovery_frame = src->recovery_frame;
dst->coded_frame = src->coded_frame;
dst->chroma_format_idc = src->chroma_format_idc;
dst->frame_mbs_only_flag = src->frame_mbs_only_flag;
dst->frame_cropping_flag = src->frame_cropping_flag;
dst->frame_cropping_rect_left_offset = src->frame_cropping_rect_left_offset;
dst->frame_cropping_rect_right_offset = src->frame_cropping_rect_right_offset;
dst->frame_cropping_rect_top_offset = src->frame_cropping_rect_top_offset;
dst->frame_cropping_rect_bottom_offset = src->frame_cropping_rect_bottom_offset;
#if (ENABLE_OUTPUT_TONEMAPPING)
// store the necessary tone mapping sei into StorablePicture structure
dst->seiHasTone_mapping = src->seiHasTone_mapping;
dst->seiHasTone_mapping = src->seiHasTone_mapping;
dst->tone_mapping_model_id = src->tone_mapping_model_id;
dst->tonemapped_bit_depth = src->tonemapped_bit_depth;
if( src->tone_mapping_lut )
{
dst->tone_mapping_lut = malloc(sizeof(int)*(1<<seiToneMapping.coded_data_bit_depth));
if (NULL == dst->tone_mapping_lut)
{
no_mem_exit("copy_dec_picture_JV: tone_mapping_lut");
}
memcpy(dst->tone_mapping_lut, src->tone_mapping_lut, sizeof(imgpel)*(1<<seiToneMapping.coded_data_bit_depth));
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -