📄 me_distortion.c
字号:
int blocksize_y_cr = blocksize_y >> shift_cr_y;
int cr_pad_size_x = img_cr_padded_size_x - blocksize_x_cr;
int k;
for (k=0; k < 2; k++)
{
src_line = src_pic + (256 << k);
ref_line = get_crline[ref_access_method] ( ref_pic_sub.crcb[k], cand_y, cand_x);
for (y=0; y<blocksize_y_cr; y++)
{
for (x4 = 0; x4 < blocksize_x_cr; x4+=2)
{
weighted_pel = iClip1( img->max_imgpel_value_uv, ((weight_cr[k] * *ref_line++ + wp_chroma_round) >> chroma_log_weight_denom) + offset_cr[k]);
mcost += byte_abs[ *src_line++ - weighted_pel ];
weighted_pel = iClip1( img->max_imgpel_value_uv, ((weight_cr[k] * *ref_line++ + wp_chroma_round) >> chroma_log_weight_denom) + offset_cr[k]);
mcost += byte_abs[ *src_line++ - weighted_pel ];
}
if (mcost >= min_mcost) return mcost;
ref_line += cr_pad_size_x;
}
}
}
return mcost;
}
/*!
************************************************************************
* \brief
* BiPred SAD computation (no weights)
************************************************************************
*/
int computeBiPredSAD1(imgpel* src_pic,
int blocksize_y,
int blocksize_x,
int min_mcost,
int cand_x1, int cand_y1,
int cand_x2, int cand_y2)
{
int mcost = 0;
int bi_diff;
int y,x4;
int pad_size_x = img_padded_size_x - blocksize_x;
src_line = src_pic;
ref2_line = get_line[bipred2_access_method] (ref_pic2_sub.luma, cand_y2, cand_x2);
ref1_line = get_line[bipred1_access_method] (ref_pic1_sub.luma, cand_y1, cand_x1);
for (y = 0; y < blocksize_y; y++)
{
for (x4 = 0; x4 < blocksize_x; x4+=4)
{
bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
mcost += byte_abs[bi_diff];
bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
mcost += byte_abs[bi_diff];
bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
mcost += byte_abs[bi_diff];
bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
mcost += byte_abs[bi_diff];
}
if (mcost >= min_mcost) return mcost;
ref2_line += pad_size_x;
ref1_line += pad_size_x;
}
if ( ChromaMEEnable ) {
// calculate chroma conribution to motion compensation error
int blocksize_x_cr = blocksize_x >> shift_cr_x;
int blocksize_y_cr = blocksize_y >> shift_cr_y;
int cr_pad_size_x = img_cr_padded_size_x - blocksize_x_cr;
int k;
for (k=0; k<2; k++)
{
src_line = src_pic + (256 << k);
ref2_line = get_crline[bipred2_access_method] ( ref_pic2_sub.crcb[k], cand_y2, cand_x2);
ref1_line = get_crline[bipred1_access_method] ( ref_pic1_sub.crcb[k], cand_y1, cand_x1);
for (y=0; y<blocksize_y_cr; y++)
{
for (x4 = 0; x4 < blocksize_x_cr; x4+=2)
{
bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
mcost += byte_abs[bi_diff];
bi_diff = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
mcost += byte_abs[bi_diff];
}
if (mcost >= min_mcost) return mcost;
ref2_line += cr_pad_size_x;
ref1_line += cr_pad_size_x;
}
}
}
return mcost;
}
/*!
************************************************************************
* \brief
* BiPred SAD computation (with weights)
************************************************************************
*/
int computeBiPredSAD2(imgpel* src_pic,
int blocksize_y,
int blocksize_x,
int min_mcost,
int cand_x1, int cand_y1,
int cand_x2, int cand_y2)
{
int mcost = 0;
int bi_diff;
int denom = luma_log_weight_denom + 1;
int lround = 2 * wp_luma_round;
int y,x4;
int weighted_pel, pixel1, pixel2;
int pad_size_x = img_padded_size_x - blocksize_x;
src_line = src_pic;
ref2_line = get_line[bipred2_access_method] (ref_pic2_sub.luma, cand_y2, cand_x2);
ref1_line = get_line[bipred1_access_method] (ref_pic1_sub.luma, cand_y1, cand_x1);
for (y=0; y<blocksize_y; y++)
{
for (x4 = 0; x4 < blocksize_x; x4+=4)
{
pixel1 = weight1 * (*ref1_line++);
pixel2 = weight2 * (*ref2_line++);
weighted_pel = iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
bi_diff = (*src_line++) - weighted_pel;
mcost += byte_abs[bi_diff];
pixel1 = weight1 * (*ref1_line++);
pixel2 = weight2 * (*ref2_line++);
weighted_pel = iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
bi_diff = (*src_line++) - weighted_pel;
mcost += byte_abs[bi_diff];
pixel1 = weight1 * (*ref1_line++);
pixel2 = weight2 * (*ref2_line++);
weighted_pel = iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
bi_diff = (*src_line++) - weighted_pel;
mcost += byte_abs[bi_diff];
pixel1 = weight1 * (*ref1_line++);
pixel2 = weight2 * (*ref2_line++);
weighted_pel = iClip1( img->max_imgpel_value, ((pixel1 + pixel2 + lround) >> denom) + offsetBi);
bi_diff = (*src_line++) - weighted_pel;
mcost += byte_abs[bi_diff];
}
if (mcost >= min_mcost) return mcost;
ref2_line += pad_size_x;
ref1_line += pad_size_x;
}
if ( ChromaMEEnable ) {
// calculate chroma conribution to motion compensation error
int blocksize_x_cr = blocksize_x >> shift_cr_x;
int blocksize_y_cr = blocksize_y >> shift_cr_y;
int cr_pad_size_x = img_cr_padded_size_x - blocksize_x_cr;
int k;
for (k=0; k<2; k++)
{
src_line = src_pic + (256 << k);
ref2_line = get_crline[bipred2_access_method] ( ref_pic2_sub.crcb[k], cand_y2, cand_x2);
ref1_line = get_crline[bipred1_access_method] ( ref_pic1_sub.crcb[k], cand_y1, cand_x1);
for (y=0; y<blocksize_y_cr; y++)
{
for (x4 = 0; x4 < blocksize_x_cr; x4+=2)
{
pixel1 = weight1_cr[k] * (*ref1_line++);
pixel2 = weight2_cr[k] * (*ref2_line++);
weighted_pel = iClip1( img->max_imgpel_value_uv, ((pixel1 + pixel2 + lround) >> denom) + offsetBi_cr[k]);
bi_diff = (*src_line++) - weighted_pel;
mcost += byte_abs[bi_diff];
pixel1 = weight1_cr[k] * (*ref1_line++);
pixel2 = weight2_cr[k] * (*ref2_line++);
weighted_pel = iClip1( img->max_imgpel_value_uv, ((pixel1 + pixel2 + lround) >> denom) + offsetBi_cr[k]);
bi_diff = (*src_line++) - weighted_pel;
mcost += byte_abs[bi_diff];
}
if (mcost >= min_mcost) return mcost;
ref2_line += cr_pad_size_x;
ref1_line += cr_pad_size_x;
}
}
}
return mcost;
}
/*!
************************************************************************
* \brief
* SAD computation _with_ Hadamard Transform
************************************************************************
*/
int computeSATD(imgpel* src_pic,
int blocksize_y,
int blocksize_x,
int min_mcost,
int cand_x,
int cand_y)
{
int mcost = 0;
int y, x, y4, *d;
int src_size_x, src_size_mul;
imgpel *src_tmp = src_pic;
if ( !test8x8transform )
{ // 4x4 TRANSFORM
src_size_x = blocksize_x - BLOCK_SIZE;
src_size_mul = blocksize_x * BLOCK_SIZE;
for (y = cand_y; y < cand_y + (blocksize_y<<2); y += (BLOCK_SIZE_SP))
{
for (x=0; x<blocksize_x; x += BLOCK_SIZE)
{
d = diff;
ref_line = get_line[ref_access_method] (ref_pic_sub.luma, y, cand_x + (x<<2));
src_line = src_tmp + x;
for (y4 = 0; y4 < BLOCK_SIZE; y4++ )
{
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
ref_line += img_padded_size_x_m4x4;
src_line += src_size_x;
}
if ((mcost += HadamardSAD4x4 (diff)) > min_mcost) return mcost;
}
src_tmp += src_size_mul;
}
}
else
{ // 8x8 TRANSFORM
src_size_x = (blocksize_x - BLOCK_SIZE8x8);
src_size_mul = blocksize_x * BLOCK_SIZE8x8;
for (y = cand_y; y < cand_y + (blocksize_y<<2); y += (BLOCK_SIZE8x8_SP) )
{
for (x=0; x<blocksize_x; x += BLOCK_SIZE8x8 )
{
d = diff;
ref_line = get_line[ref_access_method] (ref_pic_sub.luma, y, cand_x + (x<<2));
src_line = src_tmp + x;
for (y4 = 0; y4 < BLOCK_SIZE8x8; y4++ )
{
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
*d++ = *src_line++ - *ref_line++ ;
ref_line += img_padded_size_x_m8x8;
src_line += src_size_x;
}
if ((mcost += HadamardSAD8x8 (diff)) > min_mcost) return mcost;
}
src_tmp += src_size_mul;
}
}
return mcost;
}
/*!
************************************************************************
* \brief
* SAD computation of weighted samples _with_ Hadamard Transform
************************************************************************
*/
int computeSATDWP(imgpel* src_pic,
int blocksize_y,
int blocksize_x,
int min_mcost,
int cand_x,
int cand_y)
{
int mcost = 0;
int y, x, y4, *d;
int weighted_pel;
int src_size_x, src_size_mul;
imgpel *src_tmp = src_pic;
if ( !test8x8transform )
{ // 4x4 TRANSFORM
src_size_x = (blocksize_x - BLOCK_SIZE);
src_size_mul = blocksize_x * BLOCK_SIZE;
for (y = cand_y; y < cand_y + (blocksize_y<<2); y += (BLOCK_SIZE_SP))
{
for (x=0; x<blocksize_x; x += BLOCK_SIZE)
{
d = diff;
ref_line = get_line[ref_access_method] (ref_pic_sub.luma, y, cand_x + (x<<2));
src_line = src_tmp + x;
for (y4 = 0; y4 < BLOCK_SIZE; y4++ )
{
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
ref_line += img_padded_size_x_m4x4;
src_line += src_size_x;
}
if ((mcost += HadamardSAD4x4 (diff)) > min_mcost) return mcost;
}
src_tmp += src_size_mul;
}
}
else
{ // 8x8 TRANSFORM
src_size_x = (blocksize_x - BLOCK_SIZE8x8);
src_size_mul = blocksize_x * BLOCK_SIZE8x8;
for (y = cand_y; y < cand_y + (blocksize_y<<2); y += (BLOCK_SIZE8x8_SP) )
{
for (x=0; x<blocksize_x; x += BLOCK_SIZE8x8 )
{
d = diff;
ref_line = get_line[ref_access_method] (ref_pic_sub.luma, y, cand_x + (x<<2));
src_line = src_tmp + x;
for (y4 = 0; y4 < BLOCK_SIZE8x8; y4++ )
{
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
weighted_pel = iClip1( img->max_imgpel_value, ((weight_luma * *ref_line++ + wp_luma_round) >> luma_log_weight_denom) + offset_luma);
*d++ = *src_line++ - weighted_pel;
ref_line += img_padded_size_x_m8x8;
src_line += src_size_x;
}
if ((mcost += HadamardSAD8x8 (diff)) > min_mcost) return mcost;
}
src_tmp += src_size_mul;
}
}
return mcost;
}
/*!
************************************************************************
* \brief
* BiPred (w/o weights) SATD computation
************************************************************************
*/
int computeBiPredSATD1(imgpel* src_pic,
int blocksize_y,
int blocksize_x,
int min_mcost,
int cand_x1, int cand_y1,
int cand_x2, int cand_y2)
{
int mcost = 0;
int y, x, y4, *d;
int src_size_x, src_size_mul;
imgpel *src_tmp = src_pic;
if ( !test8x8transform )
{ // 4x4 TRANSFORM
src_size_x = (blocksize_x - BLOCK_SIZE);
src_size_mul = blocksize_x * BLOCK_SIZE;
for (y=0; y<(blocksize_y<<2); y += (BLOCK_SIZE_SP))
{
for (x=0; x<blocksize_x; x += BLOCK_SIZE)
{
d = diff;
src_line = src_tmp + x;
ref2_line = get_line[bipred2_access_method] (ref_pic2_sub.luma, cand_y2 + y, cand_x2 + (x<<2));
ref1_line = get_line[bipred1_access_method] (ref_pic1_sub.luma, cand_y1 + y, cand_x1 + (x<<2));
for (y4 = 0; y4 < BLOCK_SIZE; y4++ )
{
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
ref1_line += img_padded_size_x_m4x4;
ref2_line += img_padded_size_x_m4x4;
src_line += src_size_x;
}
if ((mcost += HadamardSAD4x4 (diff)) > min_mcost) return mcost;
}
src_tmp += src_size_mul;
}
}
else
{ // 8x8 TRANSFORM
src_size_x = (blocksize_x - BLOCK_SIZE8x8);
src_size_mul = blocksize_x * BLOCK_SIZE8x8;
for (y=0; y<blocksize_y; y += BLOCK_SIZE8x8 )
{
int y_pos2 = cand_y2 + (y<<2);
int y_pos1 = cand_y1 + (y<<2);
for (x=0; x<blocksize_x; x += BLOCK_SIZE8x8 )
{
d = diff;
src_line = src_tmp + x;
ref2_line = get_line[bipred2_access_method] (ref_pic2_sub.luma, y_pos2, cand_x2 + (x<<2));
ref1_line = get_line[bipred1_access_method] (ref_pic1_sub.luma, y_pos1, cand_x1 + (x<<2));
for (y4 = 0; y4 < BLOCK_SIZE8x8; y4++ )
{
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
*d++ = (*src_line++) - ((*ref1_line++ + *ref2_line++ + 1)>>1);
ref1_line += img_padded_size_x_m8x8;
ref2_line += img_padded_size_x_m8x8;
src_line += src_size_x;
}
if ((mcost += HadamardSAD8x8 (diff)) > min_mcost) return mcost;
}
src_tmp += src_size_mul;
}
}
return mcost;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -