📄 image.c
字号:
/*!
************************************************************************
* \brief
* write the encoding mode and motion vectors of current
* MB to the buffer of the error concealment module.
************************************************************************
*/
void ercWriteMBMODEandMV(Macroblock *currMB, ImageParameters *img,struct inp_par *inp)
{
extern objectBuffer_t *erc_object_list;
int i, ii, jj, currMBNum = img->current_mb_nr;
int mbx = xPosMB(currMBNum,dec_picture->size_x), mby = yPosMB(currMBNum,dec_picture->size_x);
objectBuffer_t *currRegion, *pRegion;
short*** mv;
currRegion = erc_object_list + (currMBNum<<2);
if(img->type != B_SLICE) //non-B frame
{
for (i=0; i<4; i++)
{
pRegion = currRegion + i;
pRegion->regionMode = (currMB->mb_type ==I16MB ? REGMODE_INTRA :
currMB->b8mode[i]==IBLOCK ? REGMODE_INTRA_8x8 :
currMB->b8mode[i]==0 ? REGMODE_INTER_COPY :
currMB->b8mode[i]==1 ? REGMODE_INTER_PRED : REGMODE_INTER_PRED_8x8);
if (currMB->b8mode[i]==0 || currMB->b8mode[i]==IBLOCK) // INTRA OR COPY
{
pRegion->mv[0] = 0;
pRegion->mv[1] = 0;
pRegion->mv[2] = 0;
}
else
{
ii = 4*mbx + (i & 0x01)*2;// + BLOCK_SIZE;
jj = 4*mby + (i >> 1 )*2;
if (currMB->b8mode[i]>=5 && currMB->b8mode[i]<=7) // SMALL BLOCKS
{
pRegion->mv[0] = (dec_picture->motion.mv[LIST_0][jj][ii][0] + dec_picture->motion.mv[LIST_0][jj][ii+1][0] + dec_picture->motion.mv[LIST_0][jj+1][ii][0] + dec_picture->motion.mv[LIST_0][jj+1][ii+1][0] + 2)/4;
pRegion->mv[1] = (dec_picture->motion.mv[LIST_0][jj][ii][1] + dec_picture->motion.mv[LIST_0][jj][ii+1][1] + dec_picture->motion.mv[LIST_0][jj+1][ii][1] + dec_picture->motion.mv[LIST_0][jj+1][ii+1][1] + 2)/4;
}
else // 16x16, 16x8, 8x16, 8x8
{
pRegion->mv[0] = dec_picture->motion.mv[LIST_0][jj][ii][0];
pRegion->mv[1] = dec_picture->motion.mv[LIST_0][jj][ii][1];
// pRegion->mv[0] = dec_picture->motion.mv[LIST_0][4*mby+(i/2)*2][4*mbx+(i%2)*2+BLOCK_SIZE][0];
// pRegion->mv[1] = dec_picture->motion.mv[LIST_0][4*mby+(i/2)*2][4*mbx+(i%2)*2+BLOCK_SIZE][1];
}
erc_mvperMB += iabs(pRegion->mv[0]) + iabs(pRegion->mv[1]);
pRegion->mv[2] = dec_picture->motion.ref_idx[LIST_0][jj][ii];
}
}
}
else //B-frame
{
for (i=0; i<4; i++)
{
ii = 4*mbx + (i%2)*2;// + BLOCK_SIZE;
jj = 4*mby + (i/2)*2;
pRegion = currRegion + i;
pRegion->regionMode = (currMB->mb_type ==I16MB ? REGMODE_INTRA :
currMB->b8mode[i]==IBLOCK ? REGMODE_INTRA_8x8 : REGMODE_INTER_PRED_8x8);
if (currMB->mb_type==I16MB || currMB->b8mode[i]==IBLOCK) // INTRA
{
pRegion->mv[0] = 0;
pRegion->mv[1] = 0;
pRegion->mv[2] = 0;
}
else
{
int idx = (dec_picture->motion.ref_idx[0][jj][ii]<0)?1:0;
// int idx = (currMB->b8mode[i]==0 && currMB->b8pdir[i]==2 ? LIST_0 : currMB->b8pdir[i]==1 ? LIST_1 : LIST_0);
// int idx = currMB->b8pdir[i]==0 ? LIST_0 : LIST_1;
mv = dec_picture->motion.mv[idx];
pRegion->mv[0] = (mv[jj][ii][0] + mv[jj][ii+1][0] + mv[jj+1][ii][0] + mv[jj+1][ii+1][0] + 2)/4;
pRegion->mv[1] = (mv[jj][ii][1] + mv[jj][ii+1][1] + mv[jj+1][ii][1] + mv[jj+1][ii+1][1] + 2)/4;
erc_mvperMB += iabs(pRegion->mv[0]) + iabs(pRegion->mv[1]);
pRegion->mv[2] = (dec_picture->motion.ref_idx[idx][jj][ii]);
/*
if (currMB->b8pdir[i]==0 || (currMB->b8pdir[i]==2 && currMB->b8mode[i]!=0)) // forward or bidirect
{
pRegion->mv[2] = (dec_picture->motion.ref_idx[LIST_0][jj][ii]);
///???? is it right, not only "img->fw_refFrArr[jj][ii-4]"
}
else
{
pRegion->mv[2] = (dec_picture->motion.ref_idx[LIST_1][jj][ii]);
// pRegion->mv[2] = 0;
}
*/
}
}
}
}
/*!
************************************************************************
* \brief
* set defaults for old_slice
* NAL unit of a picture"
************************************************************************
*/
void init_old_slice(OldSliceParams *p_old_slice)
{
p_old_slice->field_pic_flag = 0;
p_old_slice->pps_id = INT_MAX;
p_old_slice->frame_num = INT_MAX;
p_old_slice->nal_ref_idc = INT_MAX;
p_old_slice->idr_flag = FALSE;
p_old_slice->pic_oder_cnt_lsb = UINT_MAX;
p_old_slice->delta_pic_oder_cnt_bottom = INT_MAX;
p_old_slice->delta_pic_order_cnt[0] = INT_MAX;
p_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(Slice *currSlice, OldSliceParams *p_old_slice)
{
p_old_slice->pps_id = currSlice->pic_parameter_set_id;
p_old_slice->frame_num = img->frame_num;
p_old_slice->field_pic_flag = img->field_pic_flag;
if(img->field_pic_flag)
{
p_old_slice->bottom_field_flag = img->bottom_field_flag;
}
p_old_slice->nal_ref_idc = img->nal_reference_idc;
p_old_slice->idr_flag = img->idr_flag;
if (img->idr_flag)
{
p_old_slice->idr_pic_id = img->idr_pic_id;
}
if (active_sps->pic_order_cnt_type == 0)
{
p_old_slice->pic_oder_cnt_lsb = img->pic_order_cnt_lsb;
p_old_slice->delta_pic_oder_cnt_bottom = img->delta_pic_order_cnt_bottom;
}
if (active_sps->pic_order_cnt_type == 1)
{
p_old_slice->delta_pic_order_cnt[0] = img->delta_pic_order_cnt[0];
p_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(StorablePicture *dec_picture, Slice *currSlice, OldSliceParams *p_old_slice)
{
int result=0;
result |= (NULL==dec_picture);
result |= (p_old_slice->pps_id != currSlice->pic_parameter_set_id);
result |= (p_old_slice->frame_num != img->frame_num);
result |= (p_old_slice->field_pic_flag != img->field_pic_flag);
if(img->field_pic_flag && p_old_slice->field_pic_flag)
{
result |= (p_old_slice->bottom_field_flag != img->bottom_field_flag);
}
result |= (p_old_slice->nal_ref_idc != img->nal_reference_idc) && ((p_old_slice->nal_ref_idc == 0) || (img->nal_reference_idc == 0));
result |= ( p_old_slice->idr_flag != img->idr_flag);
if (img->idr_flag && p_old_slice->idr_flag)
{
result |= (p_old_slice->idr_pic_id != img->idr_pic_id);
}
if (active_sps->pic_order_cnt_type == 0)
{
result |= (p_old_slice->pic_oder_cnt_lsb != img->pic_order_cnt_lsb);
result |= (p_old_slice->delta_pic_oder_cnt_bottom != img->delta_pic_order_cnt_bottom);
}
if (active_sps->pic_order_cnt_type == 1)
{
result |= (p_old_slice->delta_pic_order_cnt[0] != img->delta_pic_order_cnt[0]);
result |= (p_old_slice->delta_pic_order_cnt[1] != img->delta_pic_order_cnt[1]);
}
return result;
}
/*!
************************************************************************
* \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;
}
/*!
************************************************************************
* \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
}
/*!
************************************************************************
* \brief
* decodes one slice
************************************************************************
*/
void decode_one_slice(ImageParameters *img, Slice *currSlice, 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, currSlice, 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(currSlice, &old_slice);
//reset_ec_flags();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -