summaryrefslogtreecommitdiff
path: root/tools/babl-gen-test-pixels.c
blob: 6dbd3cc163cb283c1e72be4f2622366fa106c012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* babl - dynamically extendable universal pixel conversion library.
 * Copyright (C) 2005 Øyvind Kolås
 *               2013 Daniel Sabo
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, see
 * <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <stdio.h>

#define BABL_PATH_NUM_TEST_PIXELS       3072
#define BABL_CONVERSION_NUM_TEST_PIXELS 128
#define BABL_FROMAT_NUM_TEST_PIXELS     256
#define BABL_MODEL_NUM_TEST_PIXELS      512
#define BABL_TYPE_NUM_TEST_PIXELS       512

#define BABL_COMPONENT_FMT_STR          "%.13f"
#define BABL_PIXEL_FMT_STR              BABL_COMPONENT_FMT_STR ", " \
                                        BABL_COMPONENT_FMT_STR ", " \
                                        BABL_COMPONENT_FMT_STR ", " \
                                        BABL_COMPONENT_FMT_STR

static double rand_double (void)
{
  return (double) random () / RAND_MAX;
}

static double rand_range_double (double min, double max)
{
  return rand_double () * (max - min) + min;
}

static void gen_path_pixels (void)
{
  int i;
  srandom (20050728);

  printf ("static const int babl_num_path_test_pixels = %d;\n\n", BABL_PATH_NUM_TEST_PIXELS);

  printf ("static const double babl_path_test_pixels[%d] = {\n", BABL_PATH_NUM_TEST_PIXELS * 4);

  /*  add 256 pixels in the valid range between 0.0 and 1.0  */
  for (i = 0; i < 256; i++)
    {
      printf (BABL_PIXEL_FMT_STR ",\n",
        rand_double (),
        rand_double (),
        rand_double (),
        rand_double ());
    }

  /*  add 16 pixels between -1.0 and 0.0  */
  for (i = 0; i < 16; i++)
    {
      printf (BABL_PIXEL_FMT_STR ",\n",
        rand_range_double (-1.0, 0.0),
        rand_range_double (-1.0, 0.0),
        rand_range_double (-1.0, 0.0),
        rand_range_double (-1.0, 0.0));
    }

  /*  add 16 pixels between 1.0 and 2.0  */
  for (i = 0; i < 16; i++)
    {
      printf (BABL_PIXEL_FMT_STR ",\n",
        rand_range_double (1.0, 2.0),
        rand_range_double (1.0, 2.0),
        rand_range_double (1.0, 2.0),
        rand_range_double (1.0, 2.0));
    }

  for (i = 288; i < BABL_PATH_NUM_TEST_PIXELS; i++)
    {
      printf (BABL_PIXEL_FMT_STR ",\n",
        rand_double (),
        rand_double (),
        rand_double (),
        rand_double ());
    }

  printf ("};\n\n");

  printf ("static const int babl_num_conversion_test_pixels = %d;\n\n", BABL_CONVERSION_NUM_TEST_PIXELS);

  printf ("static const double *babl_conversion_test_pixels = babl_path_test_pixels;\n\n");

  printf ("static const int babl_num_format_test_pixels = %d;\n\n", BABL_FROMAT_NUM_TEST_PIXELS);

  printf ("static const double *babl_format_test_pixels = babl_path_test_pixels;\n\n");
}

static void gen_model_pixels (void)
{
  int i;
  srandom (20050728);

  printf ("static const int babl_num_model_test_pixels = %d;\n\n", BABL_MODEL_NUM_TEST_PIXELS);

  printf ("static const double babl_model_test_pixels[%d] = {\n", BABL_MODEL_NUM_TEST_PIXELS * 4);

  /*  add 128 pixels in the valid range between 0.0 and 1.0  */
  for (i = 0; i < BABL_MODEL_NUM_TEST_PIXELS; i++)
    {
      printf (BABL_PIXEL_FMT_STR ",\n",
        rand_range_double (-0.2, 1.2),
        rand_range_double (-0.2, 1.2),
        rand_range_double (-0.2, 1.2),
        rand_range_double (-0.2, 1.2));
    }

  printf ("};\n\n");
}

static void gen_type_pixels (void)
{
  int i;
  srandom (20050728);

  printf ("static const int babl_num_type_test_pixels = %d;\n\n", BABL_TYPE_NUM_TEST_PIXELS);

  printf ("static const double babl_type_test_pixels[%d] = {\n", BABL_TYPE_NUM_TEST_PIXELS * 4);

  /*  add 128 pixels in the valid range between 0.0 and 1.0  */
  for (i = 0; i < BABL_MODEL_NUM_TEST_PIXELS; i++)
    {
      printf (BABL_PIXEL_FMT_STR ",\n",
        rand_range_double (0.0, 128.0),
        rand_range_double (0.0, 128.0),
        rand_range_double (0.0, 128.0),
        rand_range_double (0.0, 128.0));
    }

  printf ("};\n\n");
}

int main (int argc, char **argv)
{
  printf (
    "/* babl - dynamically extendable universal pixel conversion library.\n"
    " * Copyright (C) 2005 Øyvind Kolås\n"
    " *               2013 Daniel Sabo\n"
    " *\n"
    " * This library is free software; you can redistribute it and/or\n"
    " * modify it under the terms of the GNU Lesser General Public\n"
    " * License as published by the Free Software Foundation; either\n"
    " * version 3 of the License, or (at your option) any later version.\n"
    " *\n"
    " * This library is distributed in the hope that it will be useful,\n"
    " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
    " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
    " * Lesser General Public License for more details.\n"
    " *\n"
    " * You should have received a copy of the GNU Lesser General\n"
    " * Public License along with this library; if not, see\n"
    " * <http://www.gnu.org/licenses/>.\n"
    " */\n"
    "\n");

  printf ("/* THIS IS A GENERATED FILE - DO NOT EDIT */\n\n");

  gen_path_pixels ();
  gen_model_pixels ();
  gen_type_pixels ();

  return 0;
}