grain_params.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) 2016, Alliance for Open Media. All rights reserved
  3. *
  4. * This source code is subject to the terms of the BSD 2 Clause License and
  5. * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
  6. * was not distributed with this source code in the LICENSE file, you can
  7. * obtain it at www.aomedia.org/license/software. If the Alliance for Open
  8. * Media Patent License 1.0 was not distributed with this source code in the
  9. * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
  10. */
  11. /*!\file
  12. * \brief Describes film grain parameters
  13. *
  14. */
  15. #ifndef AOM_AOM_DSP_GRAIN_PARAMS_H_
  16. #define AOM_AOM_DSP_GRAIN_PARAMS_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include <stdint.h>
  21. #include <string.h>
  22. #include "config/aom_config.h"
  23. /*!\brief Structure containing film grain synthesis parameters for a frame
  24. *
  25. * This structure contains input parameters for film grain synthesis
  26. */
  27. typedef struct {
  28. // This structure is compared element-by-element in the function
  29. // aom_check_grain_params_equiv: this function must be updated if any changes
  30. // are made to this structure.
  31. int apply_grain;
  32. int update_parameters;
  33. // 8 bit values
  34. int scaling_points_y[14][2];
  35. int num_y_points; // value: 0..14
  36. // 8 bit values
  37. int scaling_points_cb[10][2];
  38. int num_cb_points; // value: 0..10
  39. // 8 bit values
  40. int scaling_points_cr[10][2];
  41. int num_cr_points; // value: 0..10
  42. int scaling_shift; // values : 8..11
  43. int ar_coeff_lag; // values: 0..3
  44. // 8 bit values
  45. int ar_coeffs_y[24];
  46. int ar_coeffs_cb[25];
  47. int ar_coeffs_cr[25];
  48. // Shift value: AR coeffs range
  49. // 6: [-2, 2)
  50. // 7: [-1, 1)
  51. // 8: [-0.5, 0.5)
  52. // 9: [-0.25, 0.25)
  53. int ar_coeff_shift; // values : 6..9
  54. int cb_mult; // 8 bits
  55. int cb_luma_mult; // 8 bits
  56. int cb_offset; // 9 bits
  57. int cr_mult; // 8 bits
  58. int cr_luma_mult; // 8 bits
  59. int cr_offset; // 9 bits
  60. int overlap_flag;
  61. int clip_to_restricted_range;
  62. unsigned int bit_depth; // video bit depth
  63. int chroma_scaling_from_luma;
  64. int grain_scale_shift;
  65. uint16_t random_seed;
  66. // This structure is compared element-by-element in the function
  67. // aom_check_grain_params_equiv: this function must be updated if any changes
  68. // are made to this structure.
  69. } aom_film_grain_t;
  70. /*!\brief Check if two film grain parameters structs are equivalent
  71. *
  72. * Check if two film grain parameters are equal, except for the
  73. * update_parameters and random_seed elements which are ignored.
  74. *
  75. * \param[in] pa The first set of parameters to compare
  76. * \param[in] pb The second set of parameters to compare
  77. * \return Returns 1 if the params are equivalent, 0 otherwise
  78. */
  79. static INLINE int aom_check_grain_params_equiv(
  80. const aom_film_grain_t *const pa, const aom_film_grain_t *const pb) {
  81. if (pa->apply_grain != pb->apply_grain) return 0;
  82. // Don't compare update_parameters
  83. if (pa->num_y_points != pb->num_y_points) return 0;
  84. if (memcmp(pa->scaling_points_y, pb->scaling_points_y,
  85. pa->num_y_points * 2 * sizeof(*pa->scaling_points_y)) != 0)
  86. return 0;
  87. if (pa->num_cb_points != pb->num_cb_points) return 0;
  88. if (memcmp(pa->scaling_points_cb, pb->scaling_points_cb,
  89. pa->num_cb_points * 2 * sizeof(*pa->scaling_points_cb)) != 0)
  90. return 0;
  91. if (pa->num_cr_points != pb->num_cr_points) return 0;
  92. if (memcmp(pa->scaling_points_cr, pb->scaling_points_cr,
  93. pa->num_cr_points * 2 * sizeof(*pa->scaling_points_cr)) != 0)
  94. return 0;
  95. if (pa->scaling_shift != pb->scaling_shift) return 0;
  96. if (pa->ar_coeff_lag != pb->ar_coeff_lag) return 0;
  97. const int num_pos = 2 * pa->ar_coeff_lag * (pa->ar_coeff_lag + 1);
  98. if (memcmp(pa->ar_coeffs_y, pb->ar_coeffs_y,
  99. num_pos * sizeof(*pa->ar_coeffs_y)) != 0)
  100. return 0;
  101. if (memcmp(pa->ar_coeffs_cb, pb->ar_coeffs_cb,
  102. num_pos * sizeof(*pa->ar_coeffs_cb)) != 0)
  103. return 0;
  104. if (memcmp(pa->ar_coeffs_cr, pb->ar_coeffs_cr,
  105. num_pos * sizeof(*pa->ar_coeffs_cr)) != 0)
  106. return 0;
  107. if (pa->ar_coeff_shift != pb->ar_coeff_shift) return 0;
  108. if (pa->cb_mult != pb->cb_mult) return 0;
  109. if (pa->cb_luma_mult != pb->cb_luma_mult) return 0;
  110. if (pa->cb_offset != pb->cb_offset) return 0;
  111. if (pa->cr_mult != pb->cr_mult) return 0;
  112. if (pa->cr_luma_mult != pb->cr_luma_mult) return 0;
  113. if (pa->cr_offset != pb->cr_offset) return 0;
  114. if (pa->overlap_flag != pb->overlap_flag) return 0;
  115. if (pa->clip_to_restricted_range != pb->clip_to_restricted_range) return 0;
  116. if (pa->bit_depth != pb->bit_depth) return 0;
  117. if (pa->chroma_scaling_from_luma != pb->chroma_scaling_from_luma) return 0;
  118. if (pa->grain_scale_shift != pb->grain_scale_shift) return 0;
  119. return 1;
  120. }
  121. #ifdef __cplusplus
  122. } // extern "C"
  123. #endif
  124. #endif // AOM_AOM_DSP_GRAIN_PARAMS_H_