channels_split_hsl.py 2.1 KB

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