📄 image.c
字号:
printf("dc_org = %d, dc_ref = %d, weight[%d] = %d\n",dc_org, dc_ref[n],n,weight[n][0]);
/* for now always use default weight for chroma weight */
weight[n][1] = default_weight_chroma;
weight[n][2] = default_weight_chroma;
/* store weighted reference pic for motion estimation */
for (i = 0; i < img->height * img->width; i++)
{
ref_pic_w[i] = Clip (0, 255, ((int) ref_pic[i] * weight[n][0] + wp_luma_round) / default_weight);
}
for (i = 0; i < 4*(img->height + 2*IMG_PAD_SIZE) ; i++)
{
for (j = 0; j< 4*(img->width + 2*IMG_PAD_SIZE); j++)
{
mref_w[n][i][j] = Clip (0, 255, ((int) mref[n][i][j] * weight[n][0] + wp_luma_round) / default_weight);
}
}
}
if ((img->type == P_SLICE)||(img->type == SP_SLICE))
{
num_bwd_ref = 0;
num_fwd_ref = num_ref;
}
else
{
num_bwd_ref = (img->type == B_SLICE && img->nal_reference_idc>0) ? num_ref : 1;
num_fwd_ref = (img->type == B_SLICE && img->nal_reference_idc>0) ? num_ref+1 : num_ref;
}
// printf("num_fwd_ref = %d num_bwd_ref = %d\n",num_fwd_ref,num_bwd_ref);
{ /* forward list */
if ((img->type == P_SLICE || img->type == SP_SLICE) && input->WeightedPrediction)
{
for (index = 0; index < num_ref; index++)
{
wp_weight[0][index][0] = weight[index][0];
wp_weight[0][index][1] = weight[index][1];
wp_weight[0][index][2] = weight[index][2];
// printf ("wp weight[%d] = %d \n", index, wp_weight[0][index][0]);
}
}
else if (img->type == B_SLICE && img->nal_reference_idc>0 && (input->WeightedBiprediction == 1))
{
for (index = 0; index < num_ref; index++)
{
wp_weight[0][index][0] = weight[index][0];
wp_weight[0][index][1] = weight[index][1];
wp_weight[0][index][2] = weight[index][2];
}
for (index = 0; index < num_ref; index++)
{ /* backward list */
if (index == 0)
n = 1;
else if (index == 1)
n = 0;
else
n = index;
}
}
else if (img->type == B_SLICE && (input->WeightedBiprediction == 1))
{
for (index = 0; index < num_ref - 1; index++)
{
wp_weight[0][index][0] = weight[index + 1][0];
wp_weight[0][index][1] = weight[index + 1][1];
wp_weight[0][index][2] = weight[index + 1][2];
}
wp_weight[1][0][0] = weight[0][0];
wp_weight[1][0][1] = weight[0][1];
wp_weight[1][0][2] = weight[0][2];
}
else
{
for (index = 0; index < num_ref; index++)
{
wp_weight[0][index][0] = 1<<luma_log_weight_denom;
wp_weight[0][index][1] = 1<<chroma_log_weight_denom;
wp_weight[0][index][2] = 1<<chroma_log_weight_denom;
wp_weight[1][index][0] = 1<<luma_log_weight_denom;
wp_weight[1][index][1] = 1<<chroma_log_weight_denom;
wp_weight[1][index][2] = 1<<chroma_log_weight_denom;
}
}
if (input->WeightedBiprediction > 0 && (img->type == B_SLICE))
{
if (img->nal_reference_idc>0)
{
for (index = 0; index < num_fwd_ref; index++)
{
fwd_ref[index] = index;
if (index == 0)
n = 1;
else if (index == 1)
n = 0;
else
n = index;
bwd_ref[index] = n;
}
}
else if (img->type == B_SLICE)
{
for (index = 0; index < num_fwd_ref; index++)
{
fwd_ref[index] = index+1;
}
bwd_ref[0] = 0; // only one possible backwards ref for traditional B picture in current software
}
}
if (img->type == B_SLICE) // need to fill in wbp_weight values
{
for (i = 0; i < num_fwd_ref; i++)
{
for (j = 0; j < num_bwd_ref; j++)
{
for (comp = 0; comp < 3; comp++)
{
log_weight_denom = (comp == 0) ? luma_log_weight_denom : chroma_log_weight_denom;
if (input->WeightedBiprediction == 1)
{
wbp_weight[0][i][j][comp] = wp_weight[0][i][comp];
wbp_weight[1][i][j][comp] = wp_weight[1][j][comp];
}
else if (input->WeightedBiprediction == 2)
{ // implicit mode
pt = poc_distance (fwd_ref[i], bwd_ref[j]);
p0 = poc_distance (fwd_ref[i], -1);
if (pt == 0)
{
wbp_weight[1][i][j][comp] = 32 ;
wbp_weight[0][i][j][comp] = 32;
}
else
{
x = (16384 + (pt>>1))/pt;
z = Clip(-1024, 1023, (x*p0 + 32 )>>6);
wbp_weight[1][i][j][comp] = z>>2;
if (wbp_weight[1][i][j][comp] < -64 || wbp_weight[1][i][j][comp] >128)
wbp_weight[1][i][j][comp] = 32;
wbp_weight[0][i][j][comp] = 64 - wbp_weight[1][i][j][comp];
}
// if (comp == 0 )
// printf ("bpw weight[%d][%d] = %d , %d \n", i, j, wbp_weight[0][i][j][0], wbp_weight[1][i][j][0]);
}
}
}
}
}
}
}
/*!
************************************************************************
* \brief
* Choose interpolation method depending on MV-resolution
************************************************************************
*/
static void interpolate_frame_to_fb ()
{ // write to mref[]
// UnifiedOneForthPix (imgY, imgUV[0], imgUV[1], mref[0], mcef[0][0], mcef[0][1], Refbuf11[0]);
}
/*!
************************************************************************
* \brief
* Choose interpolation method depending on MV-resolution
************************************************************************
*/
static void interpolate_frame ()
{ // write to mref[]
// UnifiedOneForthPix (imgY, imgUV[0], imgUV[1], mref[0], mcef[0][0], mcef[0][1], Refbuf11[0]);
}
static void GenerateFullPelRepresentation (pel_t ** Fourthpel,
pel_t * Fullpel, int xsize,
int ysize)
{
int x, y;
for (y = 0; y < ysize; y++)
for (x = 0; x < xsize; x++)
PutPel_11 (Fullpel, y, x, FastPelY_14 (Fourthpel, y * 4, x * 4));
}
/*!
************************************************************************
* \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 is;
int i, j, j4;
int ie2, je2, jj, maxy;
byte **out4Y;
byte *ref11;
byte **imgY = s->imgY;
// don't upsample twice
if (s->imgY_ups || s->imgY_11)
return;
s->imgY_11 = malloc ((s->size_x * s->size_y) * sizeof (byte));
if (NULL == s->imgY_11)
no_mem_exit("alloc_storable_picture: s->imgY_11");
get_mem2D (&(s->imgY_ups), (2*IMG_PAD_SIZE + s->size_y)*4, (2*IMG_PAD_SIZE + s->size_x)*4);
out4Y = s->imgY_ups;
ref11 = s->imgY_11;
for (j = -IMG_PAD_SIZE; j < s->size_y + IMG_PAD_SIZE; j++)
{
for (i = -IMG_PAD_SIZE; i < s->size_x + IMG_PAD_SIZE; i++)
{
jj = max (0, min (s->size_y - 1, j));
is =
(ONE_FOURTH_TAP[0][0] *
(imgY[jj][max (0, min (s->size_x - 1, i))] +
imgY[jj][max (0, min (s->size_x - 1, i + 1))]) +
ONE_FOURTH_TAP[1][0] *
(imgY[jj][max (0, min (s->size_x - 1, i - 1))] +
imgY[jj][max (0, min (s->size_x - 1, i + 2))]) +
ONE_FOURTH_TAP[2][0] *
(imgY[jj][max (0, min (s->size_x - 1, i - 2))] +
imgY[jj][max (0, min (s->size_x - 1, i + 3))]));
img4Y_tmp[j + IMG_PAD_SIZE][(i + IMG_PAD_SIZE) * 2] = imgY[jj][max (0, min (s->size_x - 1, i))] * 1024; // 1/1 pix pos
img4Y_tmp[j + IMG_PAD_SIZE][(i + IMG_PAD_SIZE) * 2 + 1] = is * 32; // 1/2 pix pos
}
}
for (i = 0; i < (s->size_x + 2 * IMG_PAD_SIZE) * 2; i++)
{
for (j = 0; j < s->size_y + 2 * IMG_PAD_SIZE; j++)
{
j4 = j * 4;
maxy = s->size_y + 2 * IMG_PAD_SIZE - 1;
// change for TML4, use 6 TAP vertical filter
is =
(ONE_FOURTH_TAP[0][0] *
(img4Y_tmp[j][i] + img4Y_tmp[min (maxy, j + 1)][i]) +
ONE_FOURTH_TAP[1][0] * (img4Y_tmp[max (0, j - 1)][i] +
img4Y_tmp[min (maxy, j + 2)][i]) +
ONE_FOURTH_TAP[2][0] * (img4Y_tmp[max (0, j - 2)][i] +
img4Y_tmp[min (maxy, j + 3)][i])) / 32;
PutPel_14 (out4Y, (j - IMG_PAD_SIZE) * 4, (i - IMG_PAD_SIZE * 2) * 2, (pel_t) max (0, min (255, (int) ((img4Y_tmp[j][i] + 512) / 1024)))); // 1/2 pix
PutPel_14 (out4Y, (j - IMG_PAD_SIZE) * 4 + 2, (i - IMG_PAD_SIZE * 2) * 2, (pel_t) max (0, min (255, (int) ((is + 512) / 1024)))); // 1/2 pix
}
}
/* 1/4 pix */
/* luma */
ie2 = (s->size_x + 2 * IMG_PAD_SIZE - 1) * 4;
je2 = (s->size_y + 2 * IMG_PAD_SIZE - 1) * 4;
for (j = 0; j < je2 + 4; j += 2)
for (i = 0; i < ie2 + 3; i += 2)
{
/* '-' */
PutPel_14 (out4Y, j - IMG_PAD_SIZE * 4, i - IMG_PAD_SIZE * 4 + 1,
(pel_t) (max
(0,
min (255,
(int) (FastPelY_14
(out4Y, j - IMG_PAD_SIZE * 4,
i - IMG_PAD_SIZE * 4) +
FastPelY_14 (out4Y,
j - IMG_PAD_SIZE * 4,
min (ie2 + 2,
i + 2) -
IMG_PAD_SIZE * 4)+1) /
2))));
}
for (i = 0; i < ie2 + 4; i++)
{
for (j = 0; j < je2 + 3; j += 2)
{
if (i % 2 == 0)
{
/* '|' */
PutPel_14 (out4Y, j - IMG_PAD_SIZE * 4 + 1,
i - IMG_PAD_SIZE * 4,
(pel_t) (max
(0,
min (255,
(int) (FastPelY_14
(out4Y, j - IMG_PAD_SIZE * 4,
i - IMG_PAD_SIZE * 4) +
FastPelY_14 (out4Y,
min (je2 + 2,
j + 2) -
IMG_PAD_SIZE *
4,
i -
IMG_PAD_SIZE *
4)+1) / 2))));
}
else if ((j % 4 == 0 && i % 4 == 1) || (j % 4 == 2 && i % 4 == 3))
{
/* '/' */
PutPel_14 (out4Y, j - IMG_PAD_SIZE * 4 + 1,
i - IMG_PAD_SIZE * 4,
(pel_t) (max
(0,
min (255,
(int) (FastPelY_14
(out4Y, j - IMG_PAD_SIZE * 4,
min (ie2 + 2,
i + 1) -
IMG_PAD_SIZE * 4) +
FastPelY_14 (out4Y,
min (je2 + 2,
j + 2) -
IMG_PAD_SIZE *
4,
i -
IMG_PAD_SIZE *
4 - 1) + 1) / 2))));
}
else
{
/* '\' */
PutPel_14 (out4Y, j - IMG_PAD_SIZE * 4 + 1,
i - IMG_PAD_SIZE * 4,
(pel_t) (max
(0,
min (255,
(int) (FastPelY_14
(out4Y, j - IMG_PAD_SIZE * 4,
i - IMG_PAD_SIZE * 4 - 1) +
FastPelY_14 (out4Y,
min (je2 + 2,
j + 2) -
IMG_PAD_SIZE *
4, min (ie2 + 2,
i + 1) -
IMG_PAD_SIZE *
4) + 1) / 2))));
}
}
}
/* Chroma: */
/* for (j = 0; j < img->height_cr; j++)
{
memcpy (outU[j], imgU[j], img->width_cr); // just copy 1/1 pix, interpolate "online"
memcpy (outV[j], imgV[j], img->width_cr);
}
*/
// Generate 1/1th pel representation (used for integer pel MV search)
GenerateFullPelRepresentation (out4Y, ref11, s->size_x, s->size_y);
}
/*!
************************************************************************
* \brief
* Find SNR for all three components
************************************************************************
*/
static void find_snr ()
{
int i, j;
int diff_y, diff_u, diff_v;
int impix;
// Calculate PSNR for Y, U and V.
// Luma.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -