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 12 /*!\file 13 * \brief Describes film grain parameters and film grain synthesis 14 * 15 */ 16 #ifndef AOM_AOM_DSP_GRAIN_SYNTHESIS_H_ 17 #define AOM_AOM_DSP_GRAIN_SYNTHESIS_H_ 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #include "aom_dsp/aom_dsp_common.h" 24 #include "aom/aom_image.h" 25 26 /*!\brief Structure containing film grain synthesis parameters for a frame 27 * 28 * This structure contains input parameters for film grain synthesis 29 */ 30 typedef struct { 31 int apply_grain; 32 33 int update_parameters; 34 35 // 8 bit values 36 int scaling_points_y[14][2]; 37 int num_y_points; // value: 0..14 38 39 // 8 bit values 40 int scaling_points_cb[10][2]; 41 int num_cb_points; // value: 0..10 42 43 // 8 bit values 44 int scaling_points_cr[10][2]; 45 int num_cr_points; // value: 0..10 46 47 int scaling_shift; // values : 8..11 48 49 int ar_coeff_lag; // values: 0..3 50 51 // 8 bit values 52 int ar_coeffs_y[24]; 53 int ar_coeffs_cb[25]; 54 int ar_coeffs_cr[25]; 55 56 // Shift value: AR coeffs range 57 // 6: [-2, 2) 58 // 7: [-1, 1) 59 // 8: [-0.5, 0.5) 60 // 9: [-0.25, 0.25) 61 int ar_coeff_shift; // values : 6..9 62 63 int cb_mult; // 8 bits 64 int cb_luma_mult; // 8 bits 65 int cb_offset; // 9 bits 66 67 int cr_mult; // 8 bits 68 int cr_luma_mult; // 8 bits 69 int cr_offset; // 9 bits 70 71 int overlap_flag; 72 73 int clip_to_restricted_range; 74 75 unsigned int bit_depth; // video bit depth 76 77 int chroma_scaling_from_luma; 78 79 int grain_scale_shift; 80 81 uint16_t random_seed; 82 } aom_film_grain_t; 83 84 /*!\brief Add film grain 85 * 86 * Add film grain to an image 87 * 88 * Returns 0 for success, -1 for failure 89 * 90 * \param[in] grain_params Grain parameters 91 * \param[in] luma luma plane 92 * \param[in] cb cb plane 93 * \param[in] cr cr plane 94 * \param[in] height luma plane height 95 * \param[in] width luma plane width 96 * \param[in] luma_stride luma plane stride 97 * \param[in] chroma_stride chroma plane stride 98 */ 99 int av1_add_film_grain_run(const aom_film_grain_t *grain_params, uint8_t *luma, 100 uint8_t *cb, uint8_t *cr, int height, int width, 101 int luma_stride, int chroma_stride, 102 int use_high_bit_depth, int chroma_subsamp_y, 103 int chroma_subsamp_x, int mc_identity); 104 105 /*!\brief Add film grain 106 * 107 * Add film grain to an image 108 * 109 * Returns 0 for success, -1 for failure 110 * 111 * \param[in] grain_params Grain parameters 112 * \param[in] src Source image 113 * \param[out] dst Resulting image with grain 114 */ 115 int av1_add_film_grain(const aom_film_grain_t *grain_params, 116 const aom_image_t *src, aom_image_t *dst); 117 118 #ifdef __cplusplus 119 } // extern "C" 120 #endif 121 122 #endif // AOM_AOM_DSP_GRAIN_SYNTHESIS_H_ 123