Quellcode durchsuchen

wave.c: change the wave arguments. The format is now eg. 150x100+10r1.3 where

150 is the wave period, 100 is the amplitude, 10 is the phase, and 1.3 is
the angle of the wave direction.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3410 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam vor 16 Jahren
Ursprung
Commit
b7e3368c23
3 geänderte Dateien mit 25 neuen und 22 gelöschten Zeilen
  1. +4
    -6
      pipi/context.c
  2. +20
    -15
      pipi/filter/wave.c
  3. +1
    -1
      pipi/pipi.h

+ 4
- 6
pipi/context.c Datei anzeigen

@@ -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, &ampx, &ampy);
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


+ 20
- 15
pipi/filter/wave.c Datei anzeigen

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


+ 1
- 1
pipi/pipi.h Datei anzeigen

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



Laden…
Abbrechen
Speichern