[gegl] gegl: move caching of babl types/formats to an internal header
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] gegl: move caching of babl types/formats to an internal header
- Date: Fri, 23 Dec 2016 20:09:42 +0000 (UTC)
commit 00877177e43fbaeb2f4606b36d354c78ca01e329
Author: Øyvind Kolås <pippin gimp org>
Date: Fri Dec 23 20:16:04 2016 +0100
gegl: move caching of babl types/formats to an internal header
gegl/gegl-algorithms.c | 37 ++++++++++++++++---------------------
gegl/gegl-types-internal.h | 27 +++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 21 deletions(-)
---
diff --git a/gegl/gegl-algorithms.c b/gegl/gegl-algorithms.c
index 89740f5..a887cd7 100644
--- a/gegl/gegl-algorithms.c
+++ b/gegl/gegl-algorithms.c
@@ -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
diff --git a/gegl/gegl-types-internal.h b/gegl/gegl-types-internal.h
index 69a96f7..de5dd83 100644
--- a/gegl/gegl-types-internal.h
+++ b/gegl/gegl-types-internal.h
@@ -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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]