2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVUTIL_FILM_GRAIN_PARAMS_H
20 #define AVUTIL_FILM_GRAIN_PARAMS_H
24 enum AVFilmGrainParamsType {
25 AV_FILM_GRAM_PARAMS_NONE = 0,
28 * The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
30 AV_FILM_GRAM_PARAMS_AV1,
34 * This structure describes how to handle film grain synthesis for AOM codecs.
36 * @note The struct must be allocated as part of AVFilmGrainParams using
37 * av_film_grain_params_alloc(). Its size is not a part of the public ABI.
39 typedef struct AVFilmGrainAOMParams {
41 * Number of points, and the scale and value for each point of the
42 * piecewise linear scaling function for the uma plane.
45 uint8_t y_points[14][2 /* value, scaling */];
48 * Signals whether to derive the chroma scaling function from the luma.
49 * Not equivalent to copying the luma values and scales.
51 int chroma_scaling_from_luma;
54 * If chroma_scaling_from_luma is set to 0, signals the chroma scaling
55 * function parameters.
58 uint8_t uv_points[2][10][2 /* value, scaling */];
61 * Specifies the shift applied to the chroma components. For AV1, its within
62 * [8; 11] and determines the range and quantization of the film grain.
67 * Specifies the auto-regression lag. The number of coefficients is given by
68 * 2*ar_coeff_lag(ar_coeff_lag - 1), with an extra one for the chroma.
73 * Luma auto-regression coefficients.
75 int8_t ar_coeffs_y[24];
78 * Chroma auto-regression coefficients.
80 int8_t ar_coeffs_uv[2][25];
83 * Specifies the range of the auto-regressive coefficients. Values of 6,
84 * 7, 8 and so on represent a range of [-2, 2), [-1, 1), [-0.5, 0.5) and
85 * so on. For AV1 must be between 6 and 9.
90 * Signals the down shift applied to the generated gaussian numbers during
93 int grain_scale_shift;
96 * Specifies the luma/chroma multipliers for the index to the component
103 * Offset used for component scaling function. For AV1 its a 9-bit value
104 * with a range [-256, 255]
109 * Signals whether to overlap film grain blocks.
114 * Signals to clip to limited color levels after film grain application.
116 int limit_output_range;
117 } AVFilmGrainAOMParams;
120 * This structure describes how to handle film grain synthesis in video
121 * for specific codecs. Must be present on every frame where film grain is
122 * meant to be synthesised for correct presentation.
124 * @note The struct must be allocated with av_film_grain_params_alloc() and
125 * its size is not a part of the public ABI.
127 typedef struct AVFilmGrainParams {
129 * Specifies the codec for which this structure is valid.
131 enum AVFilmGrainParamsType type;
134 * Seed to use for the synthesis process, if the codec allows for it.
139 * Additional fields may be added both here and in any structure included.
140 * If a codec's film grain structure differs slightly over another
141 * codec's, fields within may change meaning depending on the type.
144 AVFilmGrainAOMParams aom;
149 * Allocate an AVFilmGrainParams structure and set its fields to
150 * default values. The resulting struct can be freed using av_freep().
151 * If size is not NULL it will be set to the number of bytes allocated.
153 * @return An AVFilmGrainParams filled with default values or NULL
156 AVFilmGrainParams *av_film_grain_params_alloc(size_t *size);
159 * Allocate a complete AVFilmGrainParams and add it to the frame.
161 * @param frame The frame which side data is added to.
163 * @return The AVFilmGrainParams structure to be filled by caller.
165 AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame);
167 #endif /* AVUTIL_FILM_GRAIN_PARAMS_H */