ref: 20e9f4df68761e48d44d134ba942e4ecc11446b7
parent: df5230ef7656899f28e21792b0f903a4af4ee3ff
author: Niklas Haas <[email protected]>
date: Tue Nov 13 11:52:46 EST 2018
picture: make the film grain metadata public This becomes part of the picture properties, since users may want to apply film grain themselves (e.g. for a GPU implementation).
--- a/include/dav1d/picture.h
+++ b/include/dav1d/picture.h
@@ -106,6 +106,26 @@
DAV1D_CHR_COLOCATED = 2, ///< Co-located with luma(0, 0) sample
};
+typedef struct Dav1dFilmGrainData {
+ uint16_t seed;
+ int num_y_points;
+ uint8_t y_points[14][2 /* value, scaling */];
+ int chroma_scaling_from_luma;
+ int num_uv_points[2];
+ uint8_t uv_points[2][10][2 /* value, scaling */];
+ int scaling_shift;
+ int ar_coeff_lag;
+ int8_t ar_coeffs_y[24];
+ int8_t ar_coeffs_uv[2][25];
+ int ar_coeff_shift;
+ int grain_scale_shift;
+ int8_t uv_mult[2];
+ int8_t uv_luma_mult[2];
+ int16_t uv_offset[2];
+ int overlap_flag;
+ int clip_to_restricted_range;
+} Dav1dFilmGrainData;
+
typedef struct Dav1dPictureParameters {
int w; ///< width (in pixels)
int h; ///< height (in pixels)
@@ -122,6 +142,8 @@
* MPEG pixel range ([16,235] for 8bits luma, [16,240] for 8bits chroma).
*/
int fullrange;
+
+ Dav1dFilmGrainData film_grain; ///< film grain parameters
} Dav1dPictureParameters;
typedef struct Dav1dPicture {
--- a/src/decode.c
+++ b/src/decode.c
@@ -3099,6 +3099,7 @@
f->sr_cur.p.poc = f->frame_hdr.frame_offset;
f->sr_cur.p.p.type = f->frame_hdr.frame_type;
+ f->sr_cur.p.p.film_grain = f->frame_hdr.film_grain.data;
f->sr_cur.p.p.pri = f->seq_hdr.pri;
f->sr_cur.p.p.trc = f->seq_hdr.trc;
f->sr_cur.p.p.mtrx = f->seq_hdr.mtrx;
--- a/src/internal.h
+++ b/src/internal.h
@@ -97,7 +97,7 @@
unsigned refpoc[7];
WarpedMotionParams gmv[7];
Av1LoopfilterModeRefDeltas lf_mode_ref_deltas;
- Av1FilmGrainData film_grain;
+ Dav1dFilmGrainData film_grain;
uint8_t qidx;
unsigned coded_width;
} refs[8];
--- a/src/levels.h
+++ b/src/levels.h
@@ -391,25 +391,6 @@
int ref_delta[8];
} Av1LoopfilterModeRefDeltas;
-typedef struct Av1FilmGrainData {
- int num_y_points;
- uint8_t y_points[14][2 /* value, scaling */];
- int chroma_scaling_from_luma;
- int num_uv_points[2];
- uint8_t uv_points[2][10][2 /* value, scaling */];
- int scaling_shift;
- int ar_coeff_lag;
- int8_t ar_coeffs_y[24];
- int8_t ar_coeffs_uv[2][25];
- int ar_coeff_shift;
- int grain_scale_shift;
- int8_t uv_mult[2];
- int8_t uv_luma_mult[2];
- int16_t uv_offset[2];
- int overlap_flag;
- int clip_to_restricted_range;
-} Av1FilmGrainData;
-
typedef struct Av1FrameHeader {
int show_existing_frame;
int existing_frame_idx;
@@ -503,8 +484,8 @@
int reduced_txtp_set;
WarpedMotionParams gmv[7];
struct {
- int present, update, seed;
- Av1FilmGrainData data;
+ int present, update;
+ Dav1dFilmGrainData data;
} film_grain;
} Av1FrameHeader;
--- a/src/obu.c
+++ b/src/obu.c
@@ -1008,7 +1008,7 @@
(hdr->show_frame || hdr->showable_frame) &&
dav1d_get_bits(gb, 1);
if (hdr->film_grain.present) {
- hdr->film_grain.seed = dav1d_get_bits(gb, 16);
+ const unsigned seed = dav1d_get_bits(gb, 16);
hdr->film_grain.update = hdr->frame_type != DAV1D_FRAME_TYPE_INTER || dav1d_get_bits(gb, 1);
if (!hdr->film_grain.update) {
const int refidx = dav1d_get_bits(gb, 3);
@@ -1018,8 +1018,10 @@
break;
if (i == 7) goto error;
hdr->film_grain.data = c->refs[refidx].film_grain;
+ hdr->film_grain.data.seed = seed;
} else {
- Av1FilmGrainData *const fgd = &hdr->film_grain.data;
+ Dav1dFilmGrainData *const fgd = &hdr->film_grain.data;
+ fgd->seed = seed;
fgd->num_y_points = dav1d_get_bits(gb, 4);
if (fgd->num_y_points > 14) goto error;
--- a/src/picture.c
+++ b/src/picture.c
@@ -126,6 +126,7 @@
p->p.chr = DAV1D_CHR_UNKNOWN;
p->p.layout = layout;
p->p.bpc = bpc;
+ p->p.film_grain = (Dav1dFilmGrainData) { 0 };
int res = p_allocator->alloc_picture_callback(p, p_allocator->cookie);
if (res < 0) {
free(pic_ctx);