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 #include <math.h>
20 #include <babl/babl.h>
21 #include <stdio.h>
22 
23 #define PIXELS       6
24 #define TOLERANCE    0
25 
26 unsigned char source_buf [PIXELS * 3] =
27 { 0,     0,   0,
28   127, 127, 127,
29   255, 255, 255,
30   255, 0.0, 0.0,
31   0.0, 255, 0.0,
32   0.0, 0.0, 255 };
33 
34 unsigned char reference_buf [PIXELS * 3] =
35 { 0,   128, 128,
36   136, 128, 128,
37   255, 128, 128,
38   138, 209, 198,
39   224, 49,  209,
40   75,  196, 16 };
41 
42 unsigned char destination_buf [PIXELS * 3];
43 
44 static int
test(void)45 test (void)
46 {
47   int i;
48   int OK = 1;
49 
50   babl_process (babl_fish ("R'G'B' u8", "CIE Lab u8"),
51                 source_buf, destination_buf,
52                 PIXELS);
53 
54   for (i = 0; i < PIXELS * 3; i++)
55     {
56       if (fabs (1.0 * destination_buf[i] - reference_buf[i]) > TOLERANCE)
57         {
58           fprintf (stderr, "%2i (%2i%%3=%i, %2i/3=%i) is %i should be %i",
59                     i, i, i % 3, i, i / 3, destination_buf[i], reference_buf[i]);
60           OK = 0;
61         }
62     }
63   if (!OK)
64     return -1;
65   return 0;
66 }
67 
68 int
main(int argc,char ** argv)69 main (int    argc,
70       char **argv)
71 {
72   babl_init ();
73   if (test ())
74     return -1;
75   babl_exit ();
76   return 0;
77 }
78