filters.py 4.9 KB

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