libvmaf
Loading...
Searching...
No Matches
integer_vif.h
Go to the documentation of this file.
1
18
19#ifndef FEATURE_VIF_H_
20#define FEATURE_VIF_H_
21
22#include <stdint.h>
23#include <stdbool.h>
24#include <assert.h>
25#include "cpu.h"
26
27/* Enhancement gain imposed on vif, must be >= 1.0, where 1.0 means the gain is completely disabled */
28#ifndef DEFAULT_VIF_ENHN_GAIN_LIMIT
29#define DEFAULT_VIF_ENHN_GAIN_LIMIT (100.0)
30#endif // !DEFAULT_VIF_ENHN_GAIN_LIMIT
31
32static const uint16_t vif_filter1d_table[4][18] = {
33 { 489, 935, 1640, 2640, 3896, 5274, 6547, 7455, 7784, 7455, 6547, 5274, 3896, 2640, 1640, 935, 489, 0 },
34 { 1244, 3663, 7925, 12590, 14692, 12590, 7925, 3663, 1244, 0 },
35 { 3571, 16004, 26386, 16004, 3571, 0 },
36 { 10904, 43728, 10904, 0 }
37};
38
39static const int vif_filter1d_width[4] = { 17, 9, 5, 3 };
40
41typedef struct VifBuffer {
42 void *data;
43
44 void *ref;
45 void *dis;
46 uint16_t *mu1;
47 uint16_t *mu2;
48 uint32_t *mu1_32;
49 uint32_t *mu2_32;
50 uint32_t *ref_sq;
51 uint32_t *dis_sq;
52 uint32_t *ref_dis;
53
54 struct {
55 uint32_t *mu1;
56 uint32_t *mu2;
57 uint32_t *ref;
58 uint32_t *dis;
59 uint32_t *ref_dis;
60 uint32_t *ref_convol;
61 uint32_t *dis_convol;
62 } tmp;
63
64 ptrdiff_t stride;
65 ptrdiff_t stride_16;
66 ptrdiff_t stride_32;
67 ptrdiff_t stride_tmp;
68} VifBuffer;
69
76
77typedef struct VifPublicState {
79 uint16_t log2_table[65537];
82
83static inline void PADDING_SQ_DATA(VifBuffer buf, int w, unsigned fwidth_half)
84{
85 for (unsigned f = 1; f <= fwidth_half; ++f) {
86 int left_point = -(int)f;
87 int right_point = f;
88 buf.tmp.mu1[left_point] = buf.tmp.mu1[right_point];
89 buf.tmp.mu2[left_point] = buf.tmp.mu2[right_point];
90 buf.tmp.ref[left_point] = buf.tmp.ref[right_point];
91 buf.tmp.dis[left_point] = buf.tmp.dis[right_point];
92 buf.tmp.ref_dis[left_point] = buf.tmp.ref_dis[right_point];
93
94 left_point = w - 1 - f;
95 right_point = w - 1 + f;
96 buf.tmp.mu1[right_point] = buf.tmp.mu1[left_point];
97 buf.tmp.mu2[right_point] = buf.tmp.mu2[left_point];
98 buf.tmp.ref[right_point] = buf.tmp.ref[left_point];
99 buf.tmp.dis[right_point] = buf.tmp.dis[left_point];
100 buf.tmp.ref_dis[right_point] = buf.tmp.ref_dis[left_point];
101 }
102}
103
104static inline void PADDING_SQ_DATA_2(VifBuffer buf, int w, unsigned fwidth_half)
105{
106 for (unsigned f = 1; f <= fwidth_half; ++f) {
107 int left_point = -(int)f;
108 int right_point = f;
109 buf.tmp.ref_convol[left_point] = buf.tmp.ref_convol[right_point];
110 buf.tmp.dis_convol[left_point] = buf.tmp.dis_convol[right_point];
111
112 left_point = w - 1 - f;
113 right_point = w - 1 + f;
114 buf.tmp.ref_convol[right_point] = buf.tmp.ref_convol[left_point];
115 buf.tmp.dis_convol[right_point] = buf.tmp.dis_convol[left_point];
116 }
117}
118
119void vif_statistic_8(struct VifPublicState *s, float *num, float *den, unsigned w, unsigned h);
120void vif_statistic_16(struct VifPublicState *s, float *num, float *den, unsigned w, unsigned h, int bpc, int scale);
121
122/*
123 * Compute vif residuals on a vertically filtered line
124 * This is a support method for block based vip_statistic_xxx method and is typically called
125 * only when to is not a multiple of the block size, with from = (to / block_size) + block_size
126 */
128 unsigned to, int scale);
129
130
131#ifdef _MSC_VER
132#include <intrin.h>
133
134static inline int __builtin_clz(unsigned x) {
135 return (int)__lzcnt(x);
136}
137
138static inline int __builtin_clzll(unsigned long long x) {
139 return (int)__lzcnt64(x);
140}
141
142#endif
143
144static inline int32_t log2_32(const uint16_t *log2_table, uint32_t temp)
145{
146 int k = __builtin_clz(temp);
147 k = 16 - k;
148 temp = temp >> k;
149 return log2_table[temp] + 2048 * k;
150}
151
152static inline int32_t log2_64(const uint16_t *log2_table, uint64_t temp)
153{
154 assert(temp >= 0x20000);
155 int k = __builtin_clzll(temp);
156 k = 48 - k;
157 temp = temp >> k;
158 return log2_table[temp] + 2048 * k;
159}
160
161#endif /* _FEATURE_VIF_H_ */
void vif_statistic_8(struct VifPublicState *s, float *num, float *den, unsigned w, unsigned h)
VifResiduals vif_compute_line_residuals(VifPublicState *s, unsigned from, unsigned to, int scale)
void vif_statistic_16(struct VifPublicState *s, float *num, float *den, unsigned w, unsigned h, int bpc, int scale)
Definition integer_vif.h:41
struct VifBuffer::@243371321022260352266053163127271242127303165275 tmp
ptrdiff_t stride_16
Definition integer_vif.h:65
ptrdiff_t stride_tmp
Definition integer_vif.h:67
ptrdiff_t stride_32
Definition integer_vif.h:66
uint16_t * mu1
Definition integer_vif.h:46
uint32_t * mu1_32
Definition integer_vif.h:48
void * dis
Definition integer_vif.h:45
uint16_t * mu2
Definition integer_vif.h:47
uint32_t * mu2_32
Definition integer_vif.h:49
uint32_t * ref_dis
Definition integer_vif.h:52
void * data
Definition integer_vif.h:42
uint32_t * dis_sq
Definition integer_vif.h:51
ptrdiff_t stride
Definition integer_vif.h:64
void * ref
Definition integer_vif.h:44
uint32_t * ref_sq
Definition integer_vif.h:50
Definition integer_vif.h:77
VifBuffer buf
Definition integer_vif.h:78
double vif_enhn_gain_limit
Definition integer_vif.h:80
uint16_t log2_table[65537]
Definition integer_vif.h:79
Definition integer_vif.h:70
int64_t accum_num_log
Definition integer_vif.h:71
int64_t accum_num_non_log
Definition integer_vif.h:73
int64_t accum_den_log
Definition integer_vif.h:72
int64_t accum_den_non_log
Definition integer_vif.h:74