Path: blob/master/dep/ffmpeg/include/libavutil/film_grain_params.h
7640 views
/*1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718#ifndef AVUTIL_FILM_GRAIN_PARAMS_H19#define AVUTIL_FILM_GRAIN_PARAMS_H2021#include "frame.h"2223enum AVFilmGrainParamsType {24AV_FILM_GRAIN_PARAMS_NONE = 0,2526/**27* The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)28*/29AV_FILM_GRAIN_PARAMS_AV1,3031/**32* The union is valid when interpreted as AVFilmGrainH274Params (codec.h274)33*/34AV_FILM_GRAIN_PARAMS_H274,35};3637/**38* This structure describes how to handle film grain synthesis for AOM codecs.39*40* @note The struct must be allocated as part of AVFilmGrainParams using41* av_film_grain_params_alloc(). Its size is not a part of the public ABI.42*/43typedef struct AVFilmGrainAOMParams {44/**45* Number of points, and the scale and value for each point of the46* piecewise linear scaling function for the uma plane.47*/48int num_y_points;49uint8_t y_points[14][2 /* value, scaling */];5051/**52* Signals whether to derive the chroma scaling function from the luma.53* Not equivalent to copying the luma values and scales.54*/55int chroma_scaling_from_luma;5657/**58* If chroma_scaling_from_luma is set to 0, signals the chroma scaling59* function parameters.60*/61int num_uv_points[2 /* cb, cr */];62uint8_t uv_points[2 /* cb, cr */][10][2 /* value, scaling */];6364/**65* Specifies the shift applied to the chroma components. For AV1, its within66* [8; 11] and determines the range and quantization of the film grain.67*/68int scaling_shift;6970/**71* Specifies the auto-regression lag.72*/73int ar_coeff_lag;7475/**76* Luma auto-regression coefficients. The number of coefficients is given by77* 2 * ar_coeff_lag * (ar_coeff_lag + 1).78*/79int8_t ar_coeffs_y[24];8081/**82* Chroma auto-regression coefficients. The number of coefficients is given by83* 2 * ar_coeff_lag * (ar_coeff_lag + 1) + !!num_y_points.84*/85int8_t ar_coeffs_uv[2 /* cb, cr */][25];8687/**88* Specifies the range of the auto-regressive coefficients. Values of 6,89* 7, 8 and so on represent a range of [-2, 2), [-1, 1), [-0.5, 0.5) and90* so on. For AV1 must be between 6 and 9.91*/92int ar_coeff_shift;9394/**95* Signals the down shift applied to the generated gaussian numbers during96* synthesis.97*/98int grain_scale_shift;99100/**101* Specifies the luma/chroma multipliers for the index to the component102* scaling function.103*/104int uv_mult[2 /* cb, cr */];105int uv_mult_luma[2 /* cb, cr */];106107/**108* Offset used for component scaling function. For AV1 its a 9-bit value109* with a range [-256, 255]110*/111int uv_offset[2 /* cb, cr */];112113/**114* Signals whether to overlap film grain blocks.115*/116int overlap_flag;117118/**119* Signals to clip to limited color levels after film grain application.120*/121int limit_output_range;122} AVFilmGrainAOMParams;123124/**125* This structure describes how to handle film grain synthesis for codecs using126* the ITU-T H.274 Versatile supplemental enhancement information message.127*128* @note The struct must be allocated as part of AVFilmGrainParams using129* av_film_grain_params_alloc(). Its size is not a part of the public ABI.130*/131typedef struct AVFilmGrainH274Params {132/**133* Specifies the film grain simulation mode.134* 0 = Frequency filtering, 1 = Auto-regression135*/136int model_id;137138/**139* Specifies the blending mode used to blend the simulated film grain140* with the decoded images.141*142* 0 = Additive, 1 = Multiplicative143*/144int blending_mode_id;145146/**147* Specifies a scale factor used in the film grain characterization equations.148*/149int log2_scale_factor;150151/**152* Indicates if the modelling of film grain for a given component is present.153*/154int component_model_present[3 /* y, cb, cr */];155156/**157* Specifies the number of intensity intervals for which a specific set of158* model values has been estimated, with a range of [1, 256].159*/160uint16_t num_intensity_intervals[3 /* y, cb, cr */];161162/**163* Specifies the number of model values present for each intensity interval164* in which the film grain has been modelled, with a range of [1, 6].165*/166uint8_t num_model_values[3 /* y, cb, cr */];167168/**169* Specifies the lower ounds of each intensity interval for whichthe set of170* model values applies for the component.171*/172uint8_t intensity_interval_lower_bound[3 /* y, cb, cr */][256 /* intensity interval */];173174/**175* Specifies the upper bound of each intensity interval for which the set of176* model values applies for the component.177*/178uint8_t intensity_interval_upper_bound[3 /* y, cb, cr */][256 /* intensity interval */];179180/**181* Specifies the model values for the component for each intensity interval.182* - When model_id == 0, the following applies:183* For comp_model_value[y], the range of values is [0, 2^bit_depth_luma - 1]184* For comp_model_value[cb..cr], the range of values is [0, 2^bit_depth_chroma - 1]185* - Otherwise, the following applies:186* For comp_model_value[y], the range of values is [-2^(bit_depth_luma - 1), 2^(bit_depth_luma - 1) - 1]187* For comp_model_value[cb..cr], the range of values is [-2^(bit_depth_chroma - 1), 2^(bit_depth_chroma - 1) - 1]188*/189int16_t comp_model_value[3 /* y, cb, cr */][256 /* intensity interval */][6 /* model value */];190} AVFilmGrainH274Params;191192/**193* This structure describes how to handle film grain synthesis in video194* for specific codecs. Must be present on every frame where film grain is195* meant to be synthesised for correct presentation.196*197* @note The struct must be allocated with av_film_grain_params_alloc() and198* its size is not a part of the public ABI.199*/200typedef struct AVFilmGrainParams {201/**202* Specifies the codec for which this structure is valid.203*/204enum AVFilmGrainParamsType type;205206/**207* Seed to use for the synthesis process, if the codec allows for it.208*209* @note For H.264, this refers to `pic_offset` as defined in210* SMPTE RDD 5-2006.211*/212uint64_t seed;213214/**215* Intended display resolution. May be 0 if the codec does not specify216* any restrictions.217*/218219int width, height;220221/**222* Intended subsampling ratio, or 0 for luma-only streams.223*/224int subsampling_x, subsampling_y;225226/**227* Intended video signal characteristics.228*/229enum AVColorRange color_range;230enum AVColorPrimaries color_primaries;231enum AVColorTransferCharacteristic color_trc;232enum AVColorSpace color_space;233234/**235* Intended bit depth, or 0 for unknown/unspecified.236*/237int bit_depth_luma;238int bit_depth_chroma;239240/**241* Additional fields may be added both here and in any structure included.242* If a codec's film grain structure differs slightly over another243* codec's, fields within may change meaning depending on the type.244*/245union {246AVFilmGrainAOMParams aom;247AVFilmGrainH274Params h274;248} codec;249} AVFilmGrainParams;250251/**252* Allocate an AVFilmGrainParams structure and set its fields to253* default values. The resulting struct can be freed using av_freep().254* If size is not NULL it will be set to the number of bytes allocated.255*256* @return An AVFilmGrainParams filled with default values or NULL257* on failure.258*/259AVFilmGrainParams *av_film_grain_params_alloc(size_t *size);260261/**262* Allocate a complete AVFilmGrainParams and add it to the frame.263*264* @param frame The frame which side data is added to.265*266* @return The AVFilmGrainParams structure to be filled by caller.267*/268AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame);269270/**271* Select the most appropriate film grain parameters set for the frame,272* taking into account the frame's format, resolution and video signal273* characteristics.274*275* @note, for H.274, this may select a film grain parameter set with276* greater chroma resolution than the frame. Users should take care to277* correctly adjust the chroma grain frequency to the frame.278*/279const AVFilmGrainParams *av_film_grain_params_select(const AVFrame *frame);280281#endif /* AVUTIL_FILM_GRAIN_PARAMS_H */282283284