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