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       7
25 #define COMPONENTS   2048
26 #define TOLERANCE    0
27 
28 float source_buf [PIXELS * COMPONENTS] =
29 {
30    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
31    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
32    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
33    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
34    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
35    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
36    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
37    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
38    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
39    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
40    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
41    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
42    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
43    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
44    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
45    0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
46   /* the rest of the input buffer is nulls */
47 };
48 
49 unsigned char reference_buf [PIXELS * COMPONENTS] =
50 {
51   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
52   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
53   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
54   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
55   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
56   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
57   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
58   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
59   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
60   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
61   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
62   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
63   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
64   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
65   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
66   26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
67   /* the rest of the reference buffer is nulls */
68 };
69 
70 unsigned char destination_buf [PIXELS * COMPONENTS];
71 
72 static int
test(void)73 test (void)
74 {
75   int   components;
76   int   OK = 1;
77 
78   for (components = 1; components < 2048; components ++)
79   {
80     const Babl *fish;
81     const Babl *src_fmt;
82     const Babl *dst_fmt;
83     int   i;
84 
85     src_fmt = babl_format_n (babl_type ("float"), components);
86     dst_fmt = babl_format_n (babl_type ("u8"), components);
87 
88     fish = babl_fish (src_fmt, dst_fmt);
89 
90     babl_process (fish, source_buf, destination_buf, PIXELS);
91 
92     for (i = 0; i < PIXELS * components; i++)
93       {
94         if (abs (destination_buf[i] - reference_buf[i]) > TOLERANCE)
95           {
96             babl_log ("%i-components, pixel %i component %i is %i should be %i",
97                       components, i / components, i % components, destination_buf[i], reference_buf[i]);
98             OK = 0;
99           }
100       }
101   }
102   if (!OK)
103     return -1;
104   return 0;
105 }
106 
107 int
main(int argc,char ** argv)108 main (int    argc,
109       char **argv)
110 {
111   babl_init ();
112   if (test ())
113     return -1;
114   babl_exit ();
115   return 0;
116 }
117