1 /* babl - dynamically extendable universal pixel conversion library.
2 * Copyright (C) 2005, Øyvind Kolås.
3 *
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.
8 *
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.
13 *
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/>.
17 */
18
19
20 #include "config.h"
21 #include <math.h>
22 #include "babl-internal.h"
23
24 #define PIXELS 6
25 #define TOLERANCE 0.000001
26
27 float source_buf [PIXELS * 3] =
28 { 0.0, 0.0, 0.0,
29 0.5, 0.5, 0.5,
30 1.0, 1.0, 1.0,
31 1.0, 0.0, 0.0,
32 0.0, 1.0, 0.0,
33 0.0, 0.0, 1.0 };
34
35 float reference_buf [PIXELS * 3] =
36 { 0.0, 0.0, 0.0,
37 0.735357, 0.0, 0.0,
38 1.0, 0.0, 0.0,
39 0.299, -0.168736, 0.5,
40 0.587, -0.331264, -0.418688,
41 0.114, 0.5, -0.081312 };
42
43
44 float destination_buf [PIXELS * 3];
45
46 static int
test(void)47 test (void)
48 {
49 const Babl *fish;
50 int i;
51 int OK = 1;
52
53 fish = babl_fish (
54 babl_format_new (
55 babl_model ("RGB"),
56 babl_type ("float"),
57 babl_component ("R"),
58 babl_component ("G"),
59 babl_component ("B"),
60 NULL
61 ),
62 babl_format_new (
63 babl_model ("Y'CbCr"),
64 babl_type ("float"),
65 babl_component ("Y'"),
66 babl_component ("Cb"),
67 babl_component ("Cr"),
68 NULL
69 )
70 );
71
72 babl_process (fish, source_buf, destination_buf, PIXELS);
73
74 for (i = 0; i < PIXELS * 3; i++)
75 {
76 if (fabs (destination_buf[i] - reference_buf[i]) > TOLERANCE)
77 {
78 babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %f should be %f",
79 i, i, i % 3, i, i / 3, destination_buf[i], reference_buf[i]);
80 OK = 0;
81 }
82 }
83 if (!OK)
84 return -1;
85 return 0;
86 }
87
88 int
main(int argc,char ** argv)89 main (int argc,
90 char **argv)
91 {
92 babl_init ();
93 if (test ())
94 return -1;
95 babl_exit ();
96 return 0;
97 }
98