Avoid right shift negative numbers

This avoids the rounding errors due to the right shift of the
negative numbers that cause the reconstruction coefficient has
higher distortion than the source coefficient.

BUG=aomedia:599

Change-Id: I11ed86bf1d41164dda4398545334a7b4e8e10513
This commit is contained in:
Jingning Han 2017-06-11 07:50:39 -07:00
Родитель 3599435aed
Коммит 32d26bc0af
1 изменённых файлов: 4 добавлений и 2 удалений

Просмотреть файл

@ -246,7 +246,7 @@ static int optimize_b_greedy(const AV1_COMMON *cm, MACROBLOCK *mb, int plane,
*/
// compute the distortion for the first candidate
// and the distortion for quantizing to 0.
int dx0 = (-coeff[rc]) * (1 << shift);
int dx0 = abs(coeff[rc]) * (1 << shift);
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
dx0 >>= xd->bd - 8;
@ -270,7 +270,9 @@ static int optimize_b_greedy(const AV1_COMMON *cm, MACROBLOCK *mb, int plane,
dx = (dqcoeff[rc] - coeff[rc]) * (1 << shift);
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
dx >>= xd->bd - 8;
int dx_sign = dx < 0 ? 1 : 0;
dx = abs(dx) >> (xd->bd - 8);
if (dx_sign) dx = -dx;
}
#endif // CONFIG_HIGHBITDEPTH
d2 = (int64_t)dx * dx;