diff options
author | David Conrad <david_conrad@apple.com> | 2022-06-08 01:09:39 +0300 |
---|---|---|
committer | David Conrad <david_conrad@apple.com> | 2022-09-15 03:28:22 +0300 |
commit | 10f5ce5441778a2f1e2bdf8da09395b51d295401 (patch) | |
tree | b6b9de310dbd0234bbfaf424da5e0d2512a15e9f | |
parent | 673ee2486521446b2500124d4826a84403d2aaca (diff) |
Support film grain application whose only effect is clipping to video range
This is the parameter combination:
num_y_points == 0 && num_cb_points == 0 && num_cr_points == 0 &&
chroma_scaling_from_luma == 1 && clip_to_restricted_range == 1
Film grain application has two effects: adding noise, and optionally
clipping to video range
For luma, the spec skips film grain application if there's no noise
(num_y_points == 0), but for chroma, it's only skipped if there's no
chroma noise *and* chroma_scaling_from_luma is false
This means it's possible for there to be no noise (num_*_points = 0), but
if clip_to_restricted_range is true then chroma pixels can be clipped to
video range, if chroma_scaling_from_luma is true. Luma pixels, however,
aren't clipped to video range unless there's noise to apply.
dav1d currently skips applying film grain entirely if there is no noise,
regardless of the secondary clipping.
-rw-r--r-- | src/fg_apply_tmpl.c | 7 | ||||
-rw-r--r-- | src/lib.c | 3 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/fg_apply_tmpl.c b/src/fg_apply_tmpl.c index ee14db9..581bcb7 100644 --- a/src/fg_apply_tmpl.c +++ b/src/fg_apply_tmpl.c @@ -51,6 +51,11 @@ static void generate_scaling(const int bitdepth, const int scaling_size = 1 << bitdepth; #endif + if (num == 0) { + memset(scaling, 0, scaling_size); + return; + } + // Fill up the preceding entries with the initial value memset(scaling, points[0][1], points[0][0] << shift_x); @@ -113,7 +118,7 @@ void bitfn(dav1d_prep_grain)(const Dav1dFilmGrainDSPContext *const dsp, data, 1 HIGHBD_TAIL_SUFFIX); // Generate scaling LUTs as needed - if (data->num_y_points) + if (data->num_y_points || data->chroma_scaling_from_luma) generate_scaling(in->p.bpc, data->y_points, data->num_y_points, scaling[0]); if (data->num_uv_points[0]) generate_scaling(in->p.bpc, data->uv_points[0], data->num_uv_points[0], scaling[1]); @@ -335,7 +335,8 @@ static int has_grain(const Dav1dPicture *const pic) { const Dav1dFilmGrainData *fgdata = &pic->frame_hdr->film_grain.data; return fgdata->num_y_points || fgdata->num_uv_points[0] || - fgdata->num_uv_points[1]; + fgdata->num_uv_points[1] || (fgdata->clip_to_restricted_range && + fgdata->chroma_scaling_from_luma); } static int output_image(Dav1dContext *const c, Dav1dPicture *const out) |