~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/scripts/fade-outline.scm

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
; or from the layers alpha channel if no selection is active.
15
15
;
16
16
; Optional you may keep the generated layermask or apply
17
 
; it to the layer 
 
17
; it to the layer
18
18
 
19
19
;
20
 
; The GIMP -- an image manipulation program
 
20
; GIMP - The GNU Image Manipulation Program
21
21
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
22
 
 
22
;
23
23
; This program is free software; you can redistribute it and/or modify
24
24
; it under the terms of the GNU General Public License as published by
25
25
; the Free Software Foundation; either version 2 of the License, or
26
26
; (at your option) any later version.
27
 
 
27
;
28
28
; This program is distributed in the hope that it will be useful,
29
29
; but WITHOUT ANY WARRANTY; without even the implied warranty of
30
30
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
31
; GNU General Public License for more details.
32
 
 
32
;
33
33
; You should have received a copy of the GNU General Public License
34
34
; along with this program; if not, write to the Free Software
35
35
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37
37
 
38
38
; Define the main function:
39
39
 
40
 
(define (script-fu-fade-outline   inImage
41
 
                                  inLayer
42
 
                                  inBorderSize
43
 
                                  inFadeFrom
44
 
                                  inFadeTo
45
 
                                  inGrowingSelection
46
 
                                  inApplyMask
47
 
                                  inClearUnselected)
48
 
  (let* ((l-idx 0)
49
 
         (l-has-selection TRUE))
 
40
(define (script-fu-fade-outline inImage
 
41
                                inLayer
 
42
                                inBorderSize
 
43
                                inFadeFrom
 
44
                                inFadeTo
 
45
                                inGrowingSelection
 
46
                                inApplyMask
 
47
                                inClearUnselected)
 
48
 
 
49
  (let* (
 
50
        (l-idx 0)
 
51
        (l-has-selection TRUE)
 
52
        (l-from-gray)
 
53
        (l-to-gray)
 
54
        (l-step)
 
55
        (l-gray)
 
56
        (l-mask)
 
57
        (l-orig-selection)
 
58
        )
50
59
 
51
60
    (gimp-context-push)
52
61
 
53
62
    ; check Fade from and To Values (and force values from 0% to 100%)
54
 
    (if (> inFadeFrom 100) (begin (set! inFadeFrom 100 )) )
55
 
    (if (< inFadeFrom 0)   (begin (set! inFadeFrom 0 )) )
56
 
    (if (> inFadeTo 100) (begin (set! inFadeTo 100 )) )
57
 
    (if (< inFadeTo 0)   (begin (set! inFadeTo 0 )) )
58
 
    
 
63
    (if (> inFadeFrom 100) (set! inFadeFrom 100) )
 
64
    (if (< inFadeFrom 0)   (set! inFadeFrom 0) )
 
65
    (if (> inFadeTo 100)   (set! inFadeTo 100) )
 
66
    (if (< inFadeTo 0)     (set! inFadeTo 0) )
 
67
 
59
68
    (set! l-from-gray (* inFadeFrom 255))
60
69
    (set! l-to-gray (* inFadeTo 255))
61
70
    (set! l-step (/  (- l-from-gray l-to-gray) (+ inBorderSize 1)))
63
72
 
64
73
    ; do nothing if the layer is a layer mask
65
74
    (if (= (car (gimp-drawable-is-layer-mask inLayer)) 0)
66
 
        (begin
67
 
 
68
 
          (gimp-image-undo-group-start inImage)
69
 
              
70
 
          ; if the layer has no alpha add alpha channel
71
 
          (if (= (car (gimp-drawable-has-alpha inLayer)) FALSE)
72
 
              (begin
73
 
                (gimp-layer-add-alpha inLayer)))
 
75
        (begin
 
76
 
 
77
          (gimp-image-undo-group-start inImage)
 
78
 
 
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)
 
82
          )
74
83
 
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)
78
 
              (begin
79
 
                (gimp-floating-sel-to-layer inLayer)))
 
86
          (if (> (car (gimp-layer-is-floating-sel inLayer)) 0)
 
87
              (gimp-floating-sel-to-layer inLayer)
 
88
          )
80
89
 
81
90
          ; if there is no selection we use the layers alpha channel
82
 
          (if (= (car (gimp-selection-is-empty inImage)) TRUE)
83
 
              (begin
84
 
                (set! l-has-selection FALSE)
85
 
                (gimp-selection-layer-alpha inLayer)))
86
 
 
87
 
          (gimp-selection-sharpen inImage)
88
 
 
89
 
          ; apply the existing mask before creating a new one
90
 
          (gimp-layer-remove-mask inLayer 0)
91
 
 
92
 
          (if (= inClearUnselected  TRUE)
93
 
              (begin
94
 
                (set! l-mask (car (gimp-layer-create-mask inLayer ADD-BLACK-MASK))))
95
 
              (begin
96
 
                (set! l-mask (car (gimp-layer-create-mask inLayer ADD-WHITE-MASK)))))
97
 
 
98
 
          (gimp-layer-add-mask inLayer l-mask)
99
 
 
100
 
          (if (= inGrowingSelection  TRUE)
101
 
              (begin
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)))
108
 
                                           
109
 
          (while (<= l-idx inBorderSize)
110
 
                 (if (= l-idx inBorderSize)
111
 
                     (begin
112
 
                       (set! l-gray l-from-gray)))
113
 
 
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)
121
 
                     (begin
122
 
                       (set! l-idx (+ inBorderSize 100))     ; break the while loop
123
 
                       )))
124
 
              
125
 
          (if (= inGrowingSelection  TRUE)
126
 
              (begin
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)
133
 
                    (begin
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)))
136
 
 
137
 
                    (begin
138
 
                      (gimp-context-set-background (list 255 255 255))))
139
 
 
140
 
                (gimp-edit-fill l-mask BACKGROUND-FILL)
141
 
                (gimp-image-remove-channel inImage l-orig-selection)))
142
 
 
143
 
          (if (=  inApplyMask TRUE)
144
 
              (begin
145
 
                (gimp-layer-remove-mask inLayer 0)))
146
 
 
147
 
          (if (= l-has-selection FALSE)
148
 
              (gimp-selection-none inImage))
149
 
 
150
 
          (gimp-image-undo-group-end inImage)
151
 
          (gimp-displays-flush)))
152
 
 
153
 
    (gimp-context-pop)))
154
 
 
155
 
 
156
 
(script-fu-register "script-fu-fade-outline"
157
 
                    _"_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>"
160
 
                    "Wolfgang Hofer"
161
 
                    "10 Nov 1999"
162
 
                    "RGB* GRAY*"
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)
 
92
              (begin
 
93
                 (set! l-has-selection FALSE)
 
94
                 (gimp-selection-layer-alpha inLayer)
 
95
              )
 
96
          )
 
97
 
 
98
           ;
 
99
          (gimp-selection-sharpen inImage)
 
100
 
 
101
           ; apply the existing mask before creating a new one
 
102
          (gimp-layer-remove-mask inLayer 0)
 
103
 
 
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)))
 
107
          )
 
108
 
 
109
          (gimp-layer-add-mask inLayer l-mask)
 
110
 
 
111
          (if (= inGrowingSelection  TRUE)
 
112
              (begin
 
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)
 
119
              )
 
120
          )
 
121
 
 
122
          (while (<= l-idx inBorderSize)
 
123
             (if (= l-idx inBorderSize)
 
124
                 (set! l-gray l-from-gray)
 
125
             )
 
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
 
134
             )
 
135
          )
 
136
 
 
137
          (if (= inGrowingSelection  TRUE)
 
138
              (begin
 
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)
 
145
                    (begin
 
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))
 
148
                    )
 
149
                    (gimp-context-set-background (list 255 255 255))
 
150
                 )
 
151
                (gimp-edit-fill l-mask BACKGROUND-FILL)
 
152
                (gimp-image-remove-channel inImage l-orig-selection)
 
153
              )
 
154
          )
 
155
 
 
156
          (if (=  inApplyMask TRUE)
 
157
              (gimp-layer-remove-mask inLayer 0)
 
158
          )
 
159
 
 
160
          (if (= l-has-selection FALSE)
 
161
              (gimp-selection-none inImage)
 
162
          )
 
163
 
 
164
          (gimp-image-undo-group-end inImage)
 
165
          (gimp-displays-flush)
 
166
        )
 
167
    )
 
168
 
 
169
    (gimp-context-pop)
 
170
  )
 
171
)
 
172
 
 
173
 
 
174
(script-fu-register
 
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>"
 
179
  "Wolfgang Hofer"
 
180
  "10 Nov 1999"
 
181
  "RGB* GRAY*"
 
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
 
190
)
171
191
 
172
192
(script-fu-menu-register "script-fu-fade-outline"
173
 
                         _"<Image>/Script-Fu/Selection")
 
193
                         "<Image>/Filters/Selection")