64
73
; do nothing if the layer is a layer mask
65
74
(if (= (car (gimp-drawable-is-layer-mask inLayer)) 0)
68
(gimp-image-undo-group-start inImage)
70
; if the layer has no alpha add alpha channel
71
(if (= (car (gimp-drawable-has-alpha inLayer)) FALSE)
73
(gimp-layer-add-alpha inLayer)))
77
(gimp-image-undo-group-start inImage)
79
; if the layer has no alpha add alpha channel
80
(if (= (car (gimp-drawable-has-alpha inLayer)) FALSE)
81
(gimp-layer-add-alpha inLayer)
75
84
; if the layer is the floating selection convert to normal layer
76
85
; because floating selection cant have a layer mask
77
(if (> (car (gimp-layer-is-floating-sel inLayer)) 0)
79
(gimp-floating-sel-to-layer inLayer)))
86
(if (> (car (gimp-layer-is-floating-sel inLayer)) 0)
87
(gimp-floating-sel-to-layer inLayer)
81
90
; if there is no selection we use the layers alpha channel
82
(if (= (car (gimp-selection-is-empty inImage)) TRUE)
84
(set! l-has-selection FALSE)
85
(gimp-selection-layer-alpha inLayer)))
87
(gimp-selection-sharpen inImage)
89
; apply the existing mask before creating a new one
90
(gimp-layer-remove-mask inLayer 0)
92
(if (= inClearUnselected TRUE)
94
(set! l-mask (car (gimp-layer-create-mask inLayer ADD-BLACK-MASK))))
96
(set! l-mask (car (gimp-layer-create-mask inLayer ADD-WHITE-MASK)))))
98
(gimp-layer-add-mask inLayer l-mask)
100
(if (= inGrowingSelection TRUE)
102
(set! l-gray l-from-gray)
103
(set! l-from-gray l-to-gray)
104
(set! l-to-gray l-gray)
105
(set! l-step (/ (- l-from-gray l-to-gray) (+ inBorderSize 1)))
106
(set! l-orig-selection (car (gimp-selection-save inImage)))
107
(gimp-selection-invert inImage)))
109
(while (<= l-idx inBorderSize)
110
(if (= l-idx inBorderSize)
112
(set! l-gray l-from-gray)))
114
(gimp-context-set-background (list (/ l-gray 100) (/ l-gray 100) (/ l-gray 100)))
115
(gimp-edit-fill l-mask BACKGROUND-FILL)
116
(set! l-idx (+ l-idx 1))
117
(set! l-gray (+ l-gray l-step))
118
(gimp-selection-shrink inImage 1)
119
; check if selection has shrinked to none
120
(if (= (car (gimp-selection-is-empty inImage)) TRUE)
122
(set! l-idx (+ inBorderSize 100)) ; break the while loop
125
(if (= inGrowingSelection TRUE)
127
(gimp-selection-load l-orig-selection)
128
(gimp-context-set-background (list (/ l-to-gray 100) (/ l-to-gray 100) (/ l-to-gray 100)))
129
(gimp-edit-fill l-mask BACKGROUND-FILL)
130
(gimp-selection-grow inImage inBorderSize)
131
(gimp-selection-invert inImage)
132
(if (= inClearUnselected TRUE)
134
;(gimp-context-set-background (list (/ l-from-gray 100) (/ l-from-gray 100) (/ l-from-gray 100)))
135
(gimp-context-set-background (list 0 0 0)))
138
(gimp-context-set-background (list 255 255 255))))
140
(gimp-edit-fill l-mask BACKGROUND-FILL)
141
(gimp-image-remove-channel inImage l-orig-selection)))
143
(if (= inApplyMask TRUE)
145
(gimp-layer-remove-mask inLayer 0)))
147
(if (= l-has-selection FALSE)
148
(gimp-selection-none inImage))
150
(gimp-image-undo-group-end inImage)
151
(gimp-displays-flush)))
156
(script-fu-register "script-fu-fade-outline"
158
"Blend the Layers outline border from one alpha value (opaque) to another (transparent) by generating a Layermask"
159
"Wolfgang Hofer <hof@hotbot.com>"
163
SF-IMAGE "The image" 0
164
SF-DRAWABLE "The layer" 0
165
SF-ADJUSTMENT _"Border size" '(10 1 300 1 10 0 1)
166
SF-ADJUSTMENT _"Fade from %" '(100 0 100 1 10 0 0)
167
SF-ADJUSTMENT _"Fade to %" '(0 0 100 1 10 0 0)
168
SF-TOGGLE _"Use growing selection" FALSE
169
SF-TOGGLE _"Apply generated layermask" FALSE
170
SF-TOGGLE _"Clear unselected maskarea" TRUE)
91
(if (= (car (gimp-selection-is-empty inImage)) TRUE)
93
(set! l-has-selection FALSE)
94
(gimp-selection-layer-alpha inLayer)
99
(gimp-selection-sharpen inImage)
101
; apply the existing mask before creating a new one
102
(gimp-layer-remove-mask inLayer 0)
104
(if (= inClearUnselected TRUE)
105
(set! l-mask (car (gimp-layer-create-mask inLayer ADD-BLACK-MASK)))
106
(set! l-mask (car (gimp-layer-create-mask inLayer ADD-WHITE-MASK)))
109
(gimp-layer-add-mask inLayer l-mask)
111
(if (= inGrowingSelection TRUE)
113
(set! l-gray l-from-gray)
114
(set! l-from-gray l-to-gray)
115
(set! l-to-gray l-gray)
116
(set! l-step (/ (- l-from-gray l-to-gray) (+ inBorderSize 1)))
117
(set! l-orig-selection (car (gimp-selection-save inImage)))
118
(gimp-selection-invert inImage)
122
(while (<= l-idx inBorderSize)
123
(if (= l-idx inBorderSize)
124
(set! l-gray l-from-gray)
126
(gimp-context-set-background (list (/ l-gray 100) (/ l-gray 100) (/ l-gray 100)))
127
(gimp-edit-fill l-mask BACKGROUND-FILL)
128
(set! l-idx (+ l-idx 1))
129
(set! l-gray (+ l-gray l-step))
130
(gimp-selection-shrink inImage 1)
131
; check if selection has shrinked to none
132
(if (= (car (gimp-selection-is-empty inImage)) TRUE)
133
(set! l-idx (+ inBorderSize 100)) ; break the while loop
137
(if (= inGrowingSelection TRUE)
139
(gimp-selection-load l-orig-selection)
140
(gimp-context-set-background (list (/ l-to-gray 100) (/ l-to-gray 100) (/ l-to-gray 100)))
141
(gimp-edit-fill l-mask BACKGROUND-FILL)
142
(gimp-selection-grow inImage inBorderSize)
143
(gimp-selection-invert inImage)
144
(if (= inClearUnselected TRUE)
146
;(gimp-context-set-background (list (/ l-from-gray 100) (/ l-from-gray 100) (/ l-from-gray 100)))
147
(gimp-context-set-background (list 0 0 0))
149
(gimp-context-set-background (list 255 255 255))
151
(gimp-edit-fill l-mask BACKGROUND-FILL)
152
(gimp-image-remove-channel inImage l-orig-selection)
156
(if (= inApplyMask TRUE)
157
(gimp-layer-remove-mask inLayer 0)
160
(if (= l-has-selection FALSE)
161
(gimp-selection-none inImage)
164
(gimp-image-undo-group-end inImage)
165
(gimp-displays-flush)
175
"script-fu-fade-outline"
176
_"_Fade to Layer Mask..."
177
_"Create a layermask that fades the edges of the selected region (or alpha)"
178
"Wolfgang Hofer <hof@hotbot.com>"
182
SF-IMAGE "The image" 0
183
SF-DRAWABLE "The layer" 0
184
SF-ADJUSTMENT _"Border size" '(10 1 300 1 10 0 1)
185
SF-ADJUSTMENT _"Fade from %" '(100 0 100 1 10 0 0)
186
SF-ADJUSTMENT _"Fade to %" '(0 0 100 1 10 0 0)
187
SF-TOGGLE _"Use growing selection" FALSE
188
SF-TOGGLE _"Apply generated layermask" FALSE
189
SF-TOGGLE _"Clear unselected maskarea" TRUE
172
192
(script-fu-menu-register "script-fu-fade-outline"
173
_"<Image>/Script-Fu/Selection")
193
"<Image>/Filters/Selection")