import coloreffect import os import math import sys import inkex palette=[] #loads lliurex palette def load_palette(pal_name): if os.path.exists("/usr/share/inkscape/palettes/"+pal_name): f=open("/usr/share/inkscape/palettes/"+pal_name) lines=f.readlines() for line in lines: tmp=line.split() if len(tmp)>3: c=(int(tmp[0]),int(tmp[1]),int(tmp[2])) palette.append(c) f.close() class C(coloreffect.ColorEffect): def __init__(self): coloreffect.ColorEffect.__init__(self) self.OptionParser.add_option('--type', type = 'string', dest = 'pal_name', default = 'llx-gartoon.gpl') opt,args=self.OptionParser.parse_args() load_palette(opt.pal_name) def colmod(self,r,g,b): best=None best_dist=1000000 #palette lookup for color in palette: ar,ag,ab=color #color differential dr=ar-r dg=ag-g db=ab-b #color square dist dist=(dr*dr)+(dg*dg)+(db*db) #euclidean dist dist=math.sqrt(dist) if dist