File: n_components.c

package info (click to toggle)
babl 0.1.10-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,912 kB
  • sloc: ansic: 15,162; sh: 11,131; makefile: 362; ruby: 90
file content (116 lines) | stat: -rw-r--r-- 4,066 bytes parent folder | download | duplicates (3)
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
/* babl - dynamically extendable universal pixel conversion library.
 * Copyright (C) 2005, Øyvind Kolås.
 *
 * 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 "config.h"
#include <math.h>
#include "babl-internal.h"

#define PIXELS       7
#define COMPONENTS   2048
#define TOLERANCE    0

float source_buf [PIXELS * COMPONENTS] =
{
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
   0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 
  /* the rest of the input buffer is nulls */
}; 

unsigned char reference_buf [PIXELS * COMPONENTS] =
{ 
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  26, 51, 77, 102, 128, 153, 26, 51, 77, 102, 128, 153,
  /* the rest of the reference buffer is nulls */
};

unsigned char destination_buf [PIXELS * COMPONENTS];

static int
test (void)
{
  int   components;
  int   OK = 1;

  for (components = 1; components < 2048; components ++)
  {
    const Babl *fish;
    const Babl *src_fmt;
    const Babl *dst_fmt;
    int   i;

    src_fmt = babl_format_n (babl_type ("float"), components);
    dst_fmt = babl_format_n (babl_type ("u8"), components);

    fish = babl_fish (src_fmt, dst_fmt);

    babl_process (fish, source_buf, destination_buf, PIXELS);

    for (i = 0; i < PIXELS * components; i++)
      {
        if (abs (destination_buf[i] - reference_buf[i]) > TOLERANCE)
          {
            babl_log ("%i-components, pixel %i component %i is %i should be %i",
                      components, i / components, i % components, destination_buf[i], reference_buf[i]);
            OK = 0;
          }
      }
  }
  if (!OK)
    return -1;
  return 0;
}

int
main (int    argc,
      char **argv)
{
  babl_init ();
  if (test ())
    return -1;
  babl_exit ();
  return 0;
}