From 0cca66893078fb1fa1e79d9d2c2994407f18fd47 Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 29 Aug 2008 21:34:42 +0000 Subject: [PATCH] * pipi_template.h: factor the last unrolled preprocessor loop. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2806 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/filter/blur.c | 2 +- pipi/filter/convolution.c | 7 +++--- pipi/paint/line.c | 4 +-- pipi/pipi_template.h | 52 ++++++++++++++------------------------- 4 files changed, 25 insertions(+), 40 deletions(-) diff --git a/pipi/filter/blur.c b/pipi/filter/blur.c index bfc8645..5bb2d79 100644 --- a/pipi/filter/blur.c +++ b/pipi/filter/blur.c @@ -149,7 +149,7 @@ pipi_image_t *pipi_box_blur_ext(pipi_image_t *src, int m, int n) #else /* XXX: the following functions use the template system */ -static pipi_image_t *SUFFIX(boxblur)(pipi_image_t *src, int m, int n) +static pipi_image_t *T(boxblur)(pipi_image_t *src, int m, int n) { pipi_image_t *dst; pipi_pixels_t *srcp, *dstp; diff --git a/pipi/filter/convolution.c b/pipi/filter/convolution.c index 0c5ef18..7ffa31b 100644 --- a/pipi/filter/convolution.c +++ b/pipi/filter/convolution.c @@ -112,8 +112,7 @@ pipi_image_t *pipi_convolution(pipi_image_t *src, int m, int n, double mat[]) #else /* XXX: the following functions use the template system */ -static pipi_image_t *SUFFIX(conv)(pipi_image_t *src, - int m, int n, double mat[]) +static pipi_image_t *T(conv)(pipi_image_t *src, int m, int n, double mat[]) { pipi_image_t *dst; pipi_pixels_t *srcp, *dstp; @@ -179,8 +178,8 @@ static pipi_image_t *SUFFIX(conv)(pipi_image_t *src, return dst; } -static pipi_image_t *SUFFIX(sepconv)(pipi_image_t *src, - int m, double hvec[], int n, double vvec[]) +static pipi_image_t *T(sepconv)(pipi_image_t *src, + int m, double hvec[], int n, double vvec[]) { pipi_image_t *dst; pipi_pixels_t *srcp, *dstp; diff --git a/pipi/paint/line.c b/pipi/paint/line.c index 0b4dc49..0f2542d 100644 --- a/pipi/paint/line.c +++ b/pipi/paint/line.c @@ -239,7 +239,7 @@ static uint8_t clip_bits(pipi_image_t *img, int x, int y) } \ } -static void SUFFIX(aaline)(pipi_image_t *img, struct line* s) +static void T(aaline)(pipi_image_t *img, struct line* s) { float x1 = s->x1, y1 = s->y1, x2 = s->x2, y2 = s->y2; float g, xd, yd, xgap, xend, yend, xf, yf, val1, val2; @@ -360,7 +360,7 @@ static void SUFFIX(aaline)(pipi_image_t *img, struct line* s) /* Solid line drawing function, using Bresenham's mid-point line * scan-conversion algorithm. */ -static void SUFFIX(line)(pipi_image_t *img, struct line* s) +static void T(line)(pipi_image_t *img, struct line* s) { int x1, y1, x2, y2; int dx, dy; diff --git a/pipi/pipi_template.h b/pipi/pipi_template.h index afec77b..92f2041 100644 --- a/pipi/pipi_template.h +++ b/pipi/pipi_template.h @@ -18,77 +18,63 @@ * * TEMPLATE_FLAGS is set to a list of toggle flags, a binary OR of: * - SET_FLAG_GRAY * - SET_FLAG_WRAP + * - SET_FLAG_8BIT * * TEMPLATE_FILE is set to the template file. The following macros * will be defined when including it. Their value depend on the flags * specified above: * - FLAG_GRAY is set to 0 or 1 * - FLAG_WRAP is set to 0 or 1 - * - SUFFIX(x) expands x by adding relevant information, eg. x##_gray_wrap + * - FLAG_8BIT is set to 0 or 1 + * - T(x) expands x by adding relevant information, eg. x##_gray_wrap */ #if !defined FLAG_GRAY # if (TEMPLATE_FLAGS) & SET_FLAG_GRAY # define FLAG_GRAY 1 +# define T_GRAY(x) CAT(x, _gray) # include __FILE__ # undef FLAG_GRAY +# undef T_GRAY # endif # define FLAG_GRAY 0 +# define T_GRAY(x) x # include __FILE__ # undef FLAG_GRAY +# undef T_GRAY #elif !defined FLAG_WRAP # if (TEMPLATE_FLAGS) & SET_FLAG_WRAP # define FLAG_WRAP 1 +# define T_WRAP(x) CAT(x, _wrap) # include __FILE__ # undef FLAG_WRAP +# undef T_WRAP # endif # define FLAG_WRAP 0 +# define T_WRAP(x) x # include __FILE__ # undef FLAG_WRAP +# undef T_WRAP #elif !defined FLAG_8BIT # if (TEMPLATE_FLAGS) & SET_FLAG_8BIT # define FLAG_8BIT 1 +# define T_8BIT(x) CAT(x, _8bit) # include __FILE__ # undef FLAG_8BIT +# undef T_8BIT # endif # define FLAG_8BIT 0 +# define T_8BIT(x) x # include __FILE__ # undef FLAG_8BIT +# undef T_8BIT #else - /* FIXME: I couldn't find a way to do this in one preprocessor pass, - * too many levels of indirection seem to be needed. */ -# if FLAG_8BIT -# if FLAG_WRAP -# if FLAG_GRAY -# define SUFFIX(x) x##_gray_wrap_8bit -# else -# define SUFFIX(x) x##_wrap_8bit -# endif -# else -# if FLAG_GRAY -# define SUFFIX(x) x##_gray_8bit -# else -# define SUFFIX(x) x##_8bit -# endif -# endif -# else -# if FLAG_WRAP -# if FLAG_GRAY -# define SUFFIX(x) x##_gray_wrap -# else -# define SUFFIX(x) x##_wrap -# endif -# else -# if FLAG_GRAY -# define SUFFIX(x) x##_gray -# else -# define SUFFIX(x) x -# endif -# endif -# endif +# define CAT(x, y) x ## y +# define T(x) T_8BIT(T_WRAP(T_GRAY(x))) # include TEMPLATE_FILE -# undef SUFFIX +# undef CAT +# undef S #endif