From 196475c81320f2ecd731714dcfb3a29191167d1a Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Thu, 13 Sep 2012 21:37:54 +0200 Subject: Extensions. New HSL adjust extension (see Bug #979208 ). (bzr r11665) --- share/extensions/Makefile.am | 4 +- share/extensions/color_HSL_adjust.inx | 36 ++++++++++++++++++ share/extensions/color_HSL_adjust.py | 69 +++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 share/extensions/color_HSL_adjust.inx create mode 100644 share/extensions/color_HSL_adjust.py diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index 74d8d2fd8..16c8a2cc2 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -26,6 +26,7 @@ extensions = \ color_desaturate.py\ coloreffect.py\ color_grayscale.py\ + color_HSL_adjust.py\ color_lesshue.py\ color_lesslight.py\ color_lesssaturation.py\ @@ -204,6 +205,7 @@ modules = \ color_darker.inx\ color_desaturate.inx\ color_grayscale.inx\ + color_HSL_adjust.inx\ color_lesshue.inx\ color_lesslight.inx\ color_lesssaturation.inx\ @@ -228,7 +230,7 @@ modules = \ dxf_output.inx \ edge3d.inx \ embedimage.inx \ - embedselectedimages.inx \ + embedselectedimages.inx \ eps_input.inx \ eqtexsvg.inx \ export_gimp_palette.inx \ diff --git a/share/extensions/color_HSL_adjust.inx b/share/extensions/color_HSL_adjust.inx new file mode 100644 index 000000000..4c0330f53 --- /dev/null +++ b/share/extensions/color_HSL_adjust.inx @@ -0,0 +1,36 @@ + + + <_name>HSL Adjust + org.inkscape.color.HSL_adjust + coloreffect.py + color_HSL_adjust.py + simplestyle.py + + + 0 + false + 0 + false + 0 + false + + + <_param name="instructions" type="description" xml:space="preserve">Adjusts hue, saturation and lightness in the HSL representation of the selected objects's color. +Options: + * Hue: rotate by degrees (wraps around). + * Saturation: add/subtract % (min=-100, max=100). + * Lightness: add/subtract % (min=-100, max=100). + * Random Hue/Saturation/Lightness: randomize the parameter's value. + + + + + all + + + + + + diff --git a/share/extensions/color_HSL_adjust.py b/share/extensions/color_HSL_adjust.py new file mode 100644 index 000000000..473c4bd1e --- /dev/null +++ b/share/extensions/color_HSL_adjust.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +# standard library +import random +# local library +import coloreffect +import inkex + +class C(coloreffect.ColorEffect): + def __init__(self): + coloreffect.ColorEffect.__init__(self) + self.OptionParser.add_option("-x", "--hue", + action="store", type="int", + dest="hue", default="0", + help="Adjust hue") + self.OptionParser.add_option("-s", "--saturation", + action="store", type="int", + dest="saturation", default="0", + help="Adjust saturation") + self.OptionParser.add_option("-l", "--lightness", + action="store", type="int", + dest="lightness", default="0", + help="Adjust lightness") + self.OptionParser.add_option("", "--random_h", + action="store", type="inkbool", + dest="random_hue", default=False, + help="Randomize hue") + self.OptionParser.add_option("", "--random_s", + action="store", type="inkbool", + dest="random_saturation", default=False, + help="Randomize saturation") + self.OptionParser.add_option("", "--random_l", + action="store", type="inkbool", + dest="random_lightness", default=False, + help="Randomize lightness") + self.OptionParser.add_option("--tab", + action="store", type="string", + dest="tab", + help="The selected UI-tab when OK was pressed") + + def clamp(self, minimum, x, maximum): + return max(minimum, min(x, maximum)) + + def colmod(self, r, g, b): + hsl = self.rgb_to_hsl(r/255.0, g/255.0, b/255.0) + #inkex.debug("hsl old: " + str(hsl[0]) + ", " + str(hsl[1]) + ", " + str(hsl[2])) + if (self.options.random_hue): + hsl[0] = random.random() + elif (self.options.hue): + hueval = hsl[0] + (self.options.hue / 360.0) + hsl[0] = hueval % 1 + if(self.options.random_saturation): + hsl[1] = random.random() + elif (self.options.saturation): + satval = hsl[1] + (self.options.saturation / 100.0) + hsl[1] = self.clamp(0.0, satval, 1.0) + if(self.options.random_lightness): + hsl[2] = random.random() + elif (self.options.lightness): + lightval = hsl[2] + (self.options.lightness / 100.0) + hsl[2] = self.clamp(0.0, lightval, 1.0) + #inkex.debug("hsl new: " + str(hsl[0]) + ", " + str(hsl[1]) + ", " + str(hsl[2])) + 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() + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 -- cgit v1.2.3