Changeset 3410 for libpipi


Ignore:
Timestamp:
Mar 24, 2009, 1:48:53 AM (12 years ago)
Author:
Sam Hocevar
Message:

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.

Location:
libpipi/trunk/pipi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/context.c

    r3397 r3410  
    779779        char const *arg;
    780780        va_list ap;
    781         float freq, phase, theta, ampx, ampy;
     781        float dw, dh, d = 0.0, a = 0.0;
    782782        int ret;
    783783
     
    789789        va_end(ap);
    790790
    791         ret = sscanf(arg, "%g,%g,%g,%gx%g",
    792                      &freq, &phase, &theta, &ampx, &ampy);
    793         if(ret < 5)
    794             return -1;
    795 
    796         tmp = ctx->images[ctx->nimages - 1];
    797         ctx->images[ctx->nimages - 1] = pipi_wave(tmp, freq, phase,
    798                                                   theta, ampx, ampy);
     791        ret = sscanf(arg, "%gx%g+%gr%g", &dw, &dh, &d, &a);
     792        if(ret < 2)
     793            return -1;
     794
     795        tmp = ctx->images[ctx->nimages - 1];
     796        ctx->images[ctx->nimages - 1] = pipi_wave(tmp, dw, dh, d, a);
    799797        pipi_free(tmp);
    800798    }
  • libpipi/trunk/pipi/filter/wave.c

    r3403 r3410  
    2727#include "pipi_internals.h"
    2828
    29 pipi_image_t *pipi_wave(pipi_image_t *src, double freq, double phase,
    30                         double theta, double xamp, double yamp)
     29#define BORDER 64
     30
     31pipi_image_t *pipi_wave(pipi_image_t *src, double dw, double dh,
     32                        double d, double a)
    3133{
    3234    pipi_image_t *dst;
    3335    pipi_pixels_t *srcp, *dstp;
    3436    float *srcdata, *dstdata;
    35     double sint, cost;
     37    double sina, cosa;
    3638    int x, y, w, h, i, gray;
    3739
     
    5052    dstdata = (float *)dstp->pixels;
    5153
    52     sint = sin(theta);
    53     cost = cos(theta);
     54    sina = sin(a);
     55    cosa = cos(a);
    5456
    5557    for(y = 0; y < h; y++)
     
    5759        for(x = 0; x < w; x++)
    5860        {
    59             double t = cost * (x - w / 2) + sint * (y - h / 2);
    60             double step = sin(t * freq + phase);
    61             double dx = xamp;
    62             double dy = yamp;
     61            double angle = 2 * M_PI / dw * ((x - w / 2) * cosa
     62                                             + (y - h / 2) * sina - d);
     63            double displacement = dh * sin(angle);
     64            double dx, dy;
    6365            int x2, y2;
    6466
    65             if(x < 32) dx = dx * x / 32;
    66             if(x > w - 1 - 32) dx = dx * (w - 1 - x) / 32;
    67             if(y < 32) dy = dy * y / 32;
    68             if(y > h - 1 - 32) dy = dy * (h - 1 - y) / 32;
     67            dx = -sina * displacement;
     68            dy = cosa * displacement;
    6969
    70             x2 = x + dx * step;
    71             y2 = y + dy * step;
     70            if(x < BORDER) dx = dx * x / BORDER;
     71            if(x > w - 1 - BORDER) dx = dx * (w - 1 - x) / BORDER;
     72            if(y < BORDER) dy = dy * y / BORDER;
     73            if(y > h - 1 - BORDER) dy = dy * (h - 1 - y) / BORDER;
     74
     75            x2 = x + dx;
     76            y2 = y + dy;
    7277
    7378            /* Just in case... */
  • libpipi/trunk/pipi/pipi.h

    r3397 r3410  
    199199__extern pipi_image_t *pipi_erode(pipi_image_t *);
    200200__extern pipi_image_t *pipi_wave(pipi_image_t *, double, double,
    201                                  double, double, double);
     201                                 double, double);
    202202
    203203__extern pipi_image_t *pipi_order(pipi_image_t *);
Note: See TracChangeset for help on using the changeset viewer.