film_grain_params.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  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.
  8. *
  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.
  13. *
  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
  17. */
  18. #ifndef AVUTIL_FILM_GRAIN_PARAMS_H
  19. #define AVUTIL_FILM_GRAIN_PARAMS_H
  20. #include "frame.h"
  21. enum AVFilmGrainParamsType {
  22. AV_FILM_GRAIN_PARAMS_NONE = 0,
  23. /**
  24. * The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
  25. */
  26. AV_FILM_GRAIN_PARAMS_AV1,
  27. };
  28. /**
  29. * This structure describes how to handle film grain synthesis for AOM codecs.
  30. *
  31. * @note The struct must be allocated as part of AVFilmGrainParams using
  32. * av_film_grain_params_alloc(). Its size is not a part of the public ABI.
  33. */
  34. typedef struct AVFilmGrainAOMParams {
  35. /**
  36. * Number of points, and the scale and value for each point of the
  37. * piecewise linear scaling function for the uma plane.
  38. */
  39. int num_y_points;
  40. uint8_t y_points[14][2 /* value, scaling */];
  41. /**
  42. * Signals whether to derive the chroma scaling function from the luma.
  43. * Not equivalent to copying the luma values and scales.
  44. */
  45. int chroma_scaling_from_luma;
  46. /**
  47. * If chroma_scaling_from_luma is set to 0, signals the chroma scaling
  48. * function parameters.
  49. */
  50. int num_uv_points[2 /* cb, cr */];
  51. uint8_t uv_points[2 /* cb, cr */][10][2 /* value, scaling */];
  52. /**
  53. * Specifies the shift applied to the chroma components. For AV1, its within
  54. * [8; 11] and determines the range and quantization of the film grain.
  55. */
  56. int scaling_shift;
  57. /**
  58. * Specifies the auto-regression lag.
  59. */
  60. int ar_coeff_lag;
  61. /**
  62. * Luma auto-regression coefficients. The number of coefficients is given by
  63. * 2 * ar_coeff_lag * (ar_coeff_lag + 1).
  64. */
  65. int8_t ar_coeffs_y[24];
  66. /**
  67. * Chroma auto-regression coefficients. The number of coefficients is given by
  68. * 2 * ar_coeff_lag * (ar_coeff_lag + 1) + !!num_y_points.
  69. */
  70. int8_t ar_coeffs_uv[2 /* cb, cr */][25];
  71. /**
  72. * Specifies the range of the auto-regressive coefficients. Values of 6,
  73. * 7, 8 and so on represent a range of [-2, 2), [-1, 1), [-0.5, 0.5) and
  74. * so on. For AV1 must be between 6 and 9.
  75. */
  76. int ar_coeff_shift;
  77. /**
  78. * Signals the down shift applied to the generated gaussian numbers during
  79. * synthesis.
  80. */
  81. int grain_scale_shift;
  82. /**
  83. * Specifies the luma/chroma multipliers for the index to the component
  84. * scaling function.
  85. */
  86. int uv_mult[2 /* cb, cr */];
  87. int uv_mult_luma[2 /* cb, cr */];
  88. /**
  89. * Offset used for component scaling function. For AV1 its a 9-bit value
  90. * with a range [-256, 255]
  91. */
  92. int uv_offset[2 /* cb, cr */];
  93. /**
  94. * Signals whether to overlap film grain blocks.
  95. */
  96. int overlap_flag;
  97. /**
  98. * Signals to clip to limited color levels after film grain application.
  99. */
  100. int limit_output_range;
  101. } AVFilmGrainAOMParams;
  102. /**
  103. * This structure describes how to handle film grain synthesis in video
  104. * for specific codecs. Must be present on every frame where film grain is
  105. * meant to be synthesised for correct presentation.
  106. *
  107. * @note The struct must be allocated with av_film_grain_params_alloc() and
  108. * its size is not a part of the public ABI.
  109. */
  110. typedef struct AVFilmGrainParams {
  111. /**
  112. * Specifies the codec for which this structure is valid.
  113. */
  114. enum AVFilmGrainParamsType type;
  115. /**
  116. * Seed to use for the synthesis process, if the codec allows for it.
  117. */
  118. uint64_t seed;
  119. /**
  120. * Additional fields may be added both here and in any structure included.
  121. * If a codec's film grain structure differs slightly over another
  122. * codec's, fields within may change meaning depending on the type.
  123. */
  124. union {
  125. AVFilmGrainAOMParams aom;
  126. } codec;
  127. } AVFilmGrainParams;
  128. /**
  129. * Allocate an AVFilmGrainParams structure and set its fields to
  130. * default values. The resulting struct can be freed using av_freep().
  131. * If size is not NULL it will be set to the number of bytes allocated.
  132. *
  133. * @return An AVFilmGrainParams filled with default values or NULL
  134. * on failure.
  135. */
  136. AVFilmGrainParams *av_film_grain_params_alloc(size_t *size);
  137. /**
  138. * Allocate a complete AVFilmGrainParams and add it to the frame.
  139. *
  140. * @param frame The frame which side data is added to.
  141. *
  142. * @return The AVFilmGrainParams structure to be filled by caller.
  143. */
  144. AVFilmGrainParams *av_film_grain_params_create_side_data(AVFrame *frame);
  145. #endif /* AVUTIL_FILM_GRAIN_PARAMS_H */