Browse Source

* 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
remotes/tiles
sam 16 years ago
parent
commit
0cca668930
4 changed files with 25 additions and 40 deletions
  1. +1
    -1
      pipi/filter/blur.c
  2. +3
    -4
      pipi/filter/convolution.c
  3. +2
    -2
      pipi/paint/line.c
  4. +19
    -33
      pipi/pipi_template.h

+ 1
- 1
pipi/filter/blur.c View File

@@ -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;


+ 3
- 4
pipi/filter/convolution.c View File

@@ -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;


+ 2
- 2
pipi/paint/line.c View File

@@ -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;


+ 19
- 33
pipi/pipi_template.h View File

@@ -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


Loading…
Cancel
Save