📄 image.c
字号:
sse_frame = frame->distortion.value[0] + frame->distortion.value[1] + frame->distortion.value[2];
//! all distrortions of a field picture are accumulated in the top field
sse_field = top->distortion.value[0] + top->distortion.value[1] + top->distortion.value[2];
bit_field = top->bits_per_picture + bot->bits_per_picture;
bit_frame = frame->bits_per_picture;
return decide_fld_frame (sse_frame, sse_field, bit_field, bit_frame, lambda_picture);
}
/*!
************************************************************************
* \brief
* Field Mode Buffer
************************************************************************
*/
static void field_mode_buffer (ImageParameters *img, InputParameters *params)
{
put_buffer_frame (img);
}
/*!
************************************************************************
* \brief
* Frame Mode Buffer
************************************************************************
*/
static void frame_mode_buffer (ImageParameters *img, InputParameters *params)
{
put_buffer_frame (img);
if ((params->PicInterlace != FRAME_CODING)||(params->MbInterlace != FRAME_CODING))
{
img->height = img->height / 2;
img->height_cr = img->height_cr / 2;
img->number *= 2;
img->gop_number = (img->number - img->start_frame_no);
put_buffer_top (img);
img->number++;
img->gop_number = (img->number - img->start_frame_no);
put_buffer_bot (img);
img->number /= 2; // reset the img->number to field
img->gop_number = (img->number - img->start_frame_no);
img->height = (params->output.height + img->auto_crop_bottom);
img->height_cr = img->height_cr_frame;
put_buffer_frame (img);
}
}
/*!
************************************************************************
* \brief
* mmco initializations should go here
************************************************************************
*/
static void init_dec_ref_pic_marking_buffer(void)
{
img->dec_ref_pic_marking_buffer=NULL;
}
/*!
************************************************************************
* \brief
* Initializes the parameters for a new frame
************************************************************************
*/
static void init_frame (ImageParameters *img)
{
int i, j;
img->current_mb_nr = 0;
img->current_slice_nr = 0;
stats->bit_slice = 0;
img->mb_y = img->mb_x = 0;
img->block_y = img->pix_y = img->pix_c_y = 0;
img->block_x = img->pix_x = img->block_c_x = img->pix_c_x = 0;
// The 'slice_nr' of each macroblock is set to -1 here, to guarantee the correct encoding
// with FMO (if no FMO, encoding is correct without following assignment),
// for which MBs may not be encoded with scan order
if( IS_INDEPENDENT(params) )
{
for( j=0; j<MAX_PLANE; j++ ){
for(i=0;i< ((int) (img->FrameSizeInMbs));i++)
img->mb_data_JV[j][i].slice_nr=-1;
}
}
else
{
for(i = 0; i < ((int) (img->FrameSizeInMbs)); i++)
img->mb_data[i].slice_nr = -1;
}
if (img->b_frame_to_code == 0)
{
//Rate control
if(!params->RCEnable) // without using rate control
{
if (img->type == I_SLICE)
{
//QP oscillation for secondary SP frames
if ((params->qp2start > 0 && img->frame_no >= params->qp2start && params->sp2_frame_indicator==0)||
( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ) && (params->sp2_frame_indicator==1)))
img->qp = params->qp[1][I_SLICE];
else
img->qp = params->qp[0][I_SLICE]; // set quant. parameter for I-frame
if (redundant_coding)
{
//!KS: hard code qp increment
img->qp = imin(img->qp + 5, 51);
}
}
else
{
//QP oscillation for secondary SP frames
if ((params->qp2start > 0 && img->frame_no >= params->qp2start && params->sp2_frame_indicator==0)||
( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ) && (params->sp2_frame_indicator==1)))
img->qp = params->qp[1][P_SLICE] + (img->nal_reference_idc ? 0 : params->DispPQPOffset);
else
img->qp = params->qp[0][P_SLICE] + (img->nal_reference_idc ? 0 : params->DispPQPOffset);
if (img->type == SP_SLICE)
{
if ( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ))
{
img->qp = params->qp[1][SP_SLICE];
img->qpsp = params->qpsp[1];
}
else
{
img->qp = params->qp[0][SP_SLICE];
img->qpsp = params->qpsp[0];
}
}
}
}
img->mb_y_intra = img->mb_y_upd; // img->mb_y_intra indicates which GOB to intra code for this frame
if (params->intra_upd > 0) // if error robustness, find next GOB to update
{
img->mb_y_upd = (img->frm_number / params->intra_upd) % (img->height / MB_BLOCK_SIZE);
}
}
else
{
//Rate control
if(!params->RCEnable && params->HierarchicalCoding == 0) // without using rate control
{
//QP oscillation for secondary SP frames
if ((params->qp2start > 0 && img->frame_no >= params->qp2start && params->sp2_frame_indicator==0)||
( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ) && (params->sp2_frame_indicator==1)))
{
img->qp = params->qp[1][B_SLICE];
}
else
{
img->qp = params->qp[0][B_SLICE];
}
if (img->nal_reference_idc)
{
//QP oscillation for secondary SP frames
if ((params->qp2start > 0 && img->frame_no >= params->qp2start && params->sp2_frame_indicator==0)||
( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ) && (params->sp2_frame_indicator==1)))
{
img->qp = iClip3(-img->bitdepth_luma_qp_scale,51,params->qp[1][B_SLICE] + params->qpBRSOffset[1]);
}
else
{
img->qp = iClip3(-img->bitdepth_luma_qp_scale, 51, params->qp[0][B_SLICE] + params->qpBRSOffset[0]);
}
}
}
else if (!params->RCEnable && params->HierarchicalCoding !=0)
{
// Note that _CHANGE_QP_ does not work anymore for gop_structure. Needs to be fixed
img->qp = gop_structure[img->b_frame_to_code - 1].slice_qp;
}
}
img->no_output_of_prior_pics_flag = 0;
img->long_term_reference_flag = 0;
init_dec_ref_pic_marking_buffer();
}
/*!
************************************************************************
* \brief
* Initializes the parameters for a new field
************************************************************************
*/
static void init_field (ImageParameters *img)
{
img->current_mb_nr = 0;
img->current_slice_nr = 0;
stats->bit_slice = 0;
params->jumpd *= 2;
params->NumberBFrames *= 2;
img->number /= 2;
img->gop_number = (img->number - img->start_frame_no);
img->buf_cycle /= 2;
img->mb_y = img->mb_x = 0;
img->block_y = img->pix_y = img->pix_c_y = 0; // define vertical positions
img->block_x = img->pix_x = img->block_c_x = img->pix_c_x = 0; // define horizontal positions
if (!img->b_frame_to_code)
{
//Rate control
if(!params->RCEnable) // without using rate control
{
if (img->type == I_SLICE)
{
//QP oscillation for secondary SP frames
if ((params->qp2start > 0 && img->frame_no >= params->qp2start && params->sp2_frame_indicator==0)||
( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ) && (params->sp2_frame_indicator==1)))
img->qp = params->qp[1][I_SLICE];
else
img->qp = params->qp[0][I_SLICE]; // set quant. parameter for I-frame
}
else
{
//QP oscillation for secondary SP frames
if ((params->qp2start > 0 && img->frame_no >= params->qp2start && params->sp2_frame_indicator==0)||
( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ) && (params->sp2_frame_indicator==1)))
img->qp = params->qp[1][P_SLICE] + (img->nal_reference_idc ? 0 : params->DispPQPOffset);
else
img->qp = params->qp[0][P_SLICE] + (img->nal_reference_idc ? 0 : params->DispPQPOffset);
if (img->type == SP_SLICE)
{
if ( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ))
{
img->qp = params->qp[1][SP_SLICE];
img->qpsp = params->qpsp[1];
}
else
{
img->qp = params->qp[0][SP_SLICE];
img->qpsp = params->qpsp[0];
}
}
}
}
img->mb_y_intra = img->mb_y_upd; // img->mb_y_intra indicates which GOB to intra code for this frame
if (params->intra_upd > 0) // if error robustness, find next GOB to update
{
img->mb_y_upd =
(img->number / params->intra_upd) % (img->width / MB_BLOCK_SIZE);
}
}
else
{
//Rate control
if(!params->RCEnable && params->HierarchicalCoding == 0) // without using rate control
{
//QP oscillation for secondary SP frames
if ((params->qp2start > 0 && img->frame_no >= params->qp2start && params->sp2_frame_indicator==0)||
( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ) && (params->sp2_frame_indicator==1)))
{
img->qp = params->qp[1][B_SLICE];
}
else
img->qp = params->qp[0][B_SLICE];
if (img->nal_reference_idc)
{
//QP oscillation for secondary SP frames
if ((params->qp2start > 0 && img->frame_no >= params->qp2start && params->sp2_frame_indicator==0)||
( (params->qp2start > 0) && ( ( (img->frame_no ) % (2*params->qp2start) ) >=params->qp2start ) && (params->sp2_frame_indicator==1)))
{
img->qp = iClip3(-img->bitdepth_luma_qp_scale,51,params->qp[1][B_SLICE] + params->qpBRSOffset[1]);
}
else
img->qp = iClip3(-img->bitdepth_luma_qp_scale,51,params->qp[0][B_SLICE] + params->qpBRSOffset[0]);
}
}
else if (!params->RCEnable && params->HierarchicalCoding != 0)
{
img->qp = gop_structure[img->b_frame_to_code - 1].slice_qp;
}
}
params->jumpd /= 2;
params->NumberBFrames /= 2;
img->buf_cycle *= 2;
img->number = 2 * img->number + img->fld_type;
img->gop_number = (img->number - img->start_frame_no);
}
/*!
************************************************************************
* \brief
* Upsample 4 times, store them in out4x. Color is simply copied
*
* \par Input:
* srcy, srcu, srcv, out4y, out4u, out4v
*
* \par Side Effects_
* Uses (writes) img4Y_tmp. This should be moved to a static variable
* in this module
************************************************************************/
void UnifiedOneForthPix (StorablePicture *s)
{
int ypadded_size = s->size_y_padded;
int xpadded_size = s->size_x_padded;
// don't upsample twice
if (s->imgY_sub)
return;
// Y component
get_mem4Dpel (&(s->imgY_sub), 4, 4, ypadded_size, xpadded_size);
if (NULL == s->imgY_sub)
no_mem_exit("alloc_storable_picture: s->imgY_sub");
s->p_img_sub[0] = s->imgY_sub;
s->p_curr_img_sub = s->p_img_sub[0];
if ( params->ChromaMCBuffer || img->P444_joined)
{
// UV components
if ( img->yuv_format != YUV400 )
{
if ( img->yuv_format == YUV420 )
{
get_mem5Dpel (&(s->imgUV_sub), 2, 8, 8, ypadded_size>>1, xpadded_size>>1);
}
else if ( img->yuv_format == YUV422 )
{
get_mem5Dpel (&(s->imgUV_sub), 2, 4, 8, ypadded_size, xpadded_size>>1);
}
else
{ // YUV444
get_mem5Dpel (&(s->imgUV_sub), 2, 4, 4, ypadded_size, xpadded_size);
}
s->p_img_sub[1] = s->imgUV_sub[0];
s->p_img_sub[2] = s->imgUV_sub[1];
}
else
{
s->p_img_sub[1] = NULL;
s->p_img_sub[2] = NULL;
}
}
else
{
s->p_img_sub[1] = NULL;
s->p_img_sub[2] = NULL;
}
s->p_curr_img = s->imgY;
s->p_curr_img_sub = s->imgY_sub;
// derive the subpixel images for first component
// No need to interpolate if intra only encoding
if (params->intra_period != 1)
{
getSubImagesLuma ( s );
// and the sub-images for U and V
if ( (img->yuv_format != YUV400) && (params->ChromaMCBuffer) )
{
if (img->P444_joined)
{
//U
select_plane(PLANE_U);
getSubImagesLuma (s);
//V
select_plane(PLANE_V);
getSubImagesLuma (s);
//Y
select_plane(PLANE_Y);
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -