Commit d7a7fbc5 authored by Martin Owens's avatar Martin Owens
Browse files

Cleanup to make inx and python code coherent.

parent 46f4171c
Pipeline #99889121 passed with stages
in 5 minutes
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Add Nodes</name>
<id>org.ekips.filter.addnodes</id>
<id>org.inkscape.filter.add_nodes</id>
<param name="method" type="optiongroup" appearance="combo" gui-text="Division method:">
<option value="bymax">By max. segment length</option>
<option value="bynum">By number of segments</option>
......
......@@ -26,27 +26,19 @@ This extension either adds nodes to a path so that
import math
import inkex
from inkex import bezier
from inkex.elements import PathElement
from inkex.paths import CubicSuperPath
from inkex.base import InkscapeExtension, SvgThroughMixin
class SplitIt(SvgThroughMixin, InkscapeExtension):
class AddNodes(inkex.EffectExtension):
"""Extension to split a path by adding nodes to it"""
def __init__(self):
super(SplitIt, self).__init__()
self.arg_parser.add_argument("--segments",
type=int,
dest="segments", default=2,
help="Number of segments to divide the path into")
self.arg_parser.add_argument("--max",
type=float,
dest="max", default=2,
help="Number of segments to divide the path into")
self.arg_parser.add_argument("--method",
type=str,
dest="method", default='',
help="The kind of division to perform")
def add_arguments(self, pars):
pars.add_argument("--segments", type=int, default=2,
help="Number of segments to divide the path into")
pars.add_argument("--max", type=float, default=2.0,
help="Number of segments to divide the path into")
pars.add_argument("--method", help="The kind of division to perform")
def effect(self):
for node in self.svg.get_selected(PathElement):
......@@ -72,4 +64,4 @@ class SplitIt(SvgThroughMixin, InkscapeExtension):
node.path = CubicSuperPath(new).to_path(curves_only=True)
if __name__ == '__main__':
SplitIt().run()
AddNodes().run()
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>HSL Adjust</name>
<id>org.inkscape.color.HSL_adjust</id>
<id>org.inkscape.color.hsl_adjust</id>
<dependency type="file" location="inx">coloreffect.py</dependency>
<param name="tab" type="notebook">
<page name="Options" gui-text="Options">
......
......@@ -8,32 +8,15 @@ import coloreffect
import inkex
from inkex import colors
class C(coloreffect.ColorEffect):
def __init__(self):
super(C, self).__init__()
self.arg_parser.add_argument("-x", "--hue",
type=int, default=0,
help="Adjust hue")
self.arg_parser.add_argument("-s", "--saturation",
type=int, default=0,
help="Adjust saturation")
self.arg_parser.add_argument("-l", "--lightness",
type=int, default=0,
help="Adjust lightness")
self.arg_parser.add_argument("--random_h",
type=inkex.Boolean,
dest="random_hue", default=False,
help="Randomize hue")
self.arg_parser.add_argument("--random_s",
type=inkex.Boolean,
dest="random_saturation", default=False,
help="Randomize saturation")
self.arg_parser.add_argument("--random_l",
type=inkex.Boolean,
dest="random_lightness", default=False,
help="Randomize lightness")
self.arg_parser.add_argument("--tab",
help="The selected UI-tab when OK was pressed")
class HslAdjust(coloreffect.ColorEffect):
def add_arguments(self, pars):
pars.add_argument("--tab")
pars.add_argument("-x", "--hue", type=int, default=0, help="Adjust hue")
pars.add_argument("-s", "--saturation", type=int, default=0, help="Adjust saturation")
pars.add_argument("-l", "--lightness", type=int, default=0, help="Adjust lightness")
pars.add_argument("--random_h", type=inkex.Boolean, dest="random_hue")
pars.add_argument("--random_s", type=inkex.Boolean, dest="random_saturation")
pars.add_argument("--random_l", type=inkex.Boolean, dest="random_lightness")
def clamp(self, minimum, x, maximum):
return max(minimum, min(x, maximum))
......@@ -65,4 +48,4 @@ class C(coloreffect.ColorEffect):
if __name__ == '__main__':
C().run()
HslAdjust().run()
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Black and White</name>
<id>org.inkscape.color.blackandwhite</id>
<id>org.inkscape.color.black_and_white</id>
<dependency type="file" location="inx">coloreffect.py</dependency>
<param name="threshold" type="int" min="1" max="255" gui-text="Threshold Color (1-255):">127</param>
<effect>
......
......@@ -4,28 +4,19 @@ from __future__ import absolute_import, division
import coloreffect
class C(coloreffect.ColorEffect):
def __init__(self):
super(C, self).__init__()
self.arg_parser.add_argument("-t", "--threshold",
type=int, default=127,
help="Threshold Color Level")
class BlackAndWhite(coloreffect.ColorEffect):
"""Convert colours to black and white"""
def add_arguments(self, pars):
pars.add_argument("-t", "--threshold", type=int, default=127, help="Threshold Color Level")
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
if l > self.options.threshold:
ig = 255
else:
ig = 0
return '{:02x}{:02x}{:02x}'.format(ig, ig, ig)
lum = 0.299 * r + 0.587 * g + 0.114 * b
grey = 255 if lum > self.options.threshold else 0
return '{:02x}{:02x}{:02x}'.format(grey, grey, grey)
if __name__ == '__main__':
C().run()
BlackAndWhite().run()
......@@ -4,8 +4,8 @@ from __future__ import absolute_import, division
import coloreffect
class C(coloreffect.ColorEffect):
class Brighter(coloreffect.ColorEffect):
"""Make colours brighter"""
def colmod(self, r, g, b):
factor = 0.9
......@@ -27,6 +27,5 @@ class C(coloreffect.ColorEffect):
return '{:02x}{:02x}{:02x}'.format(r, g, b)
if __name__ == '__main__':
C().run()
Brighter().run()
......@@ -42,23 +42,14 @@ def eval_(node, namespace):
raise TypeError(node)
class C(coloreffect.ColorEffect):
def __init__(self):
super(C, self).__init__()
self.arg_parser.add_argument("-r", "--r",
dest="rFunction", default="r",
help="red channel function")
self.arg_parser.add_argument("-g", "--g",
dest="gFunction", default="g",
help="green channel function")
self.arg_parser.add_argument("-b", "--b",
dest="bFunction", default="b",
help="blue channel function")
self.arg_parser.add_argument("-t", "--tab",
help="The selected UI-tab when OK was pressed")
self.arg_parser.add_argument("-s", "--scale",
type=float, default=1,
help="The input (r,g,b) range")
class Custom(coloreffect.ColorEffect):
"""Custom colour functions per channel"""
def add_arguments(self, pars):
pars.add_argument("--tab")
pars.add_argument("-r", "--r", dest="rFunction", default="r", help="red channel function")
pars.add_argument("-g", "--g", dest="gFunction", default="g", help="green channel function")
pars.add_argument("-b", "--b", dest="bFunction", default="b", help="blue channel function")
pars.add_argument("-s", "--scale", type=float, default=1, help="The input (r,g,b) range")
def normalize(self, v):
if v < 0:
......@@ -84,6 +75,5 @@ class C(coloreffect.ColorEffect):
b2 = self.normalize(eval_expr(self.options.bFunction.strip(), safe_namespace))
return self._hexstr(r2 * factor, g2 * factor, b2 * factor)
if __name__ == '__main__':
C().run()
Custom().run()
......@@ -4,8 +4,8 @@ from __future__ import absolute_import, division
import coloreffect
class C(coloreffect.ColorEffect):
class Darker(coloreffect.ColorEffect):
"""Make the colours darker"""
def colmod(self, r, g, b):
factor = 0.9
r = int(round(max(r * factor, 0)))
......@@ -13,6 +13,5 @@ class C(coloreffect.ColorEffect):
b = int(round(max(b * factor, 0)))
return '{:02x}{:02x}{:02x}'.format(r, g, b)
if __name__ == '__main__':
C().run()
Darker().run()
......@@ -4,13 +4,13 @@ from __future__ import absolute_import, division
import coloreffect
class C(coloreffect.ColorEffect):
class Desaturate(coloreffect.ColorEffect):
"""Remove colour but maintain intesity"""
def colmod(self, r, g, b):
l = (max(r, g, b) + min(r, g, b)) // 2
ig = int(round(l))
return '{:02x}{:02x}{:02x}'.format(ig, ig, ig)
lum = (max(r, g, b) + min(r, g, b)) // 2
grey = int(round(lum))
return '{:02x}{:02x}{:02x}'.format(grey, grey, grey)
if __name__ == '__main__':
C().run()
Desaturate().run()
......@@ -4,18 +4,16 @@ from __future__ import absolute_import, division
import coloreffect
class C(coloreffect.ColorEffect):
class Grayscale(coloreffect.ColorEffect):
"""Make all colours grayscale"""
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))
return '{:02x}{:02x}{:02x}'.format(ig, ig, ig)
lum = 0.299 * r + 0.587 * g + 0.114 * b
gray = int(round(lum))
return '{:02x}{:02x}{:02x}'.format(gray, gray, gray)
if __name__ == '__main__':
C().run()
Grayscale().run()
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Less Hue</name>
<id>org.inkscape.color.lesshue</id>
<id>org.inkscape.color.less_hue</id>
<dependency type="file" location="inx">coloreffect.py</dependency>
<effect>
<object-type>all</object-type>
......
......@@ -5,7 +5,8 @@ from __future__ import absolute_import, division
import coloreffect
from inkex import colors
class C(coloreffect.ColorEffect):
class LessHue(coloreffect.ColorEffect):
"""Remove Hue from the color"""
def colmod(self, r, g, b):
hsl = colors.rgb_to_hsl(r / 255, g / 255, b / 255)
hsl[0] -= 0.05
......@@ -16,4 +17,4 @@ class C(coloreffect.ColorEffect):
if __name__ == '__main__':
C().run()
LessHue().run()
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Less Light</name>
<id>org.inkscape.color.lesslight</id>
<id>org.inkscape.color.less_light</id>
<dependency type="file" location="inx">coloreffect.py</dependency>
<effect>
<object-type>all</object-type>
......
......@@ -5,7 +5,8 @@ from __future__ import absolute_import, division
import coloreffect
from inkex import colors
class C(coloreffect.ColorEffect):
class LessLight(coloreffect.ColorEffect):
"""Reduce the light of the color"""
def colmod(self, r, g, b):
hsl = colors.rgb_to_hsl(r / 255, g / 255, b / 255)
hsl[2] -= 0.05
......@@ -16,4 +17,4 @@ class C(coloreffect.ColorEffect):
if __name__ == '__main__':
C().run()
LessLight().run()
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Less Saturation</name>
<id>org.inkscape.color.lesssaturation</id>
<id>org.inkscape.color.less_saturation</id>
<dependency type="file" location="inx">coloreffect.py</dependency>
<effect>
<object-type>all</object-type>
......
#!/usr/bin/env python
# coding=utf-8
"""Remove saturation from colors"""
from __future__ import absolute_import, division
import coloreffect
from inkex import colors
class C(coloreffect.ColorEffect):
class LessSaturation(coloreffect.ColorEffect):
"""Make colours less saturated"""
def colmod(self, r, g, b):
hsl = colors.rgb_to_hsl(r / 255, g / 255, b / 255)
hsl[1] -= 0.05
......@@ -17,4 +19,4 @@ class C(coloreffect.ColorEffect):
if __name__ == '__main__':
C().run()
LessSaturation().run()
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>More Hue</name>
<id>org.inkscape.color.morehue</id>
<id>org.inkscape.color.more_hue</id>
<dependency type="file" location="inx">coloreffect.py</dependency>
<effect>
<object-type>all</object-type>
......
......@@ -5,7 +5,7 @@ from __future__ import absolute_import, division
import coloreffect
from inkex import colors
class C(coloreffect.ColorEffect):
class MoreHue(coloreffect.ColorEffect):
def colmod(self, r, g, b):
hsl = colors.rgb_to_hsl(r / 255, g / 255, b / 255)
hsl[0] += 0.05
......@@ -14,8 +14,5 @@ class C(coloreffect.ColorEffect):
rgb = colors.hsl_to_rgb(hsl[0], hsl[1], hsl[2])
return '{:02x}{:02x}{:02x}'.format(int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))
if __name__ == '__main__':
C().run()
MoreHue().run()
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>More Light</name>
<id>org.inkscape.color.morelight</id>
<id>org.inkscape.color.more_light</id>
<dependency type="file" location="inx">coloreffect.py</dependency>
<effect>
<object-type>all</object-type>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment