gegl: move caching of babl types/formats to an internal header

parent f88ec375
......@@ -26,16 +26,11 @@
#include <babl/babl.h>
#include "gegl-types.h"
#include "gegl-types-internal.h"
#include "gegl-algorithms.h"
#include <math.h>
static const Babl *babl_type_float (void) { static const Babl *type = NULL; if (!type) type = babl_type ("float"); return type; }
static const Babl *babl_type_u8 (void) { static const Babl *type = NULL; if (!type) type = babl_type ("u8"); return type; }
static const Babl *babl_type_u16 (void) { static const Babl *type = NULL; if (!type) type = babl_type ("u16"); return type; }
static const Babl *babl_type_u32 (void) { static const Babl *type = NULL; if (!type) type = babl_type ("u32"); return type; }
static const Babl *babl_type_double (void) { static const Babl *type = NULL; if (!type) type = babl_type ("double"); return type; }
void gegl_downscale_2x2 (const Babl *format,
gint src_width,
gint src_height,
......@@ -47,15 +42,15 @@ void gegl_downscale_2x2 (const Babl *format,
const gint bpp = babl_format_get_bytes_per_pixel (format);
const Babl *comp_type = babl_format_get_type (format, 0);
if (comp_type == babl_type_float())
if (comp_type == gegl_babl_float())
gegl_downscale_2x2_float (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
else if (comp_type == babl_type_u8())
else if (comp_type == gegl_babl_u8())
gegl_downscale_2x2_u8 (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
else if (comp_type == babl_type_u16())
else if (comp_type == gegl_babl_u16())
gegl_downscale_2x2_u16 (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
else if (comp_type == babl_type_u32())
else if (comp_type == gegl_babl_u32())
gegl_downscale_2x2_u32 (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
else if (comp_type == babl_type_double())
else if (comp_type == gegl_babl_double())
gegl_downscale_2x2_double (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
else
gegl_downscale_2x2_nearest (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
......@@ -102,19 +97,19 @@ void gegl_resample_boxfilter (guchar *dest_buf,
const Babl *comp_type = babl_format_get_type (format, 0);
const gint bpp = babl_format_get_bytes_per_pixel (format);
if (comp_type == babl_type_float())
if (comp_type == gegl_babl_float())
gegl_resample_boxfilter_float (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else if (comp_type == babl_type_u8())
else if (comp_type == gegl_babl_u8())
gegl_resample_boxfilter_u8 (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else if (comp_type == babl_type_u16())
else if (comp_type == gegl_babl_u16())
gegl_resample_boxfilter_u16 (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else if (comp_type == babl_type_u32())
else if (comp_type == gegl_babl_u32())
gegl_resample_boxfilter_u32 (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else if (comp_type == babl_type_double())
else if (comp_type == gegl_babl_double())
gegl_resample_boxfilter_double (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else
......@@ -134,19 +129,19 @@ void gegl_resample_bilinear (guchar *dest_buf,
const Babl *comp_type = babl_format_get_type (format, 0);
const gint bpp = babl_format_get_bytes_per_pixel (format);
if (comp_type == babl_type_float ())
if (comp_type == gegl_babl_float ())
gegl_resample_bilinear_float (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else if (comp_type == babl_type_u8 ())
else if (comp_type == gegl_babl_u8 ())
gegl_resample_bilinear_u8 (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else if (comp_type == babl_type_u16 ())
else if (comp_type == gegl_babl_u16 ())
gegl_resample_bilinear_u16 (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else if (comp_type == babl_type_u32 ())
else if (comp_type == gegl_babl_u32 ())
gegl_resample_bilinear_u32 (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else if (comp_type == babl_type_double ())
else if (comp_type == gegl_babl_double ())
gegl_resample_bilinear_double (dest_buf, source_buf, dst_rect, src_rect,
s_rowstride, scale, bpp, d_rowstride);
else
......
......@@ -20,6 +20,8 @@
#ifndef __GEGL_TYPES_INTERNAL_H__
#define __GEGL_TYPES_INTERNAL_H__
#include <babl/babl.h>
G_BEGIN_DECLS
typedef struct _GeglPad GeglPad;
......@@ -70,6 +72,31 @@ static inline int gegl_level_from_scale (gfloat scale)
return level;
}
/* the code in babl for looking up models, formats and types is quick -
but when formats end up being used as consts for comparisons in the core of
GEGL, it is good to have even better caching, hence this way of generating
and accessing per compilation unit caches of formats.
*/
#define GEGL_CACHED_BABL(klass, typ, name) \
static inline const Babl *gegl_babl_##typ (void) { static const Babl *type = NULL; if (!type) type = babl_##klass (name); return type; }
GEGL_CACHED_BABL(type, half, "half")
GEGL_CACHED_BABL(type, float, "float")
GEGL_CACHED_BABL(type, u8, "u8")
GEGL_CACHED_BABL(type, u16, "u16")
GEGL_CACHED_BABL(type, u32, "u32")
GEGL_CACHED_BABL(type, double, "double")
GEGL_CACHED_BABL(format, rgba_float, "R'G'B'A float")
GEGL_CACHED_BABL(format, rgbA_float, "R'aG'aB'aA float")
GEGL_CACHED_BABL(format, rgba_linear_float, "RGBA float")
GEGL_CACHED_BABL(format, rgbA_linear_float, "RaGaBaA float")
GEGL_CACHED_BABL(format, ya_float, "Y'A float")
GEGL_CACHED_BABL(format, yA_float, "Y'aA float")
GEGL_CACHED_BABL(format, ya_linear_float, "Y float")
GEGL_CACHED_BABL(format, yA_linear_float, "YaA float")
G_END_DECLS
#endif /* __GEGL_TYPES_INTERNAL_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment