Path: blob/master/dep/ffmpeg/include/libavutil/film_grain_params.h
4216 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 suplemental 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#if FF_API_H274_FILM_GRAIN_VCS139/**140* TODO: On this ABI bump, please also re-order the fields in141* AVFilmGrainParams (see below)142*/143144/**145* Specifies the bit depth used for the luma component.146*147* @deprecated use AVFilmGrainParams.bit_depth_luma.148*/149attribute_deprecated150int bit_depth_luma;151152/**153* Specifies the bit depth used for the chroma components.154*155* @deprecated use AVFilmGrainParams.bit_depth_chroma.156*/157attribute_deprecated158int bit_depth_chroma;159160/**161* Specifies the video signal characteristics.162*163* @deprecated use AVFilmGrainParams.color_{range,primaries,trc,space}.164*/165attribute_deprecated166enum AVColorRange color_range;167attribute_deprecated168enum AVColorPrimaries color_primaries;169attribute_deprecated170enum AVColorTransferCharacteristic color_trc;171attribute_deprecated172enum AVColorSpace color_space;173#endif174175/**176* Specifies the blending mode used to blend the simulated film grain177* with the decoded images.178*179* 0 = Additive, 1 = Multiplicative180*/181int blending_mode_id;182183/**184* Specifies a scale factor used in the film grain characterization equations.185*/186int log2_scale_factor;187188/**189* Indicates if the modelling of film grain for a given component is present.190*/191int component_model_present[3 /* y, cb, cr */];192193/**194* Specifies the number of intensity intervals for which a specific set of195* model values has been estimated, with a range of [1, 256].196*/197uint16_t num_intensity_intervals[3 /* y, cb, cr */];198199/**200* Specifies the number of model values present for each intensity interval201* in which the film grain has been modelled, with a range of [1, 6].202*/203uint8_t num_model_values[3 /* y, cb, cr */];204205/**206* Specifies the lower ounds of each intensity interval for whichthe set of207* model values applies for the component.208*/209uint8_t intensity_interval_lower_bound[3 /* y, cb, cr */][256 /* intensity interval */];210211/**212* Specifies the upper bound of each intensity interval for which the set of213* model values applies for the component.214*/215uint8_t intensity_interval_upper_bound[3 /* y, cb, cr */][256 /* intensity interval */];216217/**218* Specifies the model values for the component for each intensity interval.219* - When model_id == 0, the following applies:220* For comp_model_value[y], the range of values is [0, 2^bit_depth_luma - 1]221* For comp_model_value[cb..cr], the range of values is [0, 2^bit_depth_chroma - 1]222* - Otherwise, the following applies:223* For comp_model_value[y], the range of values is [-2^(bit_depth_luma - 1), 2^(bit_depth_luma - 1) - 1]224* For comp_model_value[cb..cr], the range of values is [-2^(bit_depth_chroma - 1), 2^(bit_depth_chroma - 1) - 1]225*/226int16_t comp_model_value[3 /* y, cb, cr */][256 /* intensity interval */][6 /* model value */];227} AVFilmGrainH274Params;228229/**230* This structure describes how to handle film grain synthesis in video231* for specific codecs. Must be present on every frame where film grain is232* meant to be synthesised for correct presentation.233*234* @note The struct must be allocated with av_film_grain_params_alloc() and235* its size is not a part of the public ABI.236*/237typedef struct AVFilmGrainParams {238/**239* Specifies the codec for which this structure is valid.240*/241enum AVFilmGrainParamsType type;242243/**244* Seed to use for the synthesis process, if the codec allows for it.245*246* @note For H.264, this refers to `pic_offset` as defined in247* SMPTE RDD 5-2006.248*/249uint64_t seed;250251/**252* Additional fields may be added both here and in any structure included.253* If a codec's film grain structure differs slightly over another254* codec's, fields within may change meaning depending on the type.255*256* TODO: Move this to the end of the structure, at the next ABI bump.257*/258union {259AVFilmGrainAOMParams aom;260AVFilmGrainH274Params h274;261} codec;262263/**264* Intended display resolution. May be 0 if the codec does not specify265* any restrictions.266*/267268int width, height;269270/**271* Intended subsampling ratio, or 0 for luma-only streams.272*/273int subsampling_x, subsampling_y;274275/**276* Intended video signal characteristics.277*/278enum AVColorRange color_range;279enum AVColorPrimaries color_primaries;280enum AVColorTransferCharacteristic color_trc;281enum AVColorSpace color_space;282283/**284* Intended bit depth, or 0 for unknown/unspecified.285*/286int bit_depth_luma;287int bit_depth_chroma;288289} AVFilmGrainParams;290291/**292* Allocate an AVFilmGrainParams structure and set its fields to293* default values. The resulting struct can be freed using av_freep().294* If size is not NULL it will be set to the number of bytes allocated.295*296* @return An AVFilmGrainParams filled with default values or NULL297* on failure.298*/299AVFilmGrainParams *av_film_grain_params_alloc(size_t *size);300301/**302* Allocate a complete AVFilmGrainParams and add it to the frame.303*304* @param frame The frame which side data is added to.305*306* @return The AVFilmGrainParams structure to be filled by caller.307*/308AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame);309310/**311* Select the most appropriate film grain parameters set for the frame,312* taking into account the frame's format, resolution and video signal313* characteristics.314*315* @note, for H.274, this may select a film grain parameter set with316* greater chroma resolution than the frame. Users should take care to317* correctly adjust the chroma grain frequency to the frame.318*/319const AVFilmGrainParams *av_film_grain_params_select(const AVFrame *frame);320321#endif /* AVUTIL_FILM_GRAIN_PARAMS_H */322323324