📄 image.c
字号:
}
}
// 1/4 pix
ie2 = (img->width + 2 * IMG_PAD_SIZE - 1) * 4;
je2 = (img->height + 2 * IMG_PAD_SIZE - 1) * 4;
//horizonal 1/4 interpolation
for (j = 0; j < (img->height + 2 * IMG_PAD_SIZE)*4; j += 2)
for (i = 0; i < (img->width + 2 * IMG_PAD_SIZE)*4; i += 2)
{
// '-'
img4Y_tmp[j][i+1]=IClip (0,255,
(int) ((1* img4Y_tmp[j][IClip (0, (img->width + 2 * IMG_PAD_SIZE) * 4 - 2, i-2)] +
7* img4Y_tmp[j][IClip (0, (img->width + 2 * IMG_PAD_SIZE) * 4 - 2, i )] +
7* img4Y_tmp[j][IClip (0, (img->width + 2 * IMG_PAD_SIZE) * 4 - 2, i+2)] +
1* img4Y_tmp[j][IClip (0, (img->width + 2 * IMG_PAD_SIZE) * 4 - 2, i+4)] + 512)/ 1024)
);
}
//vertical 1/4 interpolation
for (i = 0; i < (img->width + 2 * IMG_PAD_SIZE)*4; i++)
{
for (j = 0; j < (img->height + 2 * IMG_PAD_SIZE)*4; j += 2)
{
// '|'
if (i % 2 == 0)
{
img4Y_tmp[j+1][i]=IClip(0,255,
(int) ((1* img4Y_tmp[IClip (0, (img->height + 2 * IMG_PAD_SIZE) * 4 - 2, j-2)][i] +
7* img4Y_tmp[IClip (0, (img->height + 2 * IMG_PAD_SIZE) * 4 - 2, j )][i] +
7* img4Y_tmp[IClip (0, (img->height + 2 * IMG_PAD_SIZE) * 4 - 2, j+2)][i] +
1* img4Y_tmp[IClip (0, (img->height + 2 * IMG_PAD_SIZE) * 4 - 2, j+4)][i] + 512) / 1024)
);
}
else if (j % 4 == 0 && i % 4 == 1)
{
// '\'
img4Y_tmp[j+1][i]=IClip(0, 255,
(int) ((img4Y_tmp[j+2][i+1] + img4Y_tmp[j][i-1] + 64) / 128)
);
}
else if(j % 4 == 2 && i % 4 == 3){
img4Y_tmp[j+1][i]=IClip(0, 255,
(int) ((img4Y_tmp[j][i-1]
+ img4Y_tmp[min((img->height + 2 * IMG_PAD_SIZE - 1) * 4, j+2)][min((img->width + 2 * IMG_PAD_SIZE - 1) * 4, i+1)] + 64 )/ 128)
);
}
else if(j % 4 == 0 && i % 4 == 3)
{
// '/'
img4Y_tmp[j+1][i]=IClip(0, 255,
(int) ((img4Y_tmp[j+2][i-1]
+ img4Y_tmp[j][min((img->width + 2 * IMG_PAD_SIZE - 1) * 4, i+1)] + 64) / 128)
);
}
else if(j % 4 == 2 && i % 4 == 1){
// '/'
img4Y_tmp[j+1][i]=IClip(0, 255,
(int) ((img4Y_tmp[j][i+1]
+ img4Y_tmp[min((img->height + 2 * IMG_PAD_SIZE - 1) * 4, j+2)][i-1] + 64) / 128)
);
}
}
}
for (j = 0; j < (img->height + 2 * IMG_PAD_SIZE)*4; j += 2)
for (i = 0; i < (img->width + 2 * IMG_PAD_SIZE)*4; i += 2)
{
img4Y_tmp[j][i]=IClip(0, 255, (int) (img4Y_tmp[j][i] + 32) / 64);
}
for (j = 0; j < (img->height + 2 * IMG_PAD_SIZE)*4; j ++)
for (i = 0; i < (img->width + 2 * IMG_PAD_SIZE)*4; i ++)
{
PutPel_14 (out4Y, j - IMG_PAD_SIZE * 4, i - IMG_PAD_SIZE * 4 ,img4Y_tmp[j][i]);
}
}
/*
*************************************************************************
* Function:Find SNR for all three components
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void find_snr ()
{
int i, j;
int diff_y, diff_u, diff_v;
int impix;
// Calculate PSNR for Y, U and V.
// Luma.
impix = img->height * img->width;
diff_y = 0;
for (i = 0; i < img->width; ++i)
{
for (j = 0; j < img->height; ++j)
{
diff_y += img->quad[imgY_org[j][i] - imgY[j][i]];
}
}
// Chroma.
diff_u = 0;
diff_v = 0;
//4:0:0 WANGJP START
if (input->chroma_format)
{
for (i = 0; i < img->width_cr; i++)
{
for (j = 0; j < img->height_cr; j++)
{
diff_u += img->quad[imgUV_org[0][j][i] - imgUV[0][j][i]];
diff_v += img->quad[imgUV_org[1][j][i] - imgUV[1][j][i]];
}
}
}
//WANGJP END
// Collecting SNR statistics
if (diff_y != 0)
{
snr->snr_y = (float) (10 * log10 (65025 * (float) impix / (float) diff_y)); // luma snr for current frame
snr->snr_u = (float) (10 * log10 (65025 * (float) impix / (float) (4 * diff_u))); // u croma snr for current frame, 1/4 of luma samples
snr->snr_v = (float) (10 * log10 (65025 * (float) impix / (float) (4 * diff_v))); // v croma snr for current frame, 1/4 of luma samples
}
if (img->number == 0)
{
snr->snr_y1 = (float) (10 * log10 (65025 * (float) impix / (float) diff_y)); // keep luma snr for first frame
snr->snr_u1 = (float) (10 * log10 (65025 * (float) impix / (float) (4 * diff_u))); // keep croma u snr for first frame
snr->snr_v1 = (float) (10 * log10 (65025 * (float) impix / (float) (4 * diff_v))); // keep croma v snr for first frame
snr->snr_ya = snr->snr_y1;
snr->snr_ua = snr->snr_u1;
snr->snr_va = snr->snr_v1;
}
// B pictures
else
{
snr->snr_ya = (float) (snr->snr_ya * (img->number + Bframe_ctr) + snr->snr_y) / (img->number + Bframe_ctr + 1); // average snr lume for all frames inc. first
snr->snr_ua = (float) (snr->snr_ua * (img->number + Bframe_ctr) + snr->snr_u) / (img->number + Bframe_ctr + 1); // average snr u croma for all frames inc. first
snr->snr_va = (float) (snr->snr_va * (img->number + Bframe_ctr) + snr->snr_v) / (img->number + Bframe_ctr + 1); // average snr v croma for all frames inc. first
}
}
/*
*************************************************************************
* Function:Find distortion for all three components
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void find_distortion ()
{
int i, j;
int diff_y, diff_u, diff_v;
int impix;
// Calculate PSNR for Y, U and V.
// Luma.
impix = img->height * img->width;
diff_y = 0;
for (i = 0; i < img->width; ++i)
{
for (j = 0; j < img->height; ++j)
{
diff_y += img->quad[abs (imgY_org[j][i] - imgY[j][i])];
}
}
// Chroma.
diff_u = 0;
diff_v = 0;
for (i = 0; i < img->width_cr; i++)
{
for (j = 0; j < img->height_cr; j++)
{
diff_u += img->quad[abs (imgUV_org[0][j][i] - imgUV[0][j][i])];
diff_v += img->quad[abs (imgUV_org[1][j][i] - imgUV[1][j][i])];
}
}
// Calculate real PSNR at find_snr_avg()
snr->snr_y = (float) diff_y;
snr->snr_u = (float) diff_u;
snr->snr_v = (float) diff_v;
}
/*!
************************************************************************
* \brief
* RD decision of frame and field coding
* Commented by qihuafei, 20070926
************************************************************************
*/
/*
int decide_fld_frame(float snr_frame_Y, float snr_field_Y, int bit_field, int bit_frame, double lambda_picture)
{
double cost_frame, cost_field;
cost_frame = bit_frame * lambda_picture + snr_frame_Y;
cost_field = bit_field * lambda_picture + snr_field_Y;
if (cost_field > cost_frame)
return (0);
else
return (1);
}
*/
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void ReportFirstframe(int tmp_time)
{
int bits;
FILE *file = fopen("stat.dat","at");
fprintf(file,"\n -------------------- DEBUG_INFO_START -------------------- \n");
fprintf (file,"%3d(I) %8d %4d %7.4f %7.4f %7.4f %5d %3d %3s\n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time,
intras, img->picture_structure ? "FRM": "FLD");
fclose(file);
#ifdef BACKGROUND
if(img->typeb == BACKGROUND_IMG)
printf ("%3d(G) %8d %4d %7.4f %7.4f %7.4f %5d %s \n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, img->picture_structure ? "FRM":"FLD" );
else
printf ("%3d(I) %8d %4d %7.4f %7.4f %7.4f %5d %s \n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, img->picture_structure ? "FRM":"FLD" );
#else
printf ("%3d(I) %8d %4d %7.4f %7.4f %7.4f %5d %s \n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, img->picture_structure ? "FRM":"FLD" );
#endif
//Rate control
if(input->RCEnable)
{
if(input->InterlaceCodingOption==0)
bits = stat->bit_ctr-stat->bit_ctr_n; // used for rate control update
else
{
bits = stat->bit_ctr - Iprev_bits; // used for rate control update
Iprev_bits = stat->bit_ctr;
}
}
stat->bitr0 = stat->bitr;
stat->bit_ctr_0 = stat->bit_ctr;
stat->bit_ctr = 0;
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void ReportIntra(int tmp_time)
{
FILE *file = fopen("stat.dat","at");
#ifdef BACKGROUND
if(img->typeb == BACKGROUND_IMG){
fprintf (file,"%3d(G) %8d %4d %7.4f %7.4f %7.4f %5d \n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time );
fclose(file);
printf ("%3d(G) %8d %4d %7.4f %7.4f %7.4f %5d %3s\n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, img->picture_structure ? "FRM":"FLD");
}
else{
fprintf (file,"%3d(I) %8d %4d %7.4f %7.4f %7.4f %5d \n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time );
fclose(file);
printf ("%3d(I) %8d %4d %7.4f %7.4f %7.4f %5d %3s\n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, img->picture_structure ? "FRM":"FLD");
}
#else
fprintf (file,"%3d(I) %8d %4d %7.4f %7.4f %7.4f %5d \n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time );
fclose(file);
printf ("%3d(I) %8d %4d %7.4f %7.4f %7.4f %5d %3s\n",
frame_no, stat->bit_ctr - stat->bit_ctr_n,
img->qp, snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, img->picture_structure ? "FRM":"FLD");
#endif
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void ReportB(int tmp_time)
{
FILE *file = fopen("stat.dat","at");
fprintf (file,"%3d(B) %8d %4d %7.4f %7.4f %7.4f %5d \n",
frame_no, stat->bit_ctr - stat->bit_ctr_n, img->qp,
snr->snr_y, snr->snr_u, snr->snr_v, tmp_time);
fclose(file);
printf ("%3d(B) %8d %4d %7.4f %7.4f %7.4f %5d %3s\n",
frame_no, stat->bit_ctr - stat->bit_ctr_n, img->qp,
snr->snr_y, snr->snr_u, snr->snr_v, tmp_time, img->picture_structure ? "FRM":"FLD");
}
/*
*************************************************************************
* Function:
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void ReportP(int tmp_time)
{
FILE *file = fopen("stat.dat","at");
char typ = (img->types==INTRA_IMG)?'I':'P';
#ifdef BACKGROUND
if(img->typeb == BP_IMG){
typ = 'S';
}
#endif
fprintf (file,"%3d(%c) %8d %4d %7.4f %7.4f %7.4f %5d %3d\n",
frame_no, typ, stat->bit_ctr - stat->bit_ctr_n, img->qp, snr->snr_y,
snr->snr_u, snr->snr_v, tmp_time,
intras);
fclose(file);
printf ("%3d(%c) %8d %4d %7.4f %7.4f %7.4f %5d %3s %3d \n",
frame_no, typ, stat->bit_ctr - stat->bit_ctr_n, img->qp, snr->snr_y,
snr->snr_u, snr->snr_v, tmp_time,
img->picture_structure ? "FRM":"FLD",intras);
}
/*
*************************************************************************
* Function:Copies contents of a Sourceframe structure into the old-style
* variables imgY_org_frm and imgUV_org_frm. No other side effects
* Input: sf the source frame the frame is to be taken from
* Output:
* Return:
* Attention:
*************************************************************************
*/
static void CopyFrameToOldImgOrgVariables ()
{
int x, y;
byte *u_buffer,*v_buffer;
u_buffer=imgY_org_buffer+input->img_width*input->img_height;
v_buffer=imgY_org_buffer+input->img_width*input->img_height*5/4;
for (y=0; y<input->img_height; y++)
for (x=0; x<input->img_width; x++)
imgY_org_frm [y][x] = imgY_org_buffer[y*input->img_width+x];
for (y=0; y<input->img_height; y++)
for (x=input->img_width; x<img->width; x++)
imgY_org_frm [y][x] = imgY_org_frm [y][x-1];
//padding bottom border
for (y=input->img_height; y<img->height; y++)
for (x=0; x<img->width; x++)
imgY_org_frm [y][x] = imgY_org_frm [y-1][x];
for (y=0; y<input->img_height/2; y++)
for (x=0; x<input->img_width/2; x++)
{
imgUV_org_frm[0][y][x] = u_buffer[y*input->img_width/2+x];
imgUV_org_frm[1][y][x] = v_buffer[y*input->img_width/2+x];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -