RSS/Atom feed Twitter
Site is read-only, email is disabled

using layer/channel as mask

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

4 of 4 messages available
Toggle history

Please log in to manage your subscriptions.

using layer/channel as mask Kevin Galligan 22 Jan 19:34
  using layer/channel as mask David Gowers 25 Jan 02:30
   using layer/channel as mask Kevin Galligan 25 Jan 02:55
    using layer/channel as mask David Gowers 25 Jan 04:49
Kevin Galligan
2007-01-22 19:34:05 UTC (almost 18 years ago)

using layer/channel as mask

I've been trying to script something that seems relatively simple, yet I've spent the better part of today stuck at one little step. I have started naming things with curse words, so I figured I'd reach out for help before I start throwing things.

I have a layer that I want to serve as the mask for another layer. The values in the mask layer are white, so in theory, I could do the following...

;Somehow get the green Channel of the mask layer

(set! greenChannelMask [magicFunctionHere])

(gimp-layer-add-mask myLayer greenChannelMask)

I'm sure there's a more elegant way of doing it. If so, please let me know. However, if the above would work, I just need to know how to get that channel. Should be easy, but I have been beating my head agaist a wall. I just can't get it. I tried 'gimp-image-get-channels' in the console just to see if I could do it the hard way, but it always returns '(0 #()#0"")', no matter what image, which leads me to believe I don't understand how that function works. I also tried 'gimp-image-get-active-channel' in the console, but that comes back with -1. All the time.

I probably wouldn't be so frustrated if this was a big deal, but should be easy to get the channel, yet I've burned much of the day and have made no other progress (other than, of course, having nowhere else to look).

Thanks in advance, -Kevin

David Gowers
2007-01-25 02:30:59 UTC (almost 18 years ago)

using layer/channel as mask

On 1/23/07, Kevin Galligan wrote:

I've been trying to script something that seems relatively simple, yet I've spent the better part of today stuck at one little step. I have started naming things with curse words, so I figured I'd reach out for help before I start throwing things.

Sounds familiar .. although that's happened much less to me since I started using Python-Fu instead of Script-Fu.

I have a layer that I want to serve as the mask for another layer. The

values in the mask layer are white, so in theory, I could do the following...

;Somehow get the green Channel of the mask layer

(set! greenChannelMask [magicFunctionHere])

(gimp-layer-add-mask myLayer greenChannelMask)

I'm sure there's a more elegant way of doing it. If so, please let me know. However, if the above would work, I just need to know how to get that channel. Should be easy, but I have been beating my head agaist a wall. I just can't get it. I tried 'gimp-image-get-channels' in the console just to see if I could do it the hard way, but it always returns '(0 #()#0"")', no matter what image, which leads me to believe I don't understand how that function works. I also tried 'gimp-image-get-active-channel' in

The function returns a list of channels. ie. What you see in the bottom part of the Channels dialog.

Anyway, you don't really need to get the green values, just get the intensity.
The way to do this is:

* Copy the mask layer (as in gimp-edit-copy -- or gimp-edit-named-copy if you want to preserve the clipboard)
* Add a mask to the target layer *if needed* * Paste onto the mask
* Anchor

the console, but that comes back with -1. All the time.

I probably wouldn't be so frustrated if this was a big deal, but should be easy to get the channel, yet I've burned much of the day and have made no other progress (other than, of course, having nowhere else to look).

Thanks in advance, -Kevin

Kevin Galligan
2007-01-25 02:55:31 UTC (almost 18 years ago)

using layer/channel as mask

I settled on that route after some wrestling...

*** CODE HERE *** (set! shadowMask (car(gimp-layer-create-mask shadowLayer ADD-ALPHA-MASK))) (gimp-layer-add-mask shadowLayer shadowMask)

(gimp-selection-all inImage) (gimp-edit-copy inDrawable)
(set! floatingSel (car (gimp-edit-paste shadowMask FALSE))) (gimp-floating-sel-anchor floatingSel)

(gimp-layer-remove-mask shadowLayer MASK-APPLY) *** ***

I hate scheme. I had to do scheme while in school for a class, and I just never, ever liked it. However, I don't think my problem here was with scheme (after, obviously, the initial refresher). It was getting my head around the api. I still don't know how to get a reference to the color channel (green, blue, or red. Didn't matter. Just needed the values).

Do you have a good link to coding python and gimp? I found some stuff, but it seemed old, and I wound up sticking with scheme.

Thanks in advance, -Kevin

On 1/24/07, David Gowers wrote:

On 1/23/07, Kevin Galligan wrote:

I've been trying to script something that seems relatively simple, yet I've spent the better part of today stuck at one little step. I have started naming things with curse words, so I figured I'd reach out for help before I start throwing things.

Sounds familiar .. although that's happened much less to me since I started using Python-Fu instead of Script-Fu.

I have a layer that I want to serve as the mask for another layer. The

values in the mask layer are white, so in theory, I could do the following...

;Somehow get the green Channel of the mask layer

(set! greenChannelMask [magicFunctionHere])

(gimp-layer-add-mask myLayer greenChannelMask)

I'm sure there's a more elegant way of doing it. If so, please let me know. However, if the above would work, I just need to know how to get that channel. Should be easy, but I have been beating my head agaist a wall. I just can't get it. I tried 'gimp-image-get-channels' in the console just to see if I could do it the hard way, but it always returns '(0 #()#0"")', no matter what image, which leads me to believe I don't understand how that function works. I also tried 'gimp-image-get-active-channel' in

The function returns a list of channels. ie. What you see in the bottom part of the Channels dialog.

Anyway, you don't really need to get the green values, just get the intensity.
The way to do this is:

* Copy the mask layer (as in gimp-edit-copy -- or gimp-edit-named-copy if you want to preserve the clipboard)
* Add a mask to the target layer *if needed* * Paste onto the mask
* Anchor

the console, but that comes back with -1. All the time.

I probably wouldn't be so frustrated if this was a big deal, but should be easy to get the channel, yet I've burned much of the day and have made no other progress (other than, of course, having nowhere else to look).

Thanks in advance, -Kevin

David Gowers
2007-01-25 04:49:59 UTC (almost 18 years ago)

using layer/channel as mask

On 1/25/07, Kevin Galligan wrote:

I settled on that route after some wrestling...

*** CODE HERE *** (set! shadowMask (car(gimp-layer-create-mask shadowLayer ADD-ALPHA-MASK))) (gimp-layer-add-mask shadowLayer shadowMask)

(gimp-selection-all inImage) (gimp-edit-copy inDrawable)
(set! floatingSel (car (gimp-edit-paste shadowMask FALSE))) (gimp-floating-sel-anchor floatingSel)

(gimp-layer-remove-mask shadowLayer MASK-APPLY)

Is it your intention to apply the mask incrementally? Every time you apply the mask, that will reduce the alpha of the pixels in shadowlayer. in short, outAlpha = inAlpha * maskValue.

*** ***

I hate scheme. I had to do scheme while in school for a class, and I just never, ever liked it. However, I don't think my problem here was with scheme (after, obviously, the initial refresher). It was getting my head around the api. I still don't know how to get a reference to the color channel (green, blue, or red. Didn't matter. Just needed the values).

You cannot.
If you want to use the 'decompose' plugin to separate the component of an image, or use Python's advanced slicing to extract data for one component from the entire pixel data, you can do that.

Do you have a good link to coding python and gimp? I found some stuff, but

it seemed old, and I wound up sticking with scheme.

On Windows it is slightly more complicated to get Gimp working with Python-Fu. On Linux, it's pretty simple -- just run ./configure with the --enable-python switch (this is enabled by default in recent versions), then rebuild and reinstall. Then you can write plugins and put them in your gimp plugins directory. A simple plugin is attached.