ref: c09f10722ad0ed0d46ef6dae84370d44ad81c17c
parent: cfd6fe6dbd195bbe576883f017f517650674dc5e
author: Ronald S. Bultje <rsbultje@gmail.com>
date: Thu Aug 29 15:35:52 EDT 2019
Fix bugs in film grain generation - calculate chroma grain based on src (not dst) luma pixels; - division should precede multiplication in delta calculation. Together, these fix differences in film grain reconstruction between libaom and dav1d for various generated samples.
--- a/src/film_grain_tmpl.c
+++ b/src/film_grain_tmpl.c
@@ -185,7 +185,7 @@
const int ey = points[i+1][1];
const int dx = ex - bx;
const int dy = ey - by;
- const int delta = dy * ((0xFFFF + (dx >> 1))) / dx;
+ const int delta = dy * ((0x10000 + (dx >> 1)) / dx);
for (int x = 0; x < dx; x++) {
const int v = by + ((x * delta + 0x8000) >> 16);
scaling[bx + x] = v;
@@ -364,7 +364,7 @@
const int by = row_num * (BLOCK_SIZE >> sy);
pixel *const dst_row = (pixel *) out->data[1 + uv] + PXSTRIDE(stride) * by;
pixel *const src_row = (pixel *) in->data[1 + uv] + PXSTRIDE(stride) * by;
- pixel *const luma_row = (pixel *) out->data[0] + PXSTRIDE(out->stride[0]) * row_num * BLOCK_SIZE;
+ pixel *const luma_row = (pixel *) in->data[0] + PXSTRIDE(in->stride[0]) * row_num * BLOCK_SIZE;
int offsets[2 /* col offset */][2 /* row offset */];
@@ -394,7 +394,7 @@
#define add_noise_uv(x, y, grain) \
const int lx = (bx + x) << sx; \
const int ly = y << sy; \
- pixel *luma = luma_row + ly * PXSTRIDE(out->stride[0]) + lx; \
+ pixel *luma = luma_row + ly * PXSTRIDE(in->stride[0]) + lx; \
pixel avg = luma[0]; \
if (sx && lx + 1 < out->p.w) \
avg = (avg + luma[1] + 1) >> 1; \