From 636c2c493e706e71318b902b762aeb9086f60766 Mon Sep 17 00:00:00 2001 From: buliabyak Date: Sat, 18 Nov 2006 18:08:42 +0000 Subject: [PATCH] add hsl adjusters; remove keep-rgb as redundant; update uris --- share/extensions/Makefile.am | 22 ++++--- share/extensions/color_brighter.inx | 2 +- share/extensions/color_custom.inx | 4 +- share/extensions/color_darker.inx | 2 +- share/extensions/color_desaturate.inx | 2 +- share/extensions/color_grayscale.inx | 2 +- share/extensions/color_keepblue.py | 8 --- share/extensions/color_keepgreen.py | 8 --- share/extensions/color_keepred.py | 8 --- .../{color_keepblue.inx => color_lesshue.inx} | 8 +-- share/extensions/color_lesshue.py | 14 +++++ ...olor_keepgreen.inx => color_lesslight.inx} | 8 +-- share/extensions/color_lesslight.py | 14 +++++ share/extensions/color_lesssaturation.inx | 16 +++++ share/extensions/color_lesssaturation.py | 14 +++++ .../{color_keepred.inx => color_morehue.inx} | 8 +-- share/extensions/color_morehue.py | 14 +++++ share/extensions/color_morelight.inx | 16 +++++ share/extensions/color_morelight.py | 14 +++++ share/extensions/color_moresaturation.inx | 16 +++++ share/extensions/color_moresaturation.py | 14 +++++ share/extensions/color_negative.inx | 2 +- share/extensions/color_removeblue.inx | 2 +- share/extensions/color_removegreen.inx | 2 +- share/extensions/color_removered.inx | 2 +- share/extensions/color_rgbbarrel.inx | 2 +- share/extensions/coloreffect.py | 60 +++++++++++++++++++ 27 files changed, 229 insertions(+), 55 deletions(-) delete mode 100644 share/extensions/color_keepblue.py delete mode 100644 share/extensions/color_keepgreen.py delete mode 100644 share/extensions/color_keepred.py rename share/extensions/{color_keepblue.inx => color_lesshue.inx} (55%) create mode 100644 share/extensions/color_lesshue.py rename share/extensions/{color_keepgreen.inx => color_lesslight.inx} (54%) create mode 100644 share/extensions/color_lesslight.py create mode 100644 share/extensions/color_lesssaturation.inx create mode 100644 share/extensions/color_lesssaturation.py rename share/extensions/{color_keepred.inx => color_morehue.inx} (55%) create mode 100644 share/extensions/color_morehue.py create mode 100644 share/extensions/color_morelight.inx create mode 100644 share/extensions/color_morelight.py create mode 100644 share/extensions/color_moresaturation.inx create mode 100644 share/extensions/color_moresaturation.py diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index bc0c0b49f..cbcba7f89 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -70,14 +70,17 @@ extensions = \ 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 + color_rgbbarrel.py\ + color_moresaturation.py\ + color_lesssaturation.py\ + color_morelight.py\ + color_lesslight.py\ + color_morehue.py\ + color_lesshue.py otherstuff = \ @@ -145,14 +148,17 @@ modules = \ 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 + color_custom.inx \ + color_moresaturation.inx\ + color_lesssaturation.inx\ + color_morelight.inx\ + color_lesslight.inx\ + color_morehue.inx\ + color_lesshue.inx extension_SCRIPTS = \ diff --git a/share/extensions/color_brighter.inx b/share/extensions/color_brighter.inx index adc34410d..48c7f5c91 100644 --- a/share/extensions/color_brighter.inx +++ b/share/extensions/color_brighter.inx @@ -1,6 +1,6 @@ <_name>Brighter - com.kaioa.brighter + org.inkscape.color.brighter coloreffect.py color_brighter.py simplestyle.py diff --git a/share/extensions/color_custom.inx b/share/extensions/color_custom.inx index 8ba2cd520..647caade7 100644 --- a/share/extensions/color_custom.inx +++ b/share/extensions/color_custom.inx @@ -1,6 +1,6 @@ - <_name>Custom - com.kaioa.zcustom + <_name>Custom... + org.inkscape.color.custom coloreffect.py color_custom.py simplestyle.py diff --git a/share/extensions/color_darker.inx b/share/extensions/color_darker.inx index aa937adc1..0408c788e 100644 --- a/share/extensions/color_darker.inx +++ b/share/extensions/color_darker.inx @@ -1,6 +1,6 @@ <_name>Darker - com.kaioa.darker + org.inkscape.color.darker coloreffect.py color_darker.py simplestyle.py diff --git a/share/extensions/color_desaturate.inx b/share/extensions/color_desaturate.inx index 2aa6c0201..5e25db525 100644 --- a/share/extensions/color_desaturate.inx +++ b/share/extensions/color_desaturate.inx @@ -1,6 +1,6 @@ <_name>Desaturate - com.kaioa.desaturate + org.inkscape.color.desaturate coloreffect.py color_desaturate.py simplestyle.py diff --git a/share/extensions/color_grayscale.inx b/share/extensions/color_grayscale.inx index 495a3aa18..d90ea8f3e 100644 --- a/share/extensions/color_grayscale.inx +++ b/share/extensions/color_grayscale.inx @@ -1,6 +1,6 @@ <_name>Grayscale - com.kaioa.grayscale + org.inkscape.color.grayscale coloreffect.py color_grayscale.py simplestyle.py diff --git a/share/extensions/color_keepblue.py b/share/extensions/color_keepblue.py deleted file mode 100644 index 205a87947..000000000 --- a/share/extensions/color_keepblue.py +++ /dev/null @@ -1,8 +0,0 @@ -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.py b/share/extensions/color_keepgreen.py deleted file mode 100644 index 3da5e451b..000000000 --- a/share/extensions/color_keepgreen.py +++ /dev/null @@ -1,8 +0,0 @@ -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.py b/share/extensions/color_keepred.py deleted file mode 100644 index 662e521e0..000000000 --- a/share/extensions/color_keepred.py +++ /dev/null @@ -1,8 +0,0 @@ -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_keepblue.inx b/share/extensions/color_lesshue.inx similarity index 55% rename from share/extensions/color_keepblue.inx rename to share/extensions/color_lesshue.inx index 900f5558b..453302650 100644 --- a/share/extensions/color_keepblue.inx +++ b/share/extensions/color_lesshue.inx @@ -1,8 +1,8 @@ - <_name>Keep Blue - com.kaioa.keepblue + <_name>Less Hue + org.inkscape.color.lesshue coloreffect.py - color_keepblue.py + color_lesshue.py simplestyle.py all @@ -11,6 +11,6 @@ \ No newline at end of file diff --git a/share/extensions/color_lesshue.py b/share/extensions/color_lesshue.py new file mode 100644 index 000000000..74ac5ae28 --- /dev/null +++ b/share/extensions/color_lesshue.py @@ -0,0 +1,14 @@ +import coloreffect, inkex + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0) + #inkex.debug("hsl: " + str(hsl[0]) + ", " + str(hsl[1]) + ", " + str(hsl[2])) + hsl[0] = hsl[0] - 0.05 + if hsl[0] < 0.0: + hsl[0] = 1.0 + hsl[0] + rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2]) + return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255) + +c = C() +c.affect() diff --git a/share/extensions/color_keepgreen.inx b/share/extensions/color_lesslight.inx similarity index 54% rename from share/extensions/color_keepgreen.inx rename to share/extensions/color_lesslight.inx index 0ee1dddd0..bf0989257 100644 --- a/share/extensions/color_keepgreen.inx +++ b/share/extensions/color_lesslight.inx @@ -1,8 +1,8 @@ - <_name>Keep Green - com.kaioa.keepgreen + <_name>Less Light + org.inkscape.color.lesslight coloreffect.py - color_keepgreen.py + color_lesslight.py simplestyle.py all @@ -11,6 +11,6 @@ \ No newline at end of file diff --git a/share/extensions/color_lesslight.py b/share/extensions/color_lesslight.py new file mode 100644 index 000000000..6f912f0ea --- /dev/null +++ b/share/extensions/color_lesslight.py @@ -0,0 +1,14 @@ +import coloreffect, inkex + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0) + #inkex.debug("hsl: " + str(hsl[0]) + ", " + str(hsl[1]) + ", " + str(hsl[2])) + hsl[2] = hsl[2] - 0.05 + if hsl[2] < 0.0: + hsl[2] = 0.0 + rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2]) + return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255) + +c = C() +c.affect() diff --git a/share/extensions/color_lesssaturation.inx b/share/extensions/color_lesssaturation.inx new file mode 100644 index 000000000..aa96cf14f --- /dev/null +++ b/share/extensions/color_lesssaturation.inx @@ -0,0 +1,16 @@ + + <_name>Less Saturation + org.inkscape.color.lesssaturation + coloreffect.py + color_lesssaturation.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_lesssaturation.py b/share/extensions/color_lesssaturation.py new file mode 100644 index 000000000..422a01994 --- /dev/null +++ b/share/extensions/color_lesssaturation.py @@ -0,0 +1,14 @@ +import coloreffect, inkex + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0) + #inkex.debug("hsl: " + str(hsl[0]) + ", " + str(hsl[1]) + ", " + str(hsl[2])) + hsl[1] = hsl[1] - 0.05 + if hsl[1] < 0.0: + hsl[1] = 0.0 + rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2]) + return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255) + +c = C() +c.affect() diff --git a/share/extensions/color_keepred.inx b/share/extensions/color_morehue.inx similarity index 55% rename from share/extensions/color_keepred.inx rename to share/extensions/color_morehue.inx index 824fa2bc4..76300ab78 100644 --- a/share/extensions/color_keepred.inx +++ b/share/extensions/color_morehue.inx @@ -1,8 +1,8 @@ - <_name>Keep Red - com.kaioa.keepred + <_name>More Hue + org.inkscape.color.morehue coloreffect.py - color_keepred.py + color_morehue.py simplestyle.py all @@ -11,6 +11,6 @@ \ No newline at end of file diff --git a/share/extensions/color_morehue.py b/share/extensions/color_morehue.py new file mode 100644 index 000000000..bc25274ac --- /dev/null +++ b/share/extensions/color_morehue.py @@ -0,0 +1,14 @@ +import coloreffect, inkex + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0) + #inkex.debug("hsl: " + str(hsl[0]) + ", " + str(hsl[1]) + ", " + str(hsl[2])) + hsl[0] = hsl[0] + 0.05 + if hsl[0] > 1.0: + hsl[0] = hsl[0] - 1.0 + rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2]) + return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255) + +c = C() +c.affect() diff --git a/share/extensions/color_morelight.inx b/share/extensions/color_morelight.inx new file mode 100644 index 000000000..8b97adf22 --- /dev/null +++ b/share/extensions/color_morelight.inx @@ -0,0 +1,16 @@ + + <_name>More Light + org.inkscape.color.morelight + coloreffect.py + color_morelight.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_morelight.py b/share/extensions/color_morelight.py new file mode 100644 index 000000000..483af7fa0 --- /dev/null +++ b/share/extensions/color_morelight.py @@ -0,0 +1,14 @@ +import coloreffect, inkex + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0) + #inkex.debug("hsl: " + str(hsl[0]) + ", " + str(hsl[1]) + ", " + str(hsl[2])) + hsl[2] = hsl[2] + 0.05 + if hsl[2] > 1.0: + hsl[2] = 1.0 + rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2]) + return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255) + +c = C() +c.affect() diff --git a/share/extensions/color_moresaturation.inx b/share/extensions/color_moresaturation.inx new file mode 100644 index 000000000..0c4a0bfa9 --- /dev/null +++ b/share/extensions/color_moresaturation.inx @@ -0,0 +1,16 @@ + + <_name>More Saturation + org.inkscape.color.moresaturation + coloreffect.py + color_moresaturation.py + simplestyle.py + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_moresaturation.py b/share/extensions/color_moresaturation.py new file mode 100644 index 000000000..2ae7f33b7 --- /dev/null +++ b/share/extensions/color_moresaturation.py @@ -0,0 +1,14 @@ +import coloreffect, inkex + +class C(coloreffect.ColorEffect): + def colmod(self,r,g,b): + hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0) + #inkex.debug("hsl: " + str(hsl[0]) + ", " + str(hsl[1]) + ", " + str(hsl[2])) + hsl[1] = hsl[1] + 0.05 + if hsl[1] > 1.0: + hsl[1] = 1.0 + rgb = self.hsl_to_rgb(hsl[0], hsl[1], hsl[2]) + return '%02x%02x%02x' % (rgb[0]*255, rgb[1]*255, rgb[2]*255) + +c = C() +c.affect() diff --git a/share/extensions/color_negative.inx b/share/extensions/color_negative.inx index 7dc73c3cc..bdf0f4cb0 100644 --- a/share/extensions/color_negative.inx +++ b/share/extensions/color_negative.inx @@ -1,6 +1,6 @@ <_name>Negative - com.kaioa.negative + org.inkscape.color.negative coloreffect.py color_negative.py simplestyle.py diff --git a/share/extensions/color_removeblue.inx b/share/extensions/color_removeblue.inx index 2dadb5a53..db3062ff5 100644 --- a/share/extensions/color_removeblue.inx +++ b/share/extensions/color_removeblue.inx @@ -1,6 +1,6 @@ <_name>Remove Blue - com.kaioa.removeblue + org.inkscape.color.removeblue coloreffect.py color_removeblue.py simplestyle.py diff --git a/share/extensions/color_removegreen.inx b/share/extensions/color_removegreen.inx index 13ea8666b..2e70dea29 100644 --- a/share/extensions/color_removegreen.inx +++ b/share/extensions/color_removegreen.inx @@ -1,6 +1,6 @@ <_name>Remove Green - com.kaioa.removegreen + org.inkscape.color.removegreen coloreffect.py color_removegreen.py simplestyle.py diff --git a/share/extensions/color_removered.inx b/share/extensions/color_removered.inx index ef74410d7..1565fc676 100644 --- a/share/extensions/color_removered.inx +++ b/share/extensions/color_removered.inx @@ -1,6 +1,6 @@ <_name>Remove Red - com.kaioa.removered + org.inkscape.color.removered coloreffect.py color_removered.py simplestyle.py diff --git a/share/extensions/color_rgbbarrel.inx b/share/extensions/color_rgbbarrel.inx index a676dae85..79d2fbc7d 100644 --- a/share/extensions/color_rgbbarrel.inx +++ b/share/extensions/color_rgbbarrel.inx @@ -1,6 +1,6 @@ <_name>RGB Barrel - com.kaioa.rgbbarrel + org.inkscape.color.rgbbarrel coloreffect.py color_rgbbarrel.py simplestyle.py diff --git a/share/extensions/coloreffect.py b/share/extensions/coloreffect.py index c1ed15065..688199475 100644 --- a/share/extensions/coloreffect.py +++ b/share/extensions/coloreffect.py @@ -24,6 +24,7 @@ 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) @@ -105,3 +106,62 @@ class ColorEffect(inkex.Effect): def colmod(self,r,g,b): pass + + def rgb_to_hsl(self,r, g, b): + rgb_max = max (max (r, g), b) + rgb_min = min (min (r, g), b) + delta = rgb_max - rgb_min + hsl = [0.0, 0.0, 0.0] + hsl[2] = (rgb_max + rgb_min)/2.0 + if delta == 0: + hsl[0] = 0.0 + hsl[1] = 0.0 + else: + if hsl[2] <= 0.5: + hsl[1] = delta / (rgb_max + rgb_min) + else: + hsl[1] = delta / (2 - rgb_max - rgb_min) + if r == rgb_max: + hsl[0] = (g - b) / delta + else: + if g == rgb_max: + hsl[0] = 2.0 + (b - r) / delta + else: + if b == rgb_max: + hsl[0] = 4.0 + (r - g) / delta + hsl[0] = hsl[0] / 6.0 + if hsl[0] < 0: + hsl[0] = hsl[0] + 1 + if hsl[0] > 1: + hsl[0] = hsl[0] - 1 + return hsl + + def hue_2_rgb (self, v1, v2, h): + if h < 0: + h += 6.0 + if h > 6: + h -= 6.0 + if h < 1: + return v1 + (v2 - v1) * h + if h < 3: + return v2 + if h < 4: + return v1 + (v2 - v1) * (4 - h) + return v1 + + def hsl_to_rgb (self,h, s, l): + rgb = [0, 0, 0] + if s == 0: + rgb[0] = l + rgb[1] = l + rgb[2] = l + else: + if l < 0.5: + v2 = l * (1 + s) + else: + v2 = l + s - l*s + v1 = 2*l - v2 + rgb[0] = self.hue_2_rgb (v1, v2, h*6 + 2.0) + rgb[1] = self.hue_2_rgb (v1, v2, h*6) + rgb[2] = self.hue_2_rgb (v1, v2, h*6 - 2.0) + return rgb -- 2.30.2