babl: fix some annotation to make the function usable in bindings.
[babl.git] / tests / alpha_symmetric_transform.c
blobaff23ce99ce1a31a234d4029d1f85f21d6c14d68
1 /* babl - dynamically extendable universal pixel conversion library.
2 * Copyright (C) 2005, 2017 Øyvind Kolås.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see
16 * <https://www.gnu.org/licenses/>.
19 #include "config.h"
20 #include <math.h>
21 #include "babl-internal.h"
23 #define TOLERANCE 0.001
24 #define PIXELS 12
26 float source_buf [PIXELS * 4] =
27 { 10.0, 1.0, 0.1, 1.0,
28 10.0, 1.0, 0.1, 0.5,
29 10.0, 1.0, 0.1, 0.1,
30 10.0, 1.0, 0.1, 0.01,
31 10.0, 1.0, 0.1, -0.01,
32 10.0, 1.0, 0.1, 1.5,
33 10.0, 1.0, 0.0001, 0.000001,
34 10.0, 1.0, 0.1 , -0.00001,
35 10.0, 1.0, 0.1, 0.0,
36 10.0, 1.0, 0.1, -0.5,
37 1000.0,10000.0, 100000.0, 0.001,
38 5000.0,50000.0, 500000.0, 0.01,
41 float bounce_buf [PIXELS * 4];
42 float destination_buf [PIXELS * 4];
44 static int
45 test (void)
47 int i;
48 int OK = 1;
50 babl_process (babl_fish ("RGBA float", "RaGaBaA float"),
51 source_buf, bounce_buf,
52 PIXELS);
53 babl_process (babl_fish ("RaGaBaA float", "RGBA float"),
54 bounce_buf, destination_buf,
55 PIXELS);
57 for (i = 0; i < PIXELS; i++)
59 for (int c = 0; c < 4; c++)
61 if (fabs (destination_buf[i*4+c] - source_buf[i*4+c]) > TOLERANCE)
63 babl_log ("separate alpha %i.%i: %.9f!=%.9f(ref) ", i, c, destination_buf[i*4+c],
64 source_buf[i*4+c]);
65 OK = 0;
67 // fprintf (stdout, "%.19f ", destination_buf[i*4+c]);
69 // fprintf (stdout, "\n");
72 fprintf (stdout, "\n");
74 babl_process (babl_fish ("RaGaBaA float", "RGBA float"),
75 source_buf, bounce_buf,
76 PIXELS);
77 babl_process (babl_fish ("RGBA float", "RaGaBaA float"),
78 bounce_buf, destination_buf,
79 PIXELS);
81 for (i = 0; i < PIXELS; i++)
83 for (int c = 0; c < 4; c++)
85 if (fabs (destination_buf[i*4+c] - source_buf[i*4+c]) > TOLERANCE)
87 babl_log ("associatd-alpha %i.%i: %.9f!=%.9f(ref) ", i, c, destination_buf[i*4+c],
88 source_buf[i*4+c]);
89 OK = 0;
91 // fprintf (stdout, "%.19f ", destination_buf[i*4+c]);
93 // fprintf (stdout, "\n");
97 if (!OK)
98 return -1;
99 return 0;
103 main (void)
105 babl_init ();
106 if (test ())
107 return -1;
108 babl_exit ();
109 return 0;