-
Notifications
You must be signed in to change notification settings - Fork 5
/
sg-luminosity-masks.scm
136 lines (122 loc) · 5.38 KB
/
sg-luminosity-masks.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
; Create Luminosity Masks for an image
; Originally authored by Patrick David <patdavid@gmail.com>
; re-coded by Saul Goode to honor selection and layer offsets
; Will isolate light, mid, and dark tones in an image as channel masks
; Adapted from tutorial by Tony Kuyper (originally for PS)
; http://goodlight.us/writing/luminositymasks/luminositymasks-1.html
; 2016-02-22 - Pat David
; Adapted for GIMP 2.9.x by updating some deprecated pdb calls to
; their new versions.
; 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 2 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.
(define (script-fu-sg-luminosity-masks image drawable)
(gimp-image-undo-group-start image)
(let ((orig-sel (car (gimp-selection-save image)))
(L (car (gimp-selection-save image)))
(LL #f)
(LLL #f)
(D #f)
(DD #f)
(DDD #f)
(M #f)
(MM #f)
(MMM #f)
(masks '())
(name (car (gimp-item-get-name drawable))) )
(set! masks (cons L masks))
(gimp-item-set-name L (string-append "L-" name))
(gimp-selection-none image)
; paste uses luminosity desaturation method
(let ((buffer (car (gimp-edit-named-copy drawable "temp"))))
(gimp-floating-sel-anchor (car (gimp-edit-named-paste L buffer TRUE)))
(gimp-buffer-delete buffer) )
(set! D (car (gimp-channel-copy L)))
(gimp-image-insert-channel image D 0 1)
(gimp-item-set-name D (string-append "D-" name))
(gimp-invert D)
(set! masks (cons D masks))
(set! DD (car (gimp-channel-copy D)))
(gimp-image-insert-channel image DD 0 2)
(gimp-item-set-name DD (string-append "DD-" name))
(gimp-channel-combine-masks DD L CHANNEL-OP-SUBTRACT 0 0)
(set! masks (cons DD masks))
(set! DDD (car (gimp-channel-copy DD)))
(gimp-image-insert-channel image DDD 0 3)
(gimp-item-set-name DDD (string-append "DDD-" name))
(gimp-channel-combine-masks DDD L CHANNEL-OP-SUBTRACT 0 0)
(set! masks (cons DDD masks))
(set! LL (car (gimp-channel-copy L)))
(gimp-image-insert-channel image LL 0 1)
(gimp-item-set-name LL (string-append "LL-" name))
(gimp-channel-combine-masks LL D CHANNEL-OP-SUBTRACT 0 0)
(set! masks (cons LL masks))
(set! LLL (car (gimp-channel-copy LL)))
(gimp-image-insert-channel image LLL 0 2)
(gimp-item-set-name LLL (string-append "LLL-" name))
(gimp-channel-combine-masks LLL D CHANNEL-OP-SUBTRACT 0 0)
(set! masks (cons LLL masks))
(set! M (car (gimp-channel-copy L)))
(gimp-image-insert-channel image M 0 3)
(gimp-item-set-name M (string-append "M-" name))
(gimp-channel-combine-masks M D CHANNEL-OP-INTERSECT 0 0)
(set! masks (cons M masks))
(set! MM (car (gimp-channel-copy LL)))
(gimp-image-insert-channel image MM 0 3)
(gimp-item-set-name MM (string-append "MM-" name))
(gimp-invert MM)
(gimp-channel-combine-masks MM DD CHANNEL-OP-SUBTRACT 0 0)
(set! masks (cons MM masks))
(set! MMM (car (gimp-channel-copy LLL)))
(gimp-image-insert-channel image MMM 0 3)
(gimp-invert MMM)
(gimp-item-set-name MMM (string-append "MMM-" name))
(gimp-channel-combine-masks MMM DDD CHANNEL-OP-SUBTRACT 0 0)
(set! masks (cons MMM masks))
;(gimp-selection-load orig-sel)
(gimp-image-select-item image CHANNEL-OP-REPLACE orig-sel)
(if (or (= (car (gimp-selection-is-empty image)) TRUE)
(= (car (gimp-drawable-mask-intersect drawable)) FALSE) )
(gimp-selection-all image) )
;(gimp-rect-select image
; (car (gimp-drawable-offsets drawable))
; (cadr (gimp-drawable-offsets drawable))
; (car (gimp-drawable-width drawable))
; (car (gimp-drawable-height drawable))
; CHANNEL-OP-INTERSECT 0 0 )
(gimp-image-select-rectangle image
CHANNEL-OP-INTERSECT
(car (gimp-drawable-offsets drawable))
(cadr (gimp-drawable-offsets drawable))
(car (gimp-drawable-width drawable))
(car (gimp-drawable-height drawable)) )
(gimp-selection-invert image)
(unless (= (car (gimp-selection-is-empty image)) TRUE)
(map (lambda (x) (gimp-edit-fill x WHITE-FILL)
(gimp-invert x) )
masks ))
;(gimp-selection-load orig-sel)
(gimp-image-select-item image CHANNEL-OP-REPLACE orig-sel)
(gimp-image-remove-channel image orig-sel)
)
(gimp-image-set-active-layer image drawable)
(gimp-image-undo-group-end image)
(gimp-displays-flush)
)
(script-fu-register "script-fu-sg-luminosity-masks"
"Luminosity Masks (saulgoode)"
"Create Luminosity Masks of Layer"
"saul goode"
"saul goode"
"Nov 2013"
"RGB*, GRAY*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
)
(script-fu-menu-register "script-fu-sg-luminosity-masks" "<Image>/Filters/Generic")