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 /* Verify that conversion of fully-transparent pixels preserves color
20  * information, when relevant for the source and destination formats.
21  * In particular, make sure that the conversion path doesn't pass
22  * through a format with premultiplied alpha.  See bug #780016.
23  *
24  * Note that this test can, and will, result in false positives; i.e.,
25  * if the test passes, it means nothing -- we only watch for the
26  * occasional failure.  Fun, right?
27  */
28 
29 #include "config.h"
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <stdint.h>
33 #include "babl-internal.h"
34 
35 #include "common.inc"
36 
37 
38 #define NUMBER_OF_TRIALS 50
39 
40 static void
clear_fish_db(void)41 clear_fish_db (void)
42 {
43   /* so ugly... */
44   *babl_fish_db () = *babl_db_init ();
45 }
46 
47 int
main(int argc,char ** argv)48 main (int    argc,
49       char **argv)
50 {
51   int OK = 1;
52   int i;
53 
54   babl_init ();
55 
56   for (i = 0; OK && i < NUMBER_OF_TRIALS; i++)
57     {
58       clear_fish_db ();
59 
60       {
61         uint16_t in [][4] = {{0xffff, 0xffff, 0xffff, 0}};
62         float    out[][4] = {{1.0,    1.0,    1.0,    0.0}};
63 
64         /* this conversion is known to have been problematic.
65          * see bug #780016.
66          */
67         CHECK_CONV_FLOAT ("u16' -> float", float, 0.001,
68                           babl_format("R'G'B'A u16"),
69                           babl_format("RGBA float"),
70                           in, out);
71       }
72     }
73 
74   /* be nice and don't overwrite the fish cache, since we cleared all the
75    * fishes.
76    */
77   /* babl_exit (); */
78 
79   return !OK;
80 }
81