filters: Add generated cubic resampling (with gamma) yay!
[gfxprim.git] / pylib / templates / common.c.t
blob30f3814c14cc3ad4b1a67a687abff03e9c0f6079
1 %% extends 'base.c.t'
3 /*
4  * Maybe opts, adds comma on the left side
5  */
6 {% macro maybe_opts_l(opts) %}{% if opts %}, {{ opts }}{% endif %}{% endmacro %}
8 /*
9  * Maybe opts, adds comma on the right side.
10  */
11 {% macro maybe_opts_r(opts) %}{% if opts %}{{ opts }}, {% endif %}{% endmacro %}
14  * Converts channels to params
15  */
16 {% macro expand_chanslist(pt, pref="", suff="") %}{{ pref+pt.chanslist[0][0]+suff }}{% for c in pt.chanslist[1:] %}, {{ pref+c[0]+suff }}{% endfor %}{% endmacro %}
18  * Clamps n-bits value
19  */
20 %%macro clamp_val(val, bits)
21 if ({{ val }} > {{ 2 ** bits - 1 }}) {{ val }} = {{ 2 ** bits - 1}};
22 %% endmacro
24 {% macro gamma_in_bits(size) %}{% if size + 2 > 8 %}16{% else %}8{% endif %}{% endmacro %}
25 {% macro gamma_out_bits(size) %}{% if size > 8 %}16{% else %}8{% endif %}{% endmacro %}
28  * Prepares pointers to Gamma tables.
29  */
30 %% macro fetch_gamma_tables(pt, ctx, pref="", suff="")
31         /* prepare Gamma tables */
32         %% for c in pt.chanslist
33         uint{{ gamma_in_bits(c[2]) }}_t *{{ pref+c[0] }}_2_LIN{{ suff }} = NULL;
34         %% endfor
36         %% for c in pt.chanslist
37         uint{{ gamma_out_bits(c[2]) }}_t *{{ pref+c[0] }}_2_GAMMA{{ suff }} = NULL;
38         %% endfor
40         %% set i = 0
41         if ({{ ctx }}->gamma) {
42                 %% for c in pt.chanslist
43                 {{ pref+c[0] }}_2_LIN{{ suff }} = {{ ctx }}->gamma->tables[{{ i }}]->u{{ gamma_in_bits(c[2]) }};
44                 %% set i = i + 1
45                 %% endfor
47                 %% set i = len(pt.chanslist)
48                 %% for c in pt.chanslist
49                 {{ pref+c[0] }}_2_GAMMA{{ suff }} = {{ ctx }}->gamma->tables[{{ i }}]->u{{ gamma_out_bits(c[2]) }};
50                 %% set i = i + 1
51                 %% endfor
52         }
53 %% endmacro