forked from haasn/libplacebo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.c
39 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
#include "tests.h"
int main()
{
struct pl_context *ctx = pl_test_context();
for (const struct pl_named_filter_config *conf = pl_named_filters;
conf->filter; conf++)
{
struct pl_filter_params params = {
.config = *conf->filter,
.lut_entries = 128,
};
printf("Testing filter '%s'\n", conf->name);
const struct pl_filter *flt = pl_filter_generate(ctx, ¶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_context_destroy(&ctx);
}