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