forked from haasn/libplacebo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.c
40 lines (35 loc) · 1.24 KB
/
filters.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "tests.h"
int main()
{
pl_log log = pl_test_logger();
for (const struct pl_filter_preset *conf = pl_filter_presets; conf->name; conf++) {
if (!conf->filter)
continue;
struct pl_filter_params params = {
.config = *conf->filter,
.lut_entries = 128,
};
printf("Testing filter '%s'\n", conf->name);
pl_filter flt = pl_filter_generate(log, ¶ms);
REQUIRE(flt);
if (params.config.polar) {
// Ensure the kernel seems sanely scaled
REQUIRE(feq(flt->weights[0], 1.0, 1e-7));
REQUIRE(feq(flt->weights[params.lut_entries - 1], 0.0, 1e-7));
} else {
// Ensure the weights for each row add up to unity
for (int i = 0; i < params.lut_entries; i++) {
float sum = 0.0;
REQUIRE(flt->row_size);
REQUIRE(flt->row_stride >= flt->row_size);
for (int n = 0; n < flt->row_size; n++) {
float w = flt->weights[i * flt->row_stride + n];
sum += w;
}
REQUIRE(feq(sum, 1.0, 1e-6));
}
}
pl_filter_free(&flt);
}
pl_log_destroy(&log);
}