From b97c841ca6aa0a4f8ff56e7760e85b2d57d95b15 Mon Sep 17 00:00:00 2001 From: buliabyak Date: Wed, 15 Nov 2006 09:04:37 +0000 Subject: [PATCH] color effects --- share/extensions/Makefile.am | 32 ++++++++- share/extensions/color_brighter.inx | 16 +++++ share/extensions/color_brighter.py | 24 +++++++ share/extensions/color_custom.inx | 19 +++++ share/extensions/color_custom.py | 31 ++++++++ share/extensions/color_darker.inx | 16 +++++ share/extensions/color_darker.py | 12 ++++ share/extensions/color_desaturate.inx | 16 +++++ share/extensions/color_desaturate.py | 10 +++ share/extensions/color_grayscale.inx | 16 +++++ share/extensions/color_grayscale.py | 14 ++++ share/extensions/color_keepblue.inx | 16 +++++ share/extensions/color_keepblue.py | 8 +++ share/extensions/color_keepgreen.inx | 16 +++++ share/extensions/color_keepgreen.py | 8 +++ share/extensions/color_keepred.inx | 16 +++++ share/extensions/color_keepred.py | 8 +++ share/extensions/color_negative.inx | 16 +++++ share/extensions/color_negative.py | 8 +++ share/extensions/color_removeblue.inx | 16 +++++ share/extensions/color_removeblue.py | 8 +++ share/extensions/color_removegreen.inx | 16 +++++ share/extensions/color_removegreen.py | 8 +++ share/extensions/color_removered.inx | 16 +++++ share/extensions/color_removered.py | 8 +++ share/extensions/color_rgbbarrel.inx | 16 +++++ share/extensions/color_rgbbarrel.py | 8 +++ share/extensions/coloreffect.py | 98 ++++++++++++++++++++++++++ 28 files changed, 494 insertions(+), 2 deletions(-) create mode 100644 share/extensions/color_brighter.inx create mode 100644 share/extensions/color_brighter.py create mode 100644 share/extensions/color_custom.inx create mode 100644 share/extensions/color_custom.py create mode 100644 share/extensions/color_darker.inx create mode 100644 share/extensions/color_darker.py create mode 100644 share/extensions/color_desaturate.inx create mode 100644 share/extensions/color_desaturate.py create mode 100644 share/extensions/color_grayscale.inx create mode 100644 share/extensions/color_grayscale.py create mode 100644 share/extensions/color_keepblue.inx create mode 100644 share/extensions/color_keepblue.py create mode 100644 share/extensions/color_keepgreen.inx create mode 100644 share/extensions/color_keepgreen.py create mode 100644 share/extensions/color_keepred.inx create mode 100644 share/extensions/color_keepred.py create mode 100644 share/extensions/color_negative.inx create mode 100644 share/extensions/color_negative.py create mode 100644 share/extensions/color_removeblue.inx create mode 100644 share/extensions/color_removeblue.py create mode 100644 share/extensions/color_removegreen.inx create mode 100644 share/extensions/color_removegreen.py create mode 100644 share/extensions/color_removered.inx create mode 100644 share/extensions/color_removered.py create mode 100644 share/extensions/color_rgbbarrel.inx create mode 100644 share/extensions/color_rgbbarrel.py create mode 100644 share/extensions/coloreffect.py diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index 33afbd014..bc0c0b49f 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -63,7 +63,22 @@ extensions = \ webbrowser_reportabug.py \ webbrowser_svgspec.py \ webbrowser_commandline.py \ - webbrowser_faq.py + webbrowser_faq.py\ + color_custom.py\ + color_desaturate.py\ + coloreffect.py\ + color_grayscale.py\ + color_brighter.py\ + color_darker.py\ + color_keepblue.py\ + color_keepgreen.py\ + color_keepred.py\ + color_negative.py\ + color_removeblue.py\ + color_removegreen.py\ + color_removered.py\ + color_rgbbarrel.py + otherstuff = \ aisvg.xslt @@ -124,7 +139,20 @@ modules = \ inkscape_help_reportabug.inx \ inkscape_help_svgspec.inx \ inkscape_help_commandline.inx \ - inkscape_help_faq.inx + inkscape_help_faq.inx\ + color_brighter.inx\ + color_darker.inx\ + color_desaturate.inx\ + color_grayscale.inx\ + color_negative.inx\ + color_keepblue.inx\ + color_keepgreen.inx\ + color_keepred.inx\ + color_removeblue.inx\ + color_removegreen.inx\ + color_removered.inx\ + color_rgbbarrel.inx\ + color_custom.inx extension_SCRIPTS = \ diff --git a/share/extensions/color_brighter.inx b/share/extensions/color_brighter.inx new file mode 100644 index 000000000..adc34410d --- /dev/null +++ b/share/extensions/color_brighter.inx @@ -0,0 +1,16 @@ + + <_name>Brighter + com.kaioa.brighter + coloreffect.py + color_brighter.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_brighter.py b/share/extensions/color_brighter.py new file mode 100644 index 000000000..d7a52ee70 --- /dev/null +++ b/share/extensions/color_brighter.py @@ -0,0 +1,24 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + FACTOR=0.9 + + i=int(1.0/(1.0-FACTOR)) + if r==0 and g==0 and b==0: + return '%02x%02x%02x' % (i,i,i) + if r>0 and r0 and g0 and b + <_name>Custom + com.kaioa.zcustom + coloreffect.py + color_custom.py + simplestyle.py + r + g + b + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_custom.py b/share/extensions/color_custom.py new file mode 100644 index 000000000..b3daced30 --- /dev/null +++ b/share/extensions/color_custom.py @@ -0,0 +1,31 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def __init__(self): + coloreffect.ColorEffect.__init__(self) + self.OptionParser.add_option("--r", action="store", type="string", dest="rFunction", default="r",help="red channel function") + self.OptionParser.add_option("--g", action="store", type="string", dest="gFunction", default="g",help="green channel function") + self.OptionParser.add_option("--b", action="store", type="string", dest="bFunction", default="b",help="blue channel function") + def normalize(self, v): + if v<0: + return 0.0 + if v>1: + return 1.0 + return v + def colmod(self,_r,_g,_b): + r=float(_r)/255 + g=float(_g)/255 + b=float(_b)/255 + #coloreffect.debug('I: %f %f %f' % (r,g,b)) + r=eval(self.options.rFunction) + g=eval(self.options.gFunction) + b=eval(self.options.bFunction) + #coloreffect.debug('E: %f %f %f' % (r,g,b)) + r=self.normalize(r) + g=self.normalize(g) + b=self.normalize(b) + #coloreffect.debug('N: %f %f %f' % (r,g,b)) + return '%02x%02x%02x' % (int(round(r*255)),int(round(g*255)),int(round(b*255))) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_darker.inx b/share/extensions/color_darker.inx new file mode 100644 index 000000000..aa937adc1 --- /dev/null +++ b/share/extensions/color_darker.inx @@ -0,0 +1,16 @@ + + <_name>Darker + com.kaioa.darker + coloreffect.py + color_darker.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_darker.py b/share/extensions/color_darker.py new file mode 100644 index 000000000..ce8899444 --- /dev/null +++ b/share/extensions/color_darker.py @@ -0,0 +1,12 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + FACTOR=0.9 + r=int(round(max(r*FACTOR,0))) + g=int(round(max(g*FACTOR,0))) + b=int(round(max(b*FACTOR,0))) + return '%02x%02x%02x' % (r,g,b) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_desaturate.inx b/share/extensions/color_desaturate.inx new file mode 100644 index 000000000..2aa6c0201 --- /dev/null +++ b/share/extensions/color_desaturate.inx @@ -0,0 +1,16 @@ + + <_name>Desaturate + com.kaioa.desaturate + coloreffect.py + color_desaturate.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_desaturate.py b/share/extensions/color_desaturate.py new file mode 100644 index 000000000..efdf2658a --- /dev/null +++ b/share/extensions/color_desaturate.py @@ -0,0 +1,10 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + l = (max(r,g,b)+min(r,g,b))/2 + ig=int(round(l)) + return '%02x%02x%02x' % (ig,ig,ig) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_grayscale.inx b/share/extensions/color_grayscale.inx new file mode 100644 index 000000000..495a3aa18 --- /dev/null +++ b/share/extensions/color_grayscale.inx @@ -0,0 +1,16 @@ + + <_name>Grayscale + com.kaioa.grayscale + coloreffect.py + color_grayscale.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_grayscale.py b/share/extensions/color_grayscale.py new file mode 100644 index 000000000..e8c44459a --- /dev/null +++ b/share/extensions/color_grayscale.py @@ -0,0 +1,14 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + #ITU-R Recommendation BT.709 + #l = 0.2125 * r + 0.7154 * g + 0.0721 * b + #NTSC and PAL + l = 0.299 * r + 0.587 * g + 0.114 * b + ig=int(round(l)) + #coloreffect.debug('gs '+hex(r)+' '+hex(g)+' '+hex(b)+'%02x%02x%02x' % (ig,ig,ig)) + return '%02x%02x%02x' % (ig,ig,ig) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_keepblue.inx b/share/extensions/color_keepblue.inx new file mode 100644 index 000000000..900f5558b --- /dev/null +++ b/share/extensions/color_keepblue.inx @@ -0,0 +1,16 @@ + + <_name>Keep Blue + com.kaioa.keepblue + coloreffect.py + color_keepblue.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_keepblue.py b/share/extensions/color_keepblue.py new file mode 100644 index 000000000..205a87947 --- /dev/null +++ b/share/extensions/color_keepblue.py @@ -0,0 +1,8 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + return '%02x%02x%02x' % (0,0,b) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_keepgreen.inx b/share/extensions/color_keepgreen.inx new file mode 100644 index 000000000..0ee1dddd0 --- /dev/null +++ b/share/extensions/color_keepgreen.inx @@ -0,0 +1,16 @@ + + <_name>Keep Green + com.kaioa.keepgreen + coloreffect.py + color_keepgreen.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_keepgreen.py b/share/extensions/color_keepgreen.py new file mode 100644 index 000000000..3da5e451b --- /dev/null +++ b/share/extensions/color_keepgreen.py @@ -0,0 +1,8 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + return '%02x%02x%02x' % (0,g,0) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_keepred.inx b/share/extensions/color_keepred.inx new file mode 100644 index 000000000..824fa2bc4 --- /dev/null +++ b/share/extensions/color_keepred.inx @@ -0,0 +1,16 @@ + + <_name>Keep Red + com.kaioa.keepred + coloreffect.py + color_keepred.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_keepred.py b/share/extensions/color_keepred.py new file mode 100644 index 000000000..662e521e0 --- /dev/null +++ b/share/extensions/color_keepred.py @@ -0,0 +1,8 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + return '%02x%02x%02x' % (r,0,0) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_negative.inx b/share/extensions/color_negative.inx new file mode 100644 index 000000000..7dc73c3cc --- /dev/null +++ b/share/extensions/color_negative.inx @@ -0,0 +1,16 @@ + + <_name>Negative + com.kaioa.negative + coloreffect.py + color_negative.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_negative.py b/share/extensions/color_negative.py new file mode 100644 index 000000000..0fb2fcecb --- /dev/null +++ b/share/extensions/color_negative.py @@ -0,0 +1,8 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + return '%02x%02x%02x' % (255-r,255-g,255-b) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_removeblue.inx b/share/extensions/color_removeblue.inx new file mode 100644 index 000000000..2dadb5a53 --- /dev/null +++ b/share/extensions/color_removeblue.inx @@ -0,0 +1,16 @@ + + <_name>Remove Blue + com.kaioa.removeblue + coloreffect.py + color_removeblue.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_removeblue.py b/share/extensions/color_removeblue.py new file mode 100644 index 000000000..90d3fe7c2 --- /dev/null +++ b/share/extensions/color_removeblue.py @@ -0,0 +1,8 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + return '%02x%02x%02x' % (r,g,0) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_removegreen.inx b/share/extensions/color_removegreen.inx new file mode 100644 index 000000000..13ea8666b --- /dev/null +++ b/share/extensions/color_removegreen.inx @@ -0,0 +1,16 @@ + + <_name>Remove Green + com.kaioa.removegreen + coloreffect.py + color_removegreen.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_removegreen.py b/share/extensions/color_removegreen.py new file mode 100644 index 000000000..87722df54 --- /dev/null +++ b/share/extensions/color_removegreen.py @@ -0,0 +1,8 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + return '%02x%02x%02x' % (r,0,b) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_removered.inx b/share/extensions/color_removered.inx new file mode 100644 index 000000000..ef74410d7 --- /dev/null +++ b/share/extensions/color_removered.inx @@ -0,0 +1,16 @@ + + <_name>Remove Red + com.kaioa.removered + coloreffect.py + color_removered.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_removered.py b/share/extensions/color_removered.py new file mode 100644 index 000000000..54d071e3f --- /dev/null +++ b/share/extensions/color_removered.py @@ -0,0 +1,8 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + return '%02x%02x%02x' % (0,g,b) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/color_rgbbarrel.inx b/share/extensions/color_rgbbarrel.inx new file mode 100644 index 000000000..a676dae85 --- /dev/null +++ b/share/extensions/color_rgbbarrel.inx @@ -0,0 +1,16 @@ + + <_name>RGB Barrel + com.kaioa.rgbbarrel + coloreffect.py + color_rgbbarrel.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_rgbbarrel.py b/share/extensions/color_rgbbarrel.py new file mode 100644 index 000000000..41a0a4e1b --- /dev/null +++ b/share/extensions/color_rgbbarrel.py @@ -0,0 +1,8 @@ +import coloreffect + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + return '%02x%02x%02x' % (b,r,g) + +c = C() +c.affect() \ No newline at end of file diff --git a/share/extensions/coloreffect.py b/share/extensions/coloreffect.py new file mode 100644 index 000000000..214495502 --- /dev/null +++ b/share/extensions/coloreffect.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +''' +Copyright (C) 2006 Jos Hirth, kaioa.com + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +''' +import sys, copy, optparse, simplestyle, inkex + +import xml.xpath + +color_props_fill=('fill:','stop-color:','flood-color:','lighting-color:') +color_props_stroke=('stroke:',) +color_props = color_props_fill + color_props_stroke + +class ColorEffect(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self,use_minidom=True) + + def effect(self): + if len(self.selected)==0: + self.getAttribs(self.document) + else: + for id,node in self.selected.iteritems(): + self.getAttribs(node) + + def getAttribs(self,node): + self.changeStyle(node) + if node.hasChildNodes(): + childs=node.childNodes + for child in childs: + self.getAttribs(child) + + def changeStyle(self,node): + if node.hasAttributes(): + style=node.getAttribute('style') # fixme: this will break for presentation attributes! + if style!='': + #inkex.debug('old style:'+style) + styles=style.split(';') + for i in range(len(styles)): + for c in range(len(color_props)): + if styles[i].startswith(color_props[c]): + styles[i]=color_props[c]+self.process_prop(styles[i][len(color_props[c]):]) + #inkex.debug('new style:'+';'.join(styles)) + node.setAttribute('style',';'.join(styles)) + ''' + def changeStyle(self,node): + if node.hasAttributes(): + sa=node.getAttribute('style') + if sa!='': + debug(sa) + styles=simplestyle.parseStyle(sa) + for c in range(len(colortags)): + if colortags[c] in styles.keys(): + styles[colortags[c]]=self.process_prop(styles[colortags[c]]) + node.setAttribute('style',simplestyle.formatStyle(styles)) + ''' + def process_prop(self,col): + #debug('got:'+col) + if simplestyle.isColor(col): + c=simplestyle.parseColor(col) + col='#'+self.colmod(c[0],c[1],c[2]) + #debug('made:'+col) + if col.startswith('url(#'): + id = col[len('url(#'):col.find(')')] + #inkex.debug('ID:' + id ) + path = '//*[@id="%s"]' % id + for node in xml.xpath.Evaluate(path,self.document): + self.process_gradient(node) + return col + + def process_gradient(self, node): + self.changeStyle(node) + if node.hasChildNodes(): + for child in node.childNodes: + self.process_gradient(child) + if node.hasAttributes(): + href=node.getAttribute('xlink:href') + if href.startswith('#'): + id = href[len('#'):len(href)] + #inkex.debug('ID:' + id ) + path = '//*[@id="%s"]' % id + for node in xml.xpath.Evaluate(path,self.document): + self.process_gradient(node) + + def colmod(self,r,g,b): + pass -- 2.30.2