diff --git a/pipi/context.c b/pipi/context.c index efe366c..4238747 100644 --- a/pipi/context.c +++ b/pipi/context.c @@ -778,7 +778,7 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) pipi_image_t *tmp; char const *arg; va_list ap; - float freq, phase, theta, ampx, ampy; + float dw, dh, d = 0.0, a = 0.0; int ret; if(ctx->nimages < 1) @@ -788,14 +788,12 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) arg = va_arg(ap, char const *); va_end(ap); - ret = sscanf(arg, "%g,%g,%g,%gx%g", - &freq, &phase, &theta, &x, &y); - if(ret < 5) + ret = sscanf(arg, "%gx%g+%gr%g", &dw, &dh, &d, &a); + if(ret < 2) return -1; tmp = ctx->images[ctx->nimages - 1]; - ctx->images[ctx->nimages - 1] = pipi_wave(tmp, freq, phase, - theta, ampx, ampy); + ctx->images[ctx->nimages - 1] = pipi_wave(tmp, dw, dh, d, a); pipi_free(tmp); } else diff --git a/pipi/filter/wave.c b/pipi/filter/wave.c index cb82876..416fc45 100644 --- a/pipi/filter/wave.c +++ b/pipi/filter/wave.c @@ -26,13 +26,15 @@ #include "pipi.h" #include "pipi_internals.h" -pipi_image_t *pipi_wave(pipi_image_t *src, double freq, double phase, - double theta, double xamp, double yamp) +#define BORDER 64 + +pipi_image_t *pipi_wave(pipi_image_t *src, double dw, double dh, + double d, double a) { pipi_image_t *dst; pipi_pixels_t *srcp, *dstp; float *srcdata, *dstdata; - double sint, cost; + double sina, cosa; int x, y, w, h, i, gray; w = src->w; @@ -49,26 +51,29 @@ pipi_image_t *pipi_wave(pipi_image_t *src, double freq, double phase, : pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32); dstdata = (float *)dstp->pixels; - sint = sin(theta); - cost = cos(theta); + sina = sin(a); + cosa = cos(a); for(y = 0; y < h; y++) { for(x = 0; x < w; x++) { - double t = cost * (x - w / 2) + sint * (y - h / 2); - double step = sin(t * freq + phase); - double dx = xamp; - double dy = yamp; + double angle = 2 * M_PI / dw * ((x - w / 2) * cosa + + (y - h / 2) * sina - d); + double displacement = dh * sin(angle); + double dx, dy; int x2, y2; - if(x < 32) dx = dx * x / 32; - if(x > w - 1 - 32) dx = dx * (w - 1 - x) / 32; - if(y < 32) dy = dy * y / 32; - if(y > h - 1 - 32) dy = dy * (h - 1 - y) / 32; + dx = -sina * displacement; + dy = cosa * displacement; + + if(x < BORDER) dx = dx * x / BORDER; + if(x > w - 1 - BORDER) dx = dx * (w - 1 - x) / BORDER; + if(y < BORDER) dy = dy * y / BORDER; + if(y > h - 1 - BORDER) dy = dy * (h - 1 - y) / BORDER; - x2 = x + dx * step; - y2 = y + dy * step; + x2 = x + dx; + y2 = y + dy; /* Just in case... */ if(x2 < 0) x2 = 0; diff --git a/pipi/pipi.h b/pipi/pipi.h index 0a8d627..9f7288b 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -198,7 +198,7 @@ __extern pipi_image_t *pipi_median_ext(pipi_image_t *, int, int); __extern pipi_image_t *pipi_dilate(pipi_image_t *); __extern pipi_image_t *pipi_erode(pipi_image_t *); __extern pipi_image_t *pipi_wave(pipi_image_t *, double, double, - double, double, double); + double, double); __extern pipi_image_t *pipi_order(pipi_image_t *);