📄 image.c
字号:
Update_Picture_Buffers_top_field();
//all I- and P-frames
interpolate_frame_to_fb ();
}
else
{ // !! B frame shenyanfei
//current_field = ref_fld[4];
for (i=0; i<img->height; i++)
{
memcpy(imgY_com[i*2], imgY_top[i], img->width); // top field
}
for (i=0; i<img->height_cr; i++)
{
memcpy(imgUV_com[0][i*2], imgUV_top[0][i], img->width_cr);
memcpy(imgUV_com[1][i*2], imgUV_top[1][i], img->width_cr);
}
}
#ifdef COREFRAME
//把编码的核心帧信息保存,以备下次参考用
if(cur_core_frame_flag&&(img->type!=B_IMG))
{
//
memcpy(&core_frame_mref_fld[core_frame_num*2][0][0], &mref[0][0][0], (img->height+2*IMG_PAD_SIZE)*4*(img->width+2*IMG_PAD_SIZE)*4);
memcpy(&core_reference_field[core_frame_num*2][0][0][0], &ref_fld[0][0][0][0], img->height*img->width);
memcpy(&core_reference_field[core_frame_num*2][1][0][0], &ref_fld[0][1][0][0], img->height*img->width/4);
memcpy(&core_reference_field[core_frame_num*2][2][0][0], &ref_fld[0][2][0][0], img->height*img->width/4);
}
#endif
if(img->type==INTRA_IMG){
img->type = INTER_IMG;
img->buf_cycle /= 2; // cjw 20051230 I bot field reference number
second_IField=1;
}
img->nb_references++;
//Rate control
if(input->RCEnable)
setbitscount(TopFieldBits);
if(input->RCEnable)
{
rc_init_pict(0,0,0);
img->qp = updateQuantizationParameter(0);
}
img->TopFieldFlag=0; // [5/8/2007 Leeswan]
//initialize buffer
put_buffer_bot();
// !! start [12/28/2005] shenyanfei cjw
//cjw 20051219
img->LumVarFlag = 0 ; // !! default : no weighting prediction
img->mb_weighting_flag = 1 ;
//cjw 20051219
if(img->type != INTRA_IMG && input->slice_weighting_flag == 1){
estimate_weighting_factor_field();
}
// !! end [12/28/2005] shenyanfei cjw
init_field();
if(input->slice_set_enable) //X ZHENG, 2008.04
init_slice_set(1);
bot_field(bot_pic);
terminate_picture(); //delete by jlzheng 6.30
if (img->type != B_IMG) //all I- and P-frames
{
Update_Picture_Buffers_bot_field();
interpolate_frame_to_fb ();
}else // !! B frame shenyanfei
{
for (i=0; i<img->height; i++)
{
memcpy(imgY_com[i*2 + 1], imgY_bot[i], img->width); // bottom field
}
for (i=0; i<img->height_cr; i++)
{
memcpy(imgUV_com[0][i*2 + 1], imgUV_bot[0][i], img->width_cr);
memcpy(imgUV_com[1][i*2 + 1], imgUV_bot[1][i], img->width_cr);
}
}
#ifdef COREFRAME
//把编码的核心帧信息保存,以备下次参考用
if(cur_core_frame_flag&&(img->type!=B_IMG))
{
//
memcpy(&core_frame_mref_fld[core_frame_num*2+1][0][0], &mref[0][0][0], (img->height+2*IMG_PAD_SIZE)*4*(img->width+2*IMG_PAD_SIZE)*4);
memcpy(&core_reference_field[core_frame_num*2+1][0][0][0], &ref_fld[0][0][0][0], img->height*img->width);
memcpy(&core_reference_field[core_frame_num*2+1][1][0][0], &ref_fld[0][1][0][0], img->height*img->width/4);
memcpy(&core_reference_field[core_frame_num*2+1][2][0][0], &ref_fld[0][2][0][0], img->height*img->width/4);
}
#endif
if(img->type!=B_IMG)
combine_field();
imgY = imgY_com;
imgUV = imgUV_com;
imgY_org = imgY_org_frm;
imgUV_org = imgUV_org_frm;
img->height <<= 1;
img->height_cr <<= 1;
if (second_IField!=1)
{
img->buf_cycle >>= 1;
}
img->nb_references = (img->nb_references-1)/2;
//Commented by qihuafei, 20070926
/* if (input->InterlaceCodingOption != FIELD_CODING)
{
find_distortion (snr, img); // find snr from original frame picture
bot_pic->distortion_y = snr->snr_y;
bot_pic->distortion_u = snr->snr_u;
bot_pic->distortion_v = snr->snr_v;
}
*/
// restore reference number and image size
}
#ifdef COREFRAME
// 核心帧
if(cur_core_frame_flag)
{
img->imgtr_last_P_frm = img->preserve_imgtr_last_P_frm;
}
#endif
//Commented by qihuafei, 20070925
/* if(input->InterlaceCodingOption == PAFF_CODING) // !! picture adaptive frame field coding
{
if (!picture_structure_decision(frame_pic,top_pic,bot_pic))
{
//split frame to field
img->height >>= 1;
img->height_cr >>= 1;
if (img->type != B_IMG)
{
split_field_top();
split_field_bot();
}
img->height <<= 1 ;
img->height_cr <<= 1;
//restore buffer
img->picture_structure = 1;
currBitStream->byte_pos = framesize;
memcpy(currBitStream->streamBuffer, pic_buf,framesize);
writeout_picture ();
imgY = imgY_frm;
imgUV = imgUV_frm;
}else
{//field
//update refernce frame buffer
if (img->type != B_IMG)
{
//integer pixel buffer
for (i=0; i<img->height; i++)
{
memcpy(imgY_frm[i],imgY_com[i], img->width); // top field
}
for (i=0; i<img->height_cr; i++)
{
memcpy(imgUV_frm[0][i], imgUV_com[0][i], img->width_cr);
memcpy(imgUV_frm[1][i], imgUV_com[1][i], img->width_cr);
}
//update 1/4 pixel reference buffer
imgY = imgY_frm;
imgUV = imgUV_frm;
mref[0] = mref_frm[0];
interpolate_frame_to_fb();
}
writeout_picture ();
}
//Rate control
if(img->picture_structure==0)
img->FieldFrame=0; // [5/8/2007 Leeswan]
//the current choice is field coding/
else
img->FieldFrame=1; // [5/8/2007 Leeswan]
}
else
{
*/
writeout_picture ();
/* }
*/
//Commented by qihuafei, 20070926
/*
if (input->InterlaceCodingOption != FRAME_CODING)
{
store_field_MV (IMG_NUMBER); // assume that img->number = frame_number
}
*/
FreeBitstream();
find_snr ();
free(pic_buf);
time (<ime2); // end time sec
#ifdef WIN32
_ftime (&tstruct2); // end time ms
#else
ftime (&tstruct2); // end time ms
#endif
tmp_time = (ltime2 * 1000 + tstruct2.millitm) - (ltime1 * 1000 + tstruct1.millitm);
tot_time = tot_time + tmp_time;
// Write reconstructed images
write_reconstructed_image ();
//Rate control
if(input->RCEnable)
{
bits = stat->bit_ctr-stat->bit_ctr_n;//CABAC*/
rc_update_pict_frame(bits);
}
if (IMG_NUMBER == 0)
ReportFirstframe(tmp_time);
else
{
//Rate control
if(input->RCEnable)
{
if(input->InterlaceCodingOption==0)
bits=stat->bit_ctr-stat->bit_ctr_n;
else
{
bits = stat->bit_ctr -Pprev_bits; // used for rate control update */
Pprev_bits = stat->bit_ctr;
}
}
switch (img->type)
{
case INTRA_IMG:
stat->bit_ctr_P += stat->bit_ctr - stat->bit_ctr_n;
ReportIntra(tmp_time);
break;
case B_IMG:
stat->bit_ctr_B += stat->bit_ctr - stat->bit_ctr_n;
ReportB(tmp_time);
break;
default: // P, P_MULTPRED?
stat->bit_ctr_P += stat->bit_ctr - stat->bit_ctr_n;
ReportP(tmp_time);
}
}
stat->bit_ctr_n = stat->bit_ctr;
//Rate control
if(input->RCEnable)
{
rc_update_pict(bits);
/*update the parameters of quadratic R-D model*/
if((img->type==INTER_IMG)&&(input->InterlaceCodingOption==0))
updateRCModel();
else if((img->type==INTER_IMG)&&(input->InterlaceCodingOption!=0)\
&&(img->IFLAG==0))
updateRCModel();
}
if (IMG_NUMBER == 0)
return 0;
else
return 1;
}
/*
*************************************************************************
* Function:This function write out a picture
* Input:
* Output:
* Return: 0 if OK, \n
1 in case of error
* Attention:
*************************************************************************
*/
static int writeout_picture()
{
assert (currBitStream->bits_to_go == 8); //! should always be the case, the //! byte alignment is done in terminate_slice
WriteBitstreamtoFile();
return 0;
}
/*
*************************************************************************
* Function:Encodes a frame picture
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void code_a_picture (Picture *frame)
{
stat->em_prev_bits_frm = 0;
stat->em_prev_bits = &stat->em_prev_bits_frm;
AllocateBitstream();
picture_header();
picture_data(frame);
frame->bits_per_picture = 8 * (currBitStream->byte_pos);
//Commented by qihuafei, 20070926
/*
if (input->InterlaceCodingOption != FRAME_CODING) //this condition is always false without PAFF
{
find_distortion (snr, img);
frame->distortion_y = snr->snr_y;
frame->distortion_u = snr->snr_u;
frame->distortion_v = snr->snr_v;
}
*/
}
/*
*************************************************************************
* Function:Frame Mode Buffer
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void frame_mode_buffer (int bit_frame, float snr_frame_y, float snr_frame_u, float snr_frame_v)
{
if (img->type != B_IMG) //all I- and P-frames
interpolate_frame_to_fb ();
}
/*
*************************************************************************
* Function:Initializes the parameters for a new frame
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void init_frame ()
{
int i, j, k;
int prevP_no, nextP_no;
img->top_bot = -1; //Yulj 2004.07.20
img->current_mb_nr = 0;
img->current_slice_nr = 0;
//---Yulj 2004.07.15
if(!input->slice_set_enable) //added by mz, 2008.04.07
{
int widthMB, heightMB;
widthMB = img->width / MB_BLOCK_SIZE;
heightMB = img->height / MB_BLOCK_SIZE;
img->mb_no_currSliceLastMB = ( input->slice_row_nr != 0 )
? min(input->slice_row_nr * widthMB - 1, widthMB * heightMB - 1)
: widthMB * heightMB - 1 ;
}
//---end.
stat->bit_slice = 0;
img->coded_mb_nr = 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;
//Modified by qihuafei, 20070928
if (input->InterlaceCodingOption==FRAME)
{
refFrArr = refFrArr_frm;
fw_refFrArr = fw_refFrArr_frm;
bw_refFrArr = bw_refFrArr_frm;
}
if (img->type != B_IMG)
{
img->tr = IMG_NUMBER * (input->jumpd + 1);
img->imgtr_last_prev_P_frm = img->imgtr_last_P_frm;//Lou 1016
// Added by XiaoZhen Zheng, HiSilicon, 20070405
if (img->type==INTRA_IMG && img->Seqheader_flag==1) {
img->last_picture_distance = img->curr_picture_distance;
img->curr_picture_distance = (IMG_NUMBER * (input->jumpd + 1))%256;
}
picture_distance = (IMG_NUMBER * (input->jumpd + 1))%256-img->curr_picture_distance; //Hisilicon XiaoZhen Zheng 20070405
// picture_distance = (IMG_NUMBER * (input->jumpd + 1))%256; //Hisilicon XiaoZhen Zheng 20070327
img->imgtr_last_last_P_frm = img->imgtr_last_P_frm;//zj
img->imgtr_last_P_frm = img->imgtr_next_P_frm;
img->imgtr_next_P_frm = picture_distance; // Tsinghua 200701
if (IMG_NUMBER != 0 && input->successive_Bframe != 0) // B pictures to encode
nextP_tr_frm = picture_distance; // Added by Xiaozhen ZHENG, 2007.05.01
// nextP_tr_frm = img->tr; // Commented by Xiaozhen ZHENG, 2007.05.01
//Rate control
if(!input->RCEnable)
{
if (img->type == INTRA_IMG)
img->qp = input->qp0; // set quant. parameter for I-frame
else
{
img->qp = input->qpN;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -