Procházet zdrojové kódy

Add a wave filter for crappy sine effects.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3397 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam před 15 roky
rodič
revize
2ff222affb
4 změnil soubory, kde provedl 120 přidání a 1 odebrání
  1. +2
    -1
      pipi/Makefile.am
  2. +26
    -0
      pipi/context.c
  3. +90
    -0
      pipi/filter/wave.c
  4. +2
    -0
      pipi/pipi.h

+ 2
- 1
pipi/Makefile.am Zobrazit soubor

@@ -72,7 +72,8 @@ filter_sources = \
filter/color.c \
filter/transform.c \
filter/median.c \
filter/dilate.c
filter/dilate.c \
filter/wave.c

quantize_sources = \
quantize/reduce.c


+ 26
- 0
pipi/context.c Zobrazit soubor

@@ -88,6 +88,7 @@ pipi_command_t const *pipi_get_command_list(void)
{ "screen", 0 },
{ "overlay", 0 },
{ "line", 1 },
{ "wave", 1 },

/* End marker */
{ NULL, 0 }
@@ -772,6 +773,31 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
x1, y1, x2, y2, color, aa);
ctx->nimages++;
}
else if(!strcmp(cmd, "wave"))
{
pipi_image_t *tmp;
char const *arg;
va_list ap;
float freq, phase, theta, ampx, ampy;
int ret;

if(ctx->nimages < 1)
return -1;

va_start(ap, 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)
return -1;

tmp = ctx->images[ctx->nimages - 1];
ctx->images[ctx->nimages - 1] = pipi_wave(tmp, freq, phase,
theta, ampx, ampy);
pipi_free(tmp);
}
else
{
return -1;


+ 90
- 0
pipi/filter/wave.c Zobrazit soubor

@@ -0,0 +1,90 @@
/*
* libpipi Pathetic image processing interface library
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This library is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

/*
* wave.c: wave and warping effects
*/

#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#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)
{
pipi_image_t *dst;
pipi_pixels_t *srcp, *dstp;
float *srcdata, *dstdata;
double sint, cost;
int x, y, w, h, i, gray;

w = src->w;
h = src->h;

gray = (src->last_modified == PIPI_PIXELS_Y_F32);

srcp = gray ? pipi_get_pixels(src, PIPI_PIXELS_Y_F32)
: pipi_get_pixels(src, PIPI_PIXELS_RGBA_F32);
srcdata = (float *)srcp->pixels;

dst = pipi_new(w, h);
dstp = gray ? pipi_get_pixels(dst, PIPI_PIXELS_Y_F32)
: pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
dstdata = (float *)dstp->pixels;

sint = sin(theta);
cost = cos(theta);

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 * step;
double dy = yamp * step;

int x2 = x + dx;
int y2 = y + dy;

if(x2 < 0) x2 = 0;
else if(x2 >= w) x2 = w - 1;

if(y2 < 0) y2 = 0;
else if(y2 >= h) y2 = h - 1;

if(gray)
{
dstdata[y * w + x] = srcdata[y2 * w + x2];
}
else
{
for(i = 0; i < 4; i++)
{
dstdata[4 * (y * w + x) + i]
= srcdata[4 * (y2 * w + x2) + i];
}
}
}
}

return dst;
}


+ 2
- 0
pipi/pipi.h Zobrazit soubor

@@ -197,6 +197,8 @@ __extern pipi_image_t *pipi_median(pipi_image_t *, int);
__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);

__extern pipi_image_t *pipi_order(pipi_image_t *);



Načítá se…
Zrušit
Uložit