channels_split_hsl.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Channels > Split HSL
  2. from lazpaint import image, dialog, layer, filters
  3. # check if it is a channel
  4. if layer.get_registry("split-channel") is not None:
  5. dialog.show_message("Layer already split")
  6. exit()
  7. layer_id = layer.get_id()
  8. layer_index = image.get_layer_index()
  9. layer_opacity = layer.get_opacity()
  10. layer_transparent = layer.is_transparent()
  11. # check if it has been split
  12. if layer.get_registry("split-channels-id") is not None:
  13. for cur_layer_id in image.iterate_layers():
  14. if layer.get_registry("split-source-id") == layer_id:
  15. dialog.show_message("Layer already split")
  16. exit()
  17. image.do_begin()
  18. channels = []
  19. if layer_transparent:
  20. channels.append({"name": "Alpha", "channel": "A", "hue": "0", "saturation": "0", "lightness": "alpha", "alpha": "255", "blend": layer.BLEND_MASK})
  21. channels.append({"name": "Saturation", "channel": "S", "hue": "0", "saturation": "0", "lightness": "saturation", "alpha": "255", "blend": layer.BLEND_LINEAR_MULTIPLY_SATURATION})
  22. channels.append({"name": "Lightness", "channel": "L", "hue": "0", "saturation": "0", "lightness": "lightness", "alpha": "255", "blend": layer.BLEND_HARD_LIGHT})
  23. channels.append({"name": "Hue", "channel": "H", "hue": "hue", "saturation": "1", "lightness": "0.5", "alpha": "255", "blend": layer.BLEND_DRAW})
  24. channels_id = []
  25. for ch in channels:
  26. layer.select_id(layer_id)
  27. layer.duplicate()
  28. filters.filter_function(hue = ch["hue"], saturation = ch["saturation"], lightness = ch["lightness"], alpha = ch["alpha"], gamma_correction = False)
  29. layer.set_name(ch["name"] + " channel")
  30. layer.set_opacity(layer_opacity)
  31. if ch["channel"] != channels[-1]:
  32. layer.set_blend_op(ch["blend"])
  33. layer.set_registry("split-channel", ch["channel"])
  34. layer.set_registry("split-source-id", layer_id)
  35. channels_id.append(layer.get_id())
  36. layer.select_id(layer_id)
  37. layer.set_registry("split-channels-id", channels_id)
  38. layer.set_visible(False)
  39. image.do_end()