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;