libvmaf
Loading...
Searching...
No Matches
integer_adm.h
Go to the documentation of this file.
1#ifndef FEATURE_ADM_H_
2#define FEATURE_ADM_H_
3
4#include "mem.h"
5#include "stdio.h"
6#include <errno.h>
7#include <math.h>
8#include <stdint.h>
9#include <string.h>
10
11static int32_t div_lookup[65537];
12static const int32_t div_Q_factor = 1073741824; // 2^30
13
14static inline void div_lookup_generator() {
15 for (int i = 1; i <= 32768; ++i) {
16 int32_t recip = (int32_t)(div_Q_factor / i);
17 div_lookup[32768 + i] = recip;
18 div_lookup[32768 - i] = 0 - recip;
19 }
20}
21
22typedef struct adm_dwt_band_t {
23 int16_t *band_a; /* Low-pass V + low-pass H. */
24 int16_t *band_v; /* Low-pass V + high-pass H. */
25 int16_t *band_h; /* High-pass V + low-pass H. */
26 int16_t *band_d; /* High-pass V + high-pass H. */
28
29typedef struct i4_adm_dwt_band_t {
30 int32_t *band_a; /* Low-pass V + low-pass H. */
31 int32_t *band_v; /* Low-pass V + high-pass H. */
32 int32_t *band_h; /* High-pass V + low-pass H. */
33 int32_t *band_d; /* High-pass V + high-pass H. */
35
36typedef struct AdmBuffer {
37 size_t ind_size_x, ind_size_y; // strides size for intermidate buffers
38 void *data_buf; // buffer for adm intermidiate data calculations
39 void *tmp_ref; // buffer for adm intermidiate data calculations
40 void *buf_x_orig; // buffer for storing imgcoeff values along x.
41 void *buf_y_orig; // buffer for storing imgcoeff values along y.
42 int *ind_y[4], *ind_x[4];
43
50
57} AdmBuffer;
58
59#ifndef NUM_BUFS_ADM
60#define NUM_BUFS_ADM 30
61#endif
62
63#ifndef M_PI
64#define M_PI 3.14159265358979323846264338327
65#endif // M_PI
66
67/* Enhancement gain imposed on adm, must be >= 1.0, where 1.0 means the gain is completely disabled */
68#ifndef DEFAULT_ADM_ENHN_GAIN_LIMIT
69#define DEFAULT_ADM_ENHN_GAIN_LIMIT (100.0)
70#endif // !DEFAULT_ADM_ENHN_GAIN_LIMIT
71
72#ifndef DEFAULT_ADM_NORM_VIEW_DIST
73#define DEFAULT_ADM_NORM_VIEW_DIST (3.0)
74#endif // !DEFAULT_ADM_NORM_VIEW_DIST
75
76#ifndef DEFAULT_ADM_REF_DISPLAY_HEIGHT
77#define DEFAULT_ADM_REF_DISPLAY_HEIGHT (1080)
78#endif // !DEFAULT_ADM_REF_DISPLAY_HEIGHT
79
80#ifndef ADM_BORDER_FACTOR
81#define ADM_BORDER_FACTOR (0.1)
82#endif // !ADM_BORDER_FACTOR
83
84/* noise multiplicative weight */
85#ifndef DEFAULT_ADM_NOISE_WEIGHT
86#define DEFAULT_ADM_NOISE_WEIGHT (0.03125)
87#endif // !DEFAULT_ADM_NOISE_WEIGHT
88
89/* CSF scale factor */
90#ifndef DEFAULT_ADM_CSF_SCALE
91#define DEFAULT_ADM_CSF_SCALE (1.0)
92#endif // !DEFAULT_ADM_CSF_SCALE
93
94/* CSF diagonal scale factor */
95#ifndef DEFAULT_ADM_CSF_DIAG_SCALE
96#define DEFAULT_ADM_CSF_DIAG_SCALE (1.0)
97#endif // !DEFAULT_ADM_CSF_DIAG_SCALE
98
99/* Default minimum value allowed for the feature */
100#ifndef DEFAULT_ADM_MIN_VAL
101#define DEFAULT_ADM_MIN_VAL (0.0)
102#endif // !DEFAULT_ADM_MIN_VAL
103
104/* Contrast sensitivity function */
111
112/* Default contrast sensitivity function */
113#ifndef DEFAULT_ADM_CSF_MODE
114#define DEFAULT_ADM_CSF_MODE (ADM_CSF_MODE_WATSON97)
115#endif // !DEFAULT_ADM_CSF_MODE
116
117/* Default luminance level (in cd/m2) for contrast sensitivity function calculation */
118#ifndef DEFAULT_ADM_CSF_LUM
119#define DEFAULT_ADM_CSF_LUM (100.0)
120#endif // !DEFAULT_ADM_CSF_LUM
121
122#define DIVS(n, d) ((n) / (d))
123
124static const int16_t dwt2_db2_coeffs_lo[10] = {15826, 27411, 7345, -4240};
125static const int16_t dwt2_db2_coeffs_hi[10] = {-4240, -7345, 27411, -15826};
126
127static const int32_t dwt2_db2_coeffs_lo_sum = 46342;
128static const int32_t dwt2_db2_coeffs_hi_sum = 0;
129
130#ifndef ONE_BY_15
131#define ONE_BY_15 8738
132#endif
133
134#ifndef I4_ONE_BY_15
135#define I4_ONE_BY_15 286331153
136#endif
137
138/* ================= */
139/* Noise floor model */
140/* ================= */
141
142/*
143 * The following dwt visibility threshold parameters are taken from
144 * "Visibility of Wavelet Quantization Noise"
145 * by A. B. Watson, G. Y. Yang, J. A. Solomon and J. Villasenor
146 * IEEE Trans. on Image Processing, Vol. 6, No 8, Aug. 1997
147 * Page 1170, formula (7) and corresponding Table IV
148 * Table IV has 2 entries for Cb and Cr thresholds
149 * Chose those corresponding to subject "sfl" since they are lower
150 * These thresholds were obtained and modeled for the 7-9 biorthogonal wavelet
151 * basis
152 */
153
154/*
155 * The following dwt visibility threshold parameters are taken from
156 * "Visibility of Wavelet Quantization Noise"
157 * by A. B. Watson, G. Y. Yang, J. A. Solomon and J. Villasenor
158 * IEEE Trans. on Image Processing, Vol. 6, No 8, Aug. 1997
159 * Page 1170, formula (7) and corresponding Table IV
160 * Table IV has 2 entries for Cb and Cr thresholds
161 * Chose those corresponding to subject "sfl" since they are lower
162 * These thresholds were obtained and modeled for the 7-9 biorthogonal wavelet
163 * basis
164 */
165struct dwt_model_params {
166 float a;
167 float k;
168 float f0;
169 float g[4];
170};
171
172// 0 -> Y, 1 -> Cb, 2 -> Cr
173static const struct dwt_model_params dwt_7_9_YCbCr_threshold[3] = {
174 {.a = 0.495, .k = 0.466, .f0 = 0.401, .g = {1.501, 1.0, 0.534, 1.0}},
175 {.a = 1.633, .k = 0.353, .f0 = 0.209, .g = {1.520, 1.0, 0.502, 1.0}},
176 {.a = 0.944, .k = 0.521, .f0 = 0.404, .g = {1.868, 1.0, 0.516, 1.0}}};
177
178/*
179 * The following dwt basis function amplitudes, A(lambda,theta), are taken from
180 * "Visibility of Wavelet Quantization Noise"
181 * by A. B. Watson, G. Y. Yang, J. A. Solomon and J. Villasenor
182 * IEEE Trans. on Image Processing, Vol. 6, No 8, Aug. 1997
183 * Page 1172, Table V
184 * The table has been transposed, i.e. it can be used directly to obtain
185 * A[lambda][theta]
186 * These amplitudes were calculated for the 7-9 biorthogonal wavelet basis
187 */
188static const float dwt_7_9_basis_function_amplitudes[6][4] = {
189 {0.62171, 0.67234, 0.72709, 0.67234},
190 {0.34537, 0.41317, 0.49428, 0.41317},
191 {0.18004, 0.22727, 0.28688, 0.22727},
192 {0.091401, 0.11792, 0.15214, 0.11792},
193 {0.045943, 0.059758, 0.077727, 0.059758},
194 {0.023013, 0.030018, 0.039156, 0.030018}};
195
196#endif /* _FEATURE_ADM_H_ */
ADM_CSF_MODE
Definition adm_options.h:55
@ ADM_CSF_MODE_WATSON97
Definition adm_options.h:56
@ ADM_CSF_MODE_BARTEN
Definition adm_options.h:57
@ ADM_CSF_MODE_BARTEN_WATSON_BLEND_MAE
Definition integer_adm.h:109
@ ADM_CSF_MODE_BARTEN_WATSON_BLEND
Definition integer_adm.h:108
Definition integer_adm.h:36
i4_adm_dwt_band_t i4_decouple_r
Definition integer_adm.h:53
adm_dwt_band_t decouple_r
Definition integer_adm.h:46
i4_adm_dwt_band_t i4_decouple_a
Definition integer_adm.h:54
adm_dwt_band_t csf_f
Definition integer_adm.h:49
i4_adm_dwt_band_t i4_csf_f
Definition integer_adm.h:56
adm_dwt_band_t ref_dwt2
Definition integer_adm.h:44
adm_dwt_band_t dis_dwt2
Definition integer_adm.h:45
void * buf_y_orig
Definition integer_adm.h:41
i4_adm_dwt_band_t i4_csf_a
Definition integer_adm.h:55
void * data_buf
Definition integer_adm.h:38
void * tmp_ref
Definition integer_adm.h:39
int * ind_y[4]
Definition integer_adm.h:42
size_t ind_size_x
Definition integer_adm.h:37
adm_dwt_band_t decouple_a
Definition integer_adm.h:47
i4_adm_dwt_band_t i4_ref_dwt2
Definition integer_adm.h:51
int * ind_x[4]
Definition integer_adm.h:42
void * buf_x_orig
Definition integer_adm.h:40
i4_adm_dwt_band_t i4_dis_dwt2
Definition integer_adm.h:52
adm_dwt_band_t csf_a
Definition integer_adm.h:48
size_t ind_size_y
Definition integer_adm.h:37
Definition integer_adm.h:22
int16_t * band_v
Definition integer_adm.h:24
int16_t * band_h
Definition integer_adm.h:25
int16_t * band_a
Definition integer_adm.h:23
int16_t * band_d
Definition integer_adm.h:26
Definition adm_tools.h:300
float g[4]
Definition adm_tools.h:304
float f0
Definition adm_tools.h:303
float a
Definition adm_tools.h:301
float k
Definition adm_tools.h:302
Definition integer_adm.h:29
int32_t * band_a
Definition integer_adm.h:30
int32_t * band_d
Definition integer_adm.h:33
int32_t * band_v
Definition integer_adm.h:31
int32_t * band_h
Definition integer_adm.h:32