Commit 20e9f4df authored by Niklas Haas's avatar Niklas Haas Committed by Ronald S. Bultje

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).
parent df5230ef
...@@ -106,6 +106,26 @@ enum Dav1dChromaSamplePosition { ...@@ -106,6 +106,26 @@ enum Dav1dChromaSamplePosition {
DAV1D_CHR_COLOCATED = 2, ///< Co-located with luma(0, 0) sample 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 { typedef struct Dav1dPictureParameters {
int w; ///< width (in pixels) int w; ///< width (in pixels)
int h; ///< height (in pixels) int h; ///< height (in pixels)
...@@ -122,6 +142,8 @@ typedef struct Dav1dPictureParameters { ...@@ -122,6 +142,8 @@ typedef struct Dav1dPictureParameters {
* MPEG pixel range ([16,235] for 8bits luma, [16,240] for 8bits chroma). * MPEG pixel range ([16,235] for 8bits luma, [16,240] for 8bits chroma).
*/ */
int fullrange; int fullrange;
Dav1dFilmGrainData film_grain; ///< film grain parameters
} Dav1dPictureParameters; } Dav1dPictureParameters;
typedef struct Dav1dPicture { typedef struct Dav1dPicture {
......
...@@ -3099,6 +3099,7 @@ int dav1d_submit_frame(Dav1dContext *const c) { ...@@ -3099,6 +3099,7 @@ int dav1d_submit_frame(Dav1dContext *const c) {
f->sr_cur.p.poc = f->frame_hdr.frame_offset; 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.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.pri = f->seq_hdr.pri;
f->sr_cur.p.p.trc = f->seq_hdr.trc; f->sr_cur.p.p.trc = f->seq_hdr.trc;
f->sr_cur.p.p.mtrx = f->seq_hdr.mtrx; f->sr_cur.p.p.mtrx = f->seq_hdr.mtrx;
......
...@@ -97,7 +97,7 @@ struct Dav1dContext { ...@@ -97,7 +97,7 @@ struct Dav1dContext {
unsigned refpoc[7]; unsigned refpoc[7];
WarpedMotionParams gmv[7]; WarpedMotionParams gmv[7];
Av1LoopfilterModeRefDeltas lf_mode_ref_deltas; Av1LoopfilterModeRefDeltas lf_mode_ref_deltas;
Av1FilmGrainData film_grain; Dav1dFilmGrainData film_grain;
uint8_t qidx; uint8_t qidx;
unsigned coded_width; unsigned coded_width;
} refs[8]; } refs[8];
......
...@@ -391,25 +391,6 @@ typedef struct Av1LoopfilterModeRefDeltas { ...@@ -391,25 +391,6 @@ typedef struct Av1LoopfilterModeRefDeltas {
int ref_delta[8]; int ref_delta[8];
} Av1LoopfilterModeRefDeltas; } 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 { typedef struct Av1FrameHeader {
int show_existing_frame; int show_existing_frame;
int existing_frame_idx; int existing_frame_idx;
...@@ -503,8 +484,8 @@ typedef struct Av1FrameHeader { ...@@ -503,8 +484,8 @@ typedef struct Av1FrameHeader {
int reduced_txtp_set; int reduced_txtp_set;
WarpedMotionParams gmv[7]; WarpedMotionParams gmv[7];
struct { struct {
int present, update, seed; int present, update;
Av1FilmGrainData data; Dav1dFilmGrainData data;
} film_grain; } film_grain;
} Av1FrameHeader; } Av1FrameHeader;
......
...@@ -1008,7 +1008,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -1008,7 +1008,7 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) {
(hdr->show_frame || hdr->showable_frame) && (hdr->show_frame || hdr->showable_frame) &&
dav1d_get_bits(gb, 1); dav1d_get_bits(gb, 1);
if (hdr->film_grain.present) { 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); hdr->film_grain.update = hdr->frame_type != DAV1D_FRAME_TYPE_INTER || dav1d_get_bits(gb, 1);
if (!hdr->film_grain.update) { if (!hdr->film_grain.update) {
const int refidx = dav1d_get_bits(gb, 3); const int refidx = dav1d_get_bits(gb, 3);
...@@ -1018,8 +1018,10 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) { ...@@ -1018,8 +1018,10 @@ static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb) {
break; break;
if (i == 7) goto error; if (i == 7) goto error;
hdr->film_grain.data = c->refs[refidx].film_grain; hdr->film_grain.data = c->refs[refidx].film_grain;
hdr->film_grain.data.seed = seed;
} else { } 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); fgd->num_y_points = dav1d_get_bits(gb, 4);
if (fgd->num_y_points > 14) goto error; if (fgd->num_y_points > 14) goto error;
......
...@@ -126,6 +126,7 @@ static int picture_alloc_with_edges(Dav1dPicture *const p, ...@@ -126,6 +126,7 @@ static int picture_alloc_with_edges(Dav1dPicture *const p,
p->p.chr = DAV1D_CHR_UNKNOWN; p->p.chr = DAV1D_CHR_UNKNOWN;
p->p.layout = layout; p->p.layout = layout;
p->p.bpc = bpc; p->p.bpc = bpc;
p->p.film_grain = (Dav1dFilmGrainData) { 0 };
int res = p_allocator->alloc_picture_callback(p, p_allocator->cookie); int res = p_allocator->alloc_picture_callback(p, p_allocator->cookie);
if (res < 0) { if (res < 0) {
free(pic_ctx); free(pic_ctx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment