ref: 1ffbeda00def479c554b46ad5f2fd29480d56906
parent: c09f10722ad0ed0d46ef6dae84370d44ad81c17c
author: Ronald S. Bultje <rsbultje@gmail.com>
date: Thu Aug 29 17:26:58 EDT 2019
Use linear interpolation for high bit-depth pixel values
--- a/src/film_grain_tmpl.c
+++ b/src/film_grain_tmpl.c
@@ -172,6 +172,7 @@
{
const int shift_x = bitdepth - 8;
const int scaling_size = 1 << bitdepth;
+ const int pad = 1 << shift_x;
// Fill up the preceding entries with the initial value
for (int i = 0; i < points[0][0] << shift_x; i++)
@@ -186,7 +187,7 @@
const int dx = ex - bx;
const int dy = ey - by;
const int delta = dy * ((0x10000 + (dx >> 1)) / dx);
- for (int x = 0; x < dx; x++) {
+ for (int x = 0; x < dx; x += pad) {
const int v = by + ((x * delta + 0x8000) >> 16);
scaling[bx + x] = v;
}
@@ -195,6 +196,21 @@
// Fill up the remaining entries with the final value
for (int i = points[num - 1][0] << shift_x; i < scaling_size; i++)
scaling[i] = points[num - 1][1];
+
+ if (pad > 1) {
+ const int rnd = pad >> 1;
+ for (int i = 0; i < num - 1; i++) {
+ const int bx = points[i][0] << shift_x;
+ const int ex = points[i+1][0] << shift_x;
+ const int dx = ex - bx;
+ for (int x = 0; x < dx; x += pad) {
+ const int range = scaling[bx + x + pad] - scaling[bx + x];
+ for (int n = 1; n < pad; n++) {
+ scaling[bx + x + n] = scaling[bx + x] + ((range * n + rnd) >> shift_x);
+ }
+ }
+ }
+ }
}
// samples from the correct block of a grain LUT, while taking into account the