📄 image.c
字号:
{ // !! 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);
}
}
if(img->type==INTRA_IMG){
img->type = INTER_IMG; // delete by jlzheng 7.21
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);
}
//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();
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);
}
}
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;
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
}
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=1;
/*the current choice is field coding*/
else
img->FieldFrame=0;
}
else
{
writeout_picture ();
}
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);
if (input->InterlaceCodingOption != FRAME_CODING)
{
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
{
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;
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
picture_distance = (IMG_NUMBER * (input->jumpd + 1))%256; //Hisilicon XiaoZhen Zheng 20070327
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 = img->tr;
//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;
}
}
}
else
{
img->p_interval = input->jumpd + 1;
prevP_no = (IMG_NUMBER - 1) * img->p_interval;
nextP_no = (IMG_NUMBER) * img->p_interval;
img->b_interval =
(int) ((float) (input->jumpd + 1) / (input->successive_Bframe + 1.0) + 0.49999);
img->tr = prevP_no + img->b_interval * img->b_frame_to_code; // from prev_P
picture_distance = ((IMG_NUMBER - 1) * (input->jumpd + 1) + img->b_interval * img->b_frame_to_code)%256; //Hisilicon XiaoZhen Zheng 20070327
if (img->tr >= nextP_no)
img->tr = nextP_no - 1;
//Rate control
if(!input->RCEnable)
img->qp = input->qpB;
// initialize arrays
if(!img->picture_structure) //field coding
{
for (k = 0; k < 2; k++)
for (i = 0; i < img->height / BLOCK_SIZE; i++)
for (j = 0; j < img->width / BLOCK_SIZE + 4; j++)
{
tmp_fwMV[k][i][j] = 0;
tmp_bwMV[k][i][j] = 0;
dfMV[k][i][j] = 0;
dbMV[k][i][j] = 0;
}
for (i = 0; i < img->height / B8_SIZE; i++)
for (j = 0; j < img->width / BLOCK_SIZE; j++)
{
fw_refFrArr[i][j] = bw_refFrArr[i][j] = -1;
}
}else
{
for (k = 0; k < 2; k++)
for (i = 0; i < img->height / BLOCK_SIZE; i++)
for (j = 0; j < img->width / BLOCK_SIZE + 4; j++)
{
tmp_fwMV[k][i][j] = 0;
tmp_bwMV[k][i][j] = 0;
dfMV[k][i][j] = 0;
dbMV[k][i][j] = 0;
}
for (i = 0; i < img->height / BLOCK_SIZE; i++)
for (j = 0; j < img->width / BLOCK_SIZE; j++)
{
fw_refFrArr[i][j] = bw_refFrArr[i][j] = -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -