1 import coloreffect
3 class C(coloreffect.ColorEffect):
4 def __init__(self):
5 coloreffect.ColorEffect.__init__(self)
6 self.OptionParser.add_option("--r", action="store", type="string", dest="rFunction", default="r",help="red channel function")
7 self.OptionParser.add_option("--g", action="store", type="string", dest="gFunction", default="g",help="green channel function")
8 self.OptionParser.add_option("--b", action="store", type="string", dest="bFunction", default="b",help="blue channel function")
9 def normalize(self, v):
10 if v<0:
11 return 0.0
12 if v>1:
13 return 1.0
14 return v
15 def colmod(self,_r,_g,_b):
16 r=float(_r)/255
17 g=float(_g)/255
18 b=float(_b)/255
19 r2=self.normalize(eval(self.options.rFunction))
20 g2=self.normalize(eval(self.options.gFunction))
21 b2=self.normalize(eval(self.options.bFunction))
22 return '%02x%02x%02x' % (int(round(r2*255)),int(round(g2*255)),int(round(b2*255)))
24 c = C()
25 c.affect()