From ddc28a0735c5c8b3ae8d2ec55da49ba491625284 Mon Sep 17 00:00:00 2001 From: Cedric Porter Date: Mon, 30 Jul 2012 14:40:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9E=E5=AE=9A=E4=BA=86=EF=BC=8C=E6=97=A5?= =?UTF-8?q?=E5=90=8E=E5=9C=A8=E6=95=B4=E7=90=86=E9=87=8D=E6=9E=84=E4=B8=80?= =?UTF-8?q?=E4=B8=8B=E4=BB=A3=E7=A0=81=EF=BC=8C=E9=87=8C=E9=9D=A2=E5=BE=88?= =?UTF-8?q?=E5=A4=9A=E5=86=97=E4=BD=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EffectLab/Effect.py | 16 +++++++++++----- EffectLab/core.c | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/EffectLab/Effect.py b/EffectLab/Effect.py index cf9464f..7e38348 100755 --- a/EffectLab/Effect.py +++ b/EffectLab/Effect.py @@ -261,7 +261,10 @@ def __init__(self, formula, antialias=2): self.antialias = antialias def filter(self, img): - return core.radian_warp(img, self.formula, self.antialias, self.empty_color) + try: + return core.radian_warp(img, self.formula, self.antialias, self.empty_color) + except: + pass def radian_formula(x, y): '''transform formula @@ -290,20 +293,23 @@ def __init__(self): class GlobalWaveEffect(Effect): '''全局波浪效果,使用sin进行变换 ''' - def __init__(self, dw=1, dh=0.1, antialias=2): + def __init__(self, dw=1, dh=0.1, xoffset=0, antialias=2): self.dw = dw self.dh = dh self.antialias = antialias + self.xoffset = xoffset def transform(self, x, y, width, height, delta_w, delta_h): - radian = 2 * math.pi * x / float(width) * delta_w + radian = 2 * math.pi * (x + self.xoffset) / float(width) * delta_w offset = 0.5 * sin(radian) * height * delta_h return x, y + offset def filter(self, img): - return core.wave_warp(img, self.dw, self.dh, self.antialias, self.empty_color) - + try: + return core.wave_warp(img, self.dw, self.dh, self.xoffset, self.antialias, self.empty_color) + except: + pass width, height = img.size f = lambda x, y: self.transform(x, y, width, height, self.dw, self.dh) diff --git a/EffectLab/core.c b/EffectLab/core.c index 20916ee..cdedbfe 100644 --- a/EffectLab/core.c +++ b/EffectLab/core.c @@ -268,8 +268,9 @@ static PyObject* wave_warp(PyObject *self, PyObject *args) double radian; double offset; int er, eg, eb, ea; + double xoffset; - if (!PyArg_ParseTuple(args, "OddiO", &image, &dw, &dh, &antialias, &empty_color)) + if (!PyArg_ParseTuple(args, "OdddiO", &image, &dw, &dh, &xoffset, &antialias, &empty_color)) { return NULL; } @@ -322,7 +323,7 @@ static PyObject* wave_warp(PyObject *self, PyObject *args) yy = j + aj / (double)antialias; /* ------------------------- */ - radian = 2 * 3.14159265 * xx / (double)width * dw; + radian = 2 * 3.14159265 * (xx + xoffset) / (double)width * dw; offset = 0.5 * sin(radian) * height * dh; xnew = xx;