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 "config.h"
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <assert.h>
23 #include "babl.h"
24 #include "common.inc"
25 
26 int
main(int argc,char ** argv)27 main (int    argc,
28       char **argv)
29 {
30   int OK = 1;
31   babl_init ();
32   {
33     unsigned char in[][4]   = {{0,1,2,3  },{4,5,6,7    },{8,9,10,11  }};
34     unsigned char out1[][1]  = {{0},        {4},  {8}  };
35     unsigned char out2[][2]  = {{0,1},      {4,5},         {8,9}  };
36     unsigned char out4[][4]  = {{0,1,2,3},  {4,5,6,7},    {8,9,10,11}  };
37     unsigned char out5[][5]  = {{0,1,2,3,0},  {4,5,6,7,0},{8,9,10,11,0}  };
38 
39     CHECK_CONV("RGBAu8 to n1'", unsigned char,
40         babl_format("R'G'B'A u8"),
41         babl_format_n (babl_type ("u8"), 1),
42         in, out1);
43 
44     CHECK_CONV("RGBAu8 to n2'", unsigned char,
45         babl_format("R'G'B'A u8"),
46         babl_format_n (babl_type ("u8"), 2),
47         in, out2);
48 
49     CHECK_CONV("RGBAu8 to n4'", unsigned char,
50         babl_format("R'G'B'A u8"),
51         babl_format_n (babl_type ("u8"), 4),
52         in, out4);
53 
54     CHECK_CONV("RGBAu8 to n5'", unsigned char,
55         babl_format("R'G'B'A u8"),
56         babl_format_n (babl_type ("u8"), 5),
57         in, out5);
58   }
59   {
60     unsigned char in[][3]   = {{0,1,2  },{4,5,6    },{8,9,10  }};
61     unsigned char out1[][1]  = {{0},        {4},  {8}  };
62     unsigned char out2[][2]  = {{0,1},      {4,5},         {8,9}  };
63     unsigned char out4[][4]  = {{0,1,2,0},  {4,5,6,0},    {8,9,10,0}  };
64     unsigned char out5[][5]  = {{0,1,2,0,0},  {4,5,6,0,0},{8,9,10,0,0}  };
65     unsigned char out6[][6]  = {{0,1,2,0,0,0},  {4,5,6,0,0,0},{8,9,10,0,0,0}  };
66 
67     CHECK_CONV("RGBu8 to n1'", unsigned char,
68         babl_format("R'G'B' u8"),
69         babl_format_n (babl_type ("u8"), 1),
70         in, out1);
71 
72 
73     CHECK_CONV("RGBu8 to n2'", unsigned char,
74         babl_format("R'G'B' u8"),
75         babl_format_n (babl_type ("u8"), 2),
76         in, out2);
77 
78 
79     CHECK_CONV("RGBu8 to n4'", unsigned char,
80         babl_format("R'G'B' u8"),
81         babl_format_n (babl_type ("u8"), 4),
82         in, out4);
83 
84     CHECK_CONV("RGBu8 to n5'", unsigned char,
85         babl_format("R'G'B' u8"),
86         babl_format_n (babl_type ("u8"), 5),
87         in, out5);
88 
89     CHECK_CONV("RGBu8 to n6'", unsigned char,
90         babl_format("R'G'B' u8"),
91         babl_format_n (babl_type ("u8"), 6),
92         in, out6);
93   }
94 
95   babl_exit ();
96   return !OK;
97 }
98