Skip to content

Commit

Permalink
Translate comment from English to Chinese.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricporter committed Jul 14, 2012
1 parent 5243eb5 commit beeefb6
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions EffectLab/Effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,41 @@
import math, operator
from math import sqrt, sin, cos, atan2

# Filters that input Image and output Image
# Effect是特效处理流程中的过滤器,输入PIL中的Image,然后输出处理好的Image
# 其中,()是经过重载的,默认调用成员函数filter(img)。这样可以方便的与其他普通过滤器函数组合在一起。
#

class Effect(object):
'''The base Effect
All Effects have a member function called "filter"
which receives a PIL Image and return a PIL Image
'''
name = 'Base Effect'
empty_color = (128, 128, 128, 255)
def __init__(self):
pass

def __call__(self, img):
'''The effect can act like a filter function'''
'''重载(),模仿C++中的仿函数。
'''
return self.filter(img)

def filter(self, img):
return img


class LocalWarpEffect(Effect):
'''Interactive Image Warping Effect
@note 参考文献: Interactive Image Warping by Andreas Gustafsson
'''
def __init__(self, center, mouse, radius):
'''
@param center 局部变形效果的圆心,可以认为是鼠标按下起点
@param mouse 鼠标释放的位置
'''

self.center = center
self.mouse = mouse
self.radius = radius

def warp(self, x, y, r, center, mouse):
cx, cy = center
mx, my = mouse
Expand All @@ -47,10 +60,9 @@ def warp(self, x, y, r, center, mouse):
def filter(self, img):
width, height = img.size
new_img = img.copy()
r = 100
cx, cy = 100, 100
mx, my = 120, 120
f = lambda x, y: (x, y)
r = self.radius
cx, cy = self.center
mx, my = self.mouse

nband = len(img.getpixel((0, 0)))
antialias = 4
Expand All @@ -62,6 +74,7 @@ def filter(self, img):
found = 0
psum = (0, ) * nband

# anti-alias
for ai in range(antialias):
_x = x + ai / float(antialias)
for aj in range(antialias):
Expand All @@ -79,14 +92,15 @@ def filter(self, img):
if found > 0:
psum = map(operator.div, psum, (antialias * antialias, ) * len(psum))
new_img.putpixel((x, y), tuple(psum))
# new_img.putpixel((x, y), img.getpixel((u, v)) )

return new_img


class LensWarpEffect(Effect):
'''Lens warping Effect
provide basic entire image lens warping framework
全局性的镜头变形效果,构造的时候需要输入一个变换方程
f(x, y) => (x', y').其中,x和y都被规范化为-1到1的取值。
参考资料:http://paulbourke.net/miscellaneous/imagewarp/
'''
name = 'Warp Effect'

Expand Down Expand Up @@ -230,6 +244,7 @@ def filter(self, img):


class GridMaker(Effect):
'''用于绘制网格'''
name = 'Grid Maker'
def __init__(self, width_offset, height_offset, color=(0, 0, 0, 255)):
self.width_offset = width_offset
Expand Down

0 comments on commit beeefb6

Please sign in to comment.