1from lazpaint import command, dialog
2
3if __name__ == "__main__":
4  dialog.show_message("Library to execute filters on the current layer.")
5
6#filters
7BLUR_PRECISE = 'BlurPrecise'
8BLUR_RADIAL = 'BlurRadial'
9BLUR_FAST = 'BlurFast'
10BLUR_BOX = 'BlurBox'
11BLUR_CORONA = 'BlurCorona'
12BLUR_DISK = 'BlurDisk'
13BLUR_MOTION = 'BlurMotion'
14BLUR_CUSTOM = 'BlurCustom'
15PIXELATE = 'Pixelate'
16
17SHARPEN = 'Sharpen'
18SMOOTH = 'Smooth'
19MEDIAN = 'Median'
20NOISE = 'Noise'
21CLEAR_TYPE = 'ClearType'
22CLEAR_TYPE_INVERSE = 'ClearTypeInverse'
23FILTER_FUNCTION = 'Function'
24CONTOUR = 'Contour'
25EMBOSS = 'Emboss'
26PHONG = 'Phong'
27
28SPHERE = 'Sphere'
29TWIRL = 'Twirl'
30WAVE_DISPLACEMENT = 'WaveDisplacement'
31CYLINDER = 'Cylinder'
32PLANE = 'Plane'
33
34PIXELATE_QUALITY_FAST = 'Fast'
35PIXELATE_QUALITY_LINEAR = 'Linear'
36PIXELATE_QUALITY_MITCHELL = 'Mitchell'
37PIXELATE_QUALITY_SPLINE = 'Spline'
38PIXELATE_QUALITY_BEST = PIXELATE_QUALITY_MITCHELL
39
40PHONG_COLOR_LAYER = 'Layer'
41PHONG_COLOR_PEN = 'Pen'
42PHONG_COLOR_BACK = 'Back'
43
44PHONG_ALTITUDE_LIGHTNESS = 'Lightness'
45PHONG_ALTITUDE_LINEAR_LIGHTNESS = 'LinearLightness'
46PHONG_ALTITUDE_SATURATION = 'Saturation'
47PHONG_ALTITUDE_ALPHA_CHANNEL = 'Alpha'
48PHONG_ALTITUDE_RED_CHANNEL = 'Red'
49PHONG_ALTITUDE_GREEN_CHANNEL = 'Green'
50PHONG_ALTITUDE_BLUE_CHANNEL = 'Blue'
51
52#colors
53COLOR_COMPLEMENTARY = 'ComplementaryColor'
54COLOR_NEGATIVE = 'Negative'
55COLOR_LINEAR_NEGATIVE = 'LinearNegative'
56COLOR_NORMALIZE = 'Normalize'
57COLOR_GRAYSCALE = 'Grayscale'
58
59#render
60RENDER_PERLIN_NOISE = 'PerlinNoise'
61RENDER_CYCLIC_PERLIN_NOISE = 'CyclicPerlinNoise'
62RENDER_CLOUDS = 'Clouds'
63RENDER_CUSTOM_WATER = 'CustomWater'
64RENDER_WATER = 'Water'
65RENDER_RAIN = 'Rain'
66RENDER_WOOD = 'Wood'
67RENDER_WOOD_VERTICAL = 'WoodVertical'
68RENDER_PLASTIK = 'Plastik'
69RENDER_METAL_FLOOR = 'MetalFloor'
70RENDER_CAMOUFLAGE = 'Camouflage'
71RENDER_SNOW_PRINT = 'SnowPrint'
72RENDER_STONE = 'Stone'
73RENDER_ROUND_STONE = 'RoundStone'
74RENDER_MARBLE = 'Marble'
75
76def run(name, validate=True):
77  if name[0:5] == "Color":
78    command.send(name, Validate=validate)
79  else:
80    command.send("Filter", Name=name, Validate=validate)
81
82def blur(name=BLUR_FAST, radius=None, validate=True): #radius: float or (x,y)
83  if isinstance(radius, tuple):
84    radius_x = radius[0]
85    radius_y = radius[1]
86    radius = None
87  else:
88    radius_x = None
89    radius_y = None
90  command.send("Filter", Name=name, Radius=radius, RadiusX=radius_x, RadiusY=radius_y, Validate=validate)
91
92def blur_motion(distance=None, angle=None, oriented=None, validate=True): #oriented: bool
93  command.send("Filter", Name=BLUR_MOTION, Distance=distance, Angle=angle, Oriented=oriented, Validate=validate)
94
95def sharpen(amount=None, validate=True): #amout: 0..10
96  command.send("Filter", Name=SHARPEN, Amount=amount, Validate=validate)
97
98def noise(grayscale=None, opacity=None, validate=True): #grayscale: bool, opacity: 0..255
99  command.send("Filter", Name=NOISE, Grayscale=grayscale, Opacity=opacity, Validate=validate)
100
101def pixelate(pixel_size=None, quality=None, validate=True):
102  command.send("Filter", Name=PIXELATE, PixelSize=pixel_size, Quality=quality, Validate=validate)
103
104def filter_function(red=None, green=None, blue=None, alpha=None, hue=None, saturation=None, lightness=None, L=None, a=None, b=None, corrected_hue=None, gamma_correction=None, validate=True): #expressions: str
105  command.send("Filter", Name=FILTER_FUNCTION, Red=red, Green=green, Blue=blue, Alpha=alpha, Hue=hue, Saturation=saturation, Lightness=lightness, CorrectedHue=corrected_hue, GammaCorrection=gamma_correction, Validate=validate)
106
107def emboss(angle=None, transparent=None, preserve_colors=None, validate=True):
108  command.send("Filter", Name=EMBOSS, Angle=angle, Transparent=transparent, PreserveColors=preserve_colors, Validate=validate)
109
110def rain(amount=None, wind=None, validate=True): #amount and wind: 0..2
111  command.send("Filter", Name=RENDER_RAIN, Amount=amount, Wind=wind, Validate=validate)
112
113def phong(color_source=None, altitude_percent=None, altitude_source=None, light_pos_percent=None, light_x_percent=None, light_y_percent=None, validate=True):
114  command.send("Filter", Name=PHONG, ColorSource=color_source, AltitudePercent=altitude_percent, AltitudeSource=altitude_source, LightPosPercent=light_pos_percent, LightXPercent=light_x_percent, LightYPercent=light_y_percent, Validate=validate)
115
116def twirl(radius=None, angle=None, center_pos_percent=None, center_x_percent=None, center_y_percent=None, validate=True):
117  command.send("Filter", Name=TWIRL, Radius=radius, Angle=angle, CenterPosPercent=center_pos_percent, CenterXPercent=center_x_percent, CenterYPercent=center_y_percent, Validate=validate)
118
119def wave_displacement(wave_length=None, displacement=None, phase=None, center_pos_percent=None, center_x_percent=None, center_y_percent=None, validate=True): #phase: 0..360
120  command.send("Filter", Name=WAVE_DISPLACEMENT, WaveLength=wave_length, Displacement=displacement, Phase=phase, CenterPosPercent=center_pos_percent, CenterXPercent=center_x_percent, CenterYPercent=center_y_percent, Validate=validate)
121