1 /* This file is part of GEGL
2 *
3 * GEGL is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 3 of the License, or (at your option) any later version.
7 *
8 * GEGL is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
15 *
16 * Copyright 2018 Øyvind Kolås
17 */
18
19 #ifndef __GEGL_BUFFER_FORMATS_H__
20 #define __GEGL_BUFFER_FORMATS_H__
21
22
23 //G_BEGIN_DECLS
24
25 #include <babl/babl.h>
26 #include <glib-object.h>
27
28 /* the code in babl for looking up models, formats and types is quick -
29 but when formats end up being used as consts for comparisons in the core of
30 GEGL, it is good to have even better caching, hence this way of generating
31 and accessing per compilation unit caches of formats.
32 */
33
34 #define GEGL_CACHED_BABL(klass, typ, name) \
35 static inline const Babl *gegl_babl_##typ (void) { static const Babl *type = NULL; if (!type) type = babl_##klass (name); return type; }
36
37 GEGL_CACHED_BABL(type, half, "half")
38 GEGL_CACHED_BABL(type, float, "float")
39 GEGL_CACHED_BABL(type, u8, "u8")
40 GEGL_CACHED_BABL(type, u16, "u16")
41 GEGL_CACHED_BABL(type, u32, "u32")
42 GEGL_CACHED_BABL(type, double, "double")
43
44 GEGL_CACHED_BABL(model, rgb_linear, "RGB")
45 GEGL_CACHED_BABL(model, rgba_linear, "RGBA")
46 GEGL_CACHED_BABL(model, rgbA_linear, "RaGaBaA")
47 GEGL_CACHED_BABL(model, y_linear, "Y")
48 GEGL_CACHED_BABL(model, ya_linear, "YA")
49 GEGL_CACHED_BABL(model, yA_linear, "YaA")
50
51 GEGL_CACHED_BABL(format, rgba_float, "R'G'B'A float")
52 GEGL_CACHED_BABL(format, rgba_u8, "R'G'B'A u8")
53 GEGL_CACHED_BABL(format, rgb_u8, "R'G'B' u8")
54 GEGL_CACHED_BABL(format, rgbA_float, "R'aG'aB'aA float")
55 GEGL_CACHED_BABL(format, rgba_linear_float, "RGBA float")
56 GEGL_CACHED_BABL(format, rgba_linear_u16, "RGBA u16")
57 GEGL_CACHED_BABL(format, rgbA_linear_float, "RaGaBaA float")
58 GEGL_CACHED_BABL(format, ya_float, "Y'A float")
59 GEGL_CACHED_BABL(format, yA_float, "Y'aA float")
60 GEGL_CACHED_BABL(format, ya_linear_float, "Y float")
61 GEGL_CACHED_BABL(format, yA_linear_float, "YaA float")
62
63
64 #ifdef G_OS_WIN32
65 /* one use 16kb of stack before an exception triggered warning on win32 */
66 #define GEGL_ALLOCA_THRESHOLD 8192
67 #else
68 /* on linux/OSX 0.5mb is reasonable, the stack size of new threads is 2MB */
69 #define GEGL_ALLOCA_THRESHOLD (1024*1024/2)
70 #endif
71
int_floorf(float x)72 static inline int int_floorf (float x)
73 {
74 int i = (int)x; /* truncate */
75 return i - ( i > x ); /* convert trunc to floor */
76 }
77
int_ceilf(float x)78 static inline int int_ceilf (float x)
79 {
80 return -int_floorf(-(x));
81 }
82
83 //G_END_DECLS
84
85 #endif /* __GEGL_BUFFER_FORMATS_H__ */
86