It is currently Sun Sep 13, 2026 4:31 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: New Luminosity Masks Scripts
PostPosted: Sun Nov 24, 2019 6:32 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 875
Because the Saul Goode LM script is not working in GIMP 2.10.14, Tim Tran created a new script for me. My idea was that the channels should not overlap so that they could be used separately or in combination.

To show my ingratitude, I then modified it (because I had a clear example of Python that I could understand)!
I added a DDDD and LLLL which affect only the very darkest and lightest parts of an image. I also split the M into a medium dark (MD) and medium light (ML).
It allows one to make extreme adjustments using Colours/Curves or Brightness & Contrast without affecting adjacent areas.
Also, by making "loose" selections, one can adjust the required area without changing other parts which may be included within the selection.

I have attached both versions. Tim's is named david_lum_mask.py and my modification david1_lum_mask.py
(Linux users will have to make them executable.)

I hope others will try both versions and give comments and criticism.

david.


Attachments:
david_lum_mask.zip [1.74 KiB]
Downloaded 409 times
david1_lum_mask.zip [2.14 KiB]
Downloaded 435 times
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: New Luminosity Masks Scripts
PostPosted: Sat Dec 07, 2019 7:56 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 875
Yet another update!
Because luminosity masks can be unusable for low-contrast images (one mask can contain almost all of the picture content), I have modified my previous script.
It now equalizes the layer used to create the masks. The full range of masks are now available for use on low-contrast images.
This avoids the need to produce time-consuming hand drawn masks.

It does not appear to have any negative consequences for photographs of normal contrast.

Linux users will have to make the file executable.

I would appreciate feedback as to its effectiveness.

david.


Attachments:
david2_lum_mask.zip [2.17 KiB]
Downloaded 399 times
Top
 Post subject: Re: New Luminosity Masks Scripts
PostPosted: Thu Dec 12, 2019 12:23 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Oct 10, 2018
Posts: 191
Location: Charlottesville Virginia
David, thanks for your work. I've been trying to make use of layer masks for some time now, following them from the initial essay description to the first scripting of the procedure and the several scripts since then. How to handle especially the middle values has been unsettled from the very beginning. The number of masks created has varied, as well as where to locate the masks in the GIMP work area and how or if to assign modes and visibility. I was glad to have all of the variations because creating such scripts in either scheme or python remains out of my ken.

I can't comment on the technical aspects of the scripts, but, speaking as a user I believe your "ungrateful David" version was the first "complete" version of what was originally attempted. It seemed to work better, was faster, and offered more genuinely usable mask layers than what had come before. (Sometimes script writers left out layers altogether and other times cautioned users that some of them just weren't very useful.) Upon finding your take on the script, I began archiving all the previous versions I had collected and used from time to time.

In my opinion, your update, applying EQ to the initial stages, could point a way for even further creative development. I would be very interested to see where this additional processing approach might lead.

So, just in case you were beginning to wonder ...

Thanks again!


Top
 Post subject: Re: New Luminosity Masks Scripts
PostPosted: Thu Dec 12, 2019 1:27 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jul 06, 2013
Posts: 2662
Location: California
I have version 2 installed. How do I call it up to use the plugin?


Top
 Post subject: Re: New Luminosity Masks Scripts
PostPosted: Thu Dec 12, 2019 2:54 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 875
mackenzieh,

You should find the script under Python-Fu/David2 Luminosity Masks... Click on this and it should create all the layers and masks.

neurolurker,

I am glad you find it useful. I used the Saul Goode script for several years. When it ceased to work under GIMP 2.10 I decided to incorporate ideas I had thought about for a long time. Although it is not ideal I hope it proves useful to you.

david.


Top
 Post subject: Re: New Luminosity Masks Scripts
PostPosted: Thu Dec 12, 2019 6:21 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jul 06, 2013
Posts: 2662
Location: California
David,

Here is what I see when I load up gimp:
Image
Image
ImageImage

I am running gimp 2.10.14 on Windows 10 64bit. I don't see your plugin.

EDIT:
I now have your plugin.
Image


Last edited by mackenzieh on Thu Dec 12, 2019 6:34 pm, edited 1 time in total.

Top
 Post subject: Re: New Luminosity Masks Scripts
PostPosted: Thu Dec 12, 2019 6:33 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 875
mackenzieh,

One of your screen captures is showing it under Python-Fu - David2 Luminosity Masks...
If you click on it, having loaded an image, it should run.

Close to midnight here in the UK. Let me know how you get on and I will look for your reply in the morning.

david.


Top
 Post subject: Re: New Luminosity Masks Scripts
PostPosted: Sat Sep 12, 2026 7:06 pm  (#8) 
Offline
GimpChat Member

Joined: Sep 29, 2016
Posts: 11
Necroposting, but, updated version that works with 3.2.4:

#!/usr/bin/env python3

# david2_lum_mask.py
# following the steps described on this link's pdf by david: https://gimplearn.net/viewtopic.php?p=29419#p29419
# Created by Tin Tran https://gimplearn.net
# Comments directed to https://gimplearn.net
#
# After being created, that ungrateful wretch, david, modified it by adding layers LLLL.
# DDDD and replacing M with a medium dark (MD) and medium light (ML).
#
# License: GPLv3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release.
# Rel 2: DM 23 November 2019.
# Rel 3: updated for GIMP 3.2.4
# -*- coding: utf-8 -*-
import sys
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
from gi.repository import GLib
from gi.repository import GObject
gi.require_version('Gegl', '0.4')
from gi.repository import Gegl

def python_david2_lum_mask(image, layer):
    image.undo_group_start()
    Gimp.context_push()
   
    # Make a copy of the layer to desaturate
    layer_copy = Gimp.Layer.new_from_drawable(layer, image)
    image.insert_layer(layer_copy, None, 0)
    layer_copy.equalize(True)
    # In GIMP 3, desaturate is a method of Gimp.Drawable
    layer_copy.desaturate(Gimp.DesaturateMode.LUMINANCE)

    # Copy Red channel as L1
    channel_L1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "L1")
    image.insert_channel(channel_L1, None, 0)

    # Create D1 from Alpha subtract L1
    channel_D1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "D1")
    image.insert_channel(channel_D1, None, 0)
    channel_D1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DD1 from Alpha - L1 - L1
    channel_DD1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "DD1")
    image.insert_channel(channel_DD1, None, 0)
    channel_DD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DDD1 from Alpha - L1 - L1 - L1
    channel_DDD1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "DDD1")
    image.insert_channel(channel_DDD1, None, 0)
    channel_DDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DDDD1 from Alpha - L1 - L1 - L1 - L1
    channel_DDDD1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "DDDD1")
    image.insert_channel(channel_DDDD1, None, 0)
    channel_DDDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DDDD from Alpha - L1 - L1 - L1 - L1 - L1
    channel_DDDD = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "DDDD")
    image.insert_channel(channel_DDDD, None, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LL1 from RED_CHANNEL - D1
    channel_LL1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "LL1")
    image.insert_channel(channel_LL1, None, 0)
    channel_LL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LLL1 from RED_CHANNEL - D1 - D1
    channel_LLL1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "LLL1")
    image.insert_channel(channel_LLL1, None, 0)
    channel_LLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LLLL1 from RED_CHANNEL - D1 - D1 - D1
    channel_LLLL1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "LLLL1")
    image.insert_channel(channel_LLLL1, None, 0)
    channel_LLLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LLLL from RED_CHANNEL - D1 - D1 - D1 - D1
    channel_LLLL = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "LLLL")
    image.insert_channel(channel_LLLL, None, 0)
    channel_LLLL.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create ML from D1 - DD1 - DD1
    channel_ML = channel_D1.copy()
    image.insert_channel(channel_ML, None, 0)
    channel_ML.set_name("ML")
    channel_ML.combine_masks(channel_DD1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_ML.combine_masks(channel_DD1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create MD from L1 - LL1 - LL1
    channel_MD = channel_L1.copy()
    image.insert_channel(channel_MD, None, 0)
    channel_MD.set_name("MD")
    channel_MD.combine_masks(channel_LL1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_MD.combine_masks(channel_LL1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create D from DD1 - DDD1
    channel_D = channel_DD1.copy()
    image.insert_channel(channel_D, None, 0)
    channel_D.set_name("D")
    channel_D.combine_masks(channel_DDD1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DD from DDD1 - DDDD1
    channel_DD = channel_DDD1.copy()
    image.insert_channel(channel_DD, None, 0)
    channel_DD.set_name("DD")
    channel_DD.combine_masks(channel_DDDD1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DDD from DDDD1 - DDDD
    channel_DDD = channel_DDDD1.copy()
    image.insert_channel(channel_DDD, None, 0)
    channel_DDD.set_name("DDD")
    channel_DDD.combine_masks(channel_DDDD, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create L from LL1 - LLL1
    channel_L = channel_LL1.copy()
    image.insert_channel(channel_L, None, 0)
    channel_L.set_name("L")
    channel_L.combine_masks(channel_LLL1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LL from LLL1 - LLLL1
    channel_LL = channel_LLL1.copy()
    image.insert_channel(channel_LL, None, 0)
    channel_LL.set_name("LL")
    channel_LL.combine_masks(channel_LLLL1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LLL from LLLL1 - LLLL
    channel_LLL = channel_LLLL1.copy()
    image.insert_channel(channel_LLL, None, 0)
    channel_LLL.set_name("LLL")
    channel_LLL.combine_masks(channel_LLLL, Gimp.ChannelOps.SUBTRACT, 0, 0)

    Gimp.Selection.none(image)
    image.remove_layer(layer_copy)

    # Helper to create a layer with a channel mask
    def create_mask_layer(channel, name):
        image.select_item(Gimp.ChannelOps.REPLACE, channel)
        new_layer = Gimp.Layer.new_from_drawable(layer, image)
        image.insert_layer(new_layer, None, 0)
        new_layer.set_name(name)
        mask = new_layer.create_mask(Gimp.AddMaskType.SELECTION)
        new_layer.add_mask(mask)

    # Create layers with masks
    create_mask_layer(channel_DDDD, "DDDD")
    create_mask_layer(channel_DDD, "DDD")
    create_mask_layer(channel_DD, "DD")
    create_mask_layer(channel_D, "D")
    create_mask_layer(channel_MD, "MD")
    create_mask_layer(channel_ML, "ML")
    create_mask_layer(channel_L, "L")
    create_mask_layer(channel_LL, "LL")
    create_mask_layer(channel_LLL, "LLL")
    create_mask_layer(channel_LLLL, "LLLL")

    # Remove all channels
    for ch in [channel_L1, channel_LL1, channel_LLL1, channel_LLLL1,
               channel_L, channel_LL, channel_LLL, channel_LLLL,
               channel_D1, channel_DD1, channel_DDD1, channel_DDDD1,
               channel_D, channel_DD, channel_DDD, channel_DDDD,
               channel_ML, channel_MD]:
        image.remove_channel(ch)

    Gimp.Selection.none(image)
    Gimp.context_pop()
    image.undo_group_end()
    Gimp.displays_flush()

class David2LumMaskPlugin(Gimp.PlugIn):
    def do_query_procedures(self):
        return ["python-fu-david2-lum-mask"]

    def do_create_procedure(self, name):
        procedure = Gimp.ImageProcedure.new(self, name,
                                            Gimp.PDBProcType.PLUGIN,
                                            self.run, None)
        procedure.set_image_types("RGB*, GRAY*")
        procedure.set_menu_label("David2 Luminosity Masks...")
        procedure.add_menu_path("<Image>/Python-Fu/")
        procedure.set_documentation("Create Luminosity Masks",
                                    "Create Luminosity Masks",
                                    "David Marsden")
        procedure.set_attribution("David Marsden", "David Marsden", "December 2019")
        return procedure

    def run(self, procedure, run_mode, image, drawables, config, run_data):
        if len(drawables) != 1:
            return procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR,
                                               GLib.Error("Procedure requires one layer."))
        layer = drawables[0]
        python_david2_lum_mask(image, layer)
        return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())

Gimp.main(David2LumMaskPlugin.__gtype__, sys.argv)

And a version that just makes channels instead of making image layers (my preference):

# david2_lum_mask.py
# following the steps described on this link's pdf by david: https://gimplearn.net/viewtopic.php?p=29419#p29419
# Created by Tin Tran https://gimplearn.net
# Comments directed to https://gimplearn.net
#
# After being created, that ungrateful wretch, david, modified it by adding layers LLLL.
# DDDD and replacing M with a medium dark (MD) and medium light (ML).
#
# License: GPLv3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release.
# Rel 2: DM 23 November 2019.
# Rel 3: updated for GIMP 3.2.4
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
from gi.repository import GLib
from gi.repository import GObject
gi.require_version('Gegl', '0.4')
from gi.repository import Gegl


def python_david2_lum_mask(image, layer):
    image.undo_group_start()
    Gimp.context_push()

    # Make a copy of the layer to desaturate
    layer_copy = Gimp.Layer.new_from_drawable(layer, image)
    image.insert_layer(layer_copy, None, 0)
    layer_copy.equalize(True)
    layer_copy.desaturate(Gimp.DesaturateMode.LUMINANCE)

    # Copy Red channel as L1
    channel_L1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "L1")
    image.insert_channel(channel_L1, None, 0)

    # Create D1 from Alpha subtract L1
    channel_D1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "D1")
    image.insert_channel(channel_D1, None, 0)
    channel_D1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DD1 from Alpha - L1 - L1
    channel_DD1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "DD1")
    image.insert_channel(channel_DD1, None, 0)
    channel_DD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DDD1 from Alpha - L1 - L1 - L1
    channel_DDD1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "DDD1")
    image.insert_channel(channel_DDD1, None, 0)
    channel_DDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DDDD1 from Alpha - L1 - L1 - L1 - L1
    channel_DDDD1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "DDDD1")
    image.insert_channel(channel_DDDD1, None, 0)
    channel_DDDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD1.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DDDD from Alpha - L1 - L1 - L1 - L1 - L1
    channel_DDDD = Gimp.Channel.new_from_component(image, Gimp.ChannelType.ALPHA, "DDDD")
    image.insert_channel(channel_DDDD, None, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_DDDD.combine_masks(channel_L1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LL1 from RED_CHANNEL - D1
    channel_LL1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "LL1")
    image.insert_channel(channel_LL1, None, 0)
    channel_LL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LLL1 from RED_CHANNEL - D1 - D1
    channel_LLL1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "LLL1")
    image.insert_channel(channel_LLL1, None, 0)
    channel_LLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LLLL1 from RED_CHANNEL - D1 - D1 - D1
    channel_LLLL1 = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "LLLL1")
    image.insert_channel(channel_LLLL1, None, 0)
    channel_LLLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL1.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LLLL from RED_CHANNEL - D1 - D1 - D1 - D1
    channel_LLLL = Gimp.Channel.new_from_component(image, Gimp.ChannelType.RED, "LLLL")
    image.insert_channel(channel_LLLL, None, 0)
    channel_LLLL.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_LLLL.combine_masks(channel_D1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create ML from D1 - DD1 - DD1
    channel_ML = channel_D1.copy()
    image.insert_channel(channel_ML, None, 0)
    channel_ML.set_name("ML")
    channel_ML.combine_masks(channel_DD1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_ML.combine_masks(channel_DD1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create MD from L1 - LL1 - LL1
    channel_MD = channel_L1.copy()
    image.insert_channel(channel_MD, None, 0)
    channel_MD.set_name("MD")
    channel_MD.combine_masks(channel_LL1, Gimp.ChannelOps.SUBTRACT, 0, 0)
    channel_MD.combine_masks(channel_LL1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create D from DD1 - DDD1
    channel_D = channel_DD1.copy()
    image.insert_channel(channel_D, None, 0)
    channel_D.set_name("D")
    channel_D.combine_masks(channel_DDD1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DD from DDD1 - DDDD1
    channel_DD = channel_DDD1.copy()
    image.insert_channel(channel_DD, None, 0)
    channel_DD.set_name("DD")
    channel_DD.combine_masks(channel_DDDD1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create DDD from DDDD1 - DDDD
    channel_DDD = channel_DDDD1.copy()
    image.insert_channel(channel_DDD, None, 0)
    channel_DDD.set_name("DDD")
    channel_DDD.combine_masks(channel_DDDD, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create L from LL1 - LLL1
    channel_L = channel_LL1.copy()
    image.insert_channel(channel_L, None, 0)
    channel_L.set_name("L")
    channel_L.combine_masks(channel_LLL1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LL from LLL1 - LLLL1
    channel_LL = channel_LLL1.copy()
    image.insert_channel(channel_LL, None, 0)
    channel_LL.set_name("LL")
    channel_LL.combine_masks(channel_LLLL1, Gimp.ChannelOps.SUBTRACT, 0, 0)

    # Create LLL from LLLL1 - LLLL
    channel_LLL = channel_LLLL1.copy()
    image.insert_channel(channel_LLL, None, 0)
    channel_LLL.set_name("LLL")
    channel_LLL.combine_masks(channel_LLLL, Gimp.ChannelOps.SUBTRACT, 0, 0)

    Gimp.Selection.none(image)
    image.remove_layer(layer_copy)

    # Make the final luminosity-mask channels invisible so they don't
    # overlay a red tint on the canvas (they remain in the Channels dialog)
    final_channels = [
        channel_DDDD, channel_DDD, channel_DD, channel_D,
        channel_MD, channel_ML,
        channel_L, channel_LL, channel_LLL, channel_LLLL,
    ]
    for ch in final_channels:
        ch.set_visible(False)

    # Remove only the intermediate (working) channels; keep the final ones
    for ch in [channel_L1, channel_D1, channel_DD1, channel_DDD1, channel_DDDD1,
               channel_LL1, channel_LLL1, channel_LLLL1]:
        image.remove_channel(ch)

    Gimp.Selection.none(image)
    Gimp.context_pop()
    image.undo_group_end()
    Gimp.displays_flush()


class David2LumMaskPlugin(Gimp.PlugIn):
    def do_query_procedures(self):
        return ["python-fu-david2-lum-mask-channels"]

    def do_create_procedure(self, name):
        procedure = Gimp.ImageProcedure.new(self, name,
                                            Gimp.PDBProcType.PLUGIN,
                                            self.run, None)
        procedure.set_image_types("RGB*, GRAY*")
        procedure.set_menu_label("David2 Luminosity Masks - Channels...")
        procedure.add_menu_path("<Image>/Python-Fu/")
        procedure.set_documentation("Create Luminosity Masks - Channels",
                                    "Create Luminosity Masks - Channels",
                                    "David Marsden")
        procedure.set_attribution("David Marsden", "David Marsden", "December 2019")
        return procedure

    def run(self, procedure, run_mode, image, drawables, config, run_data):
        if len(drawables) != 1:
            return procedure.new_return_values(
                Gimp.PDBStatusType.CALLING_ERROR,
                GLib.Error("Procedure requires one layer."))
        layer = drawables[0]
        python_david2_lum_mask(image, layer)
        return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())


Gimp.main(David2LumMaskPlugin.__gtype__, sys.argv)

These were bot-updated, but I read through and it looks good (and works well, so far at least).


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group