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

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/scripts/drop-shadow.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:
1
 
; The GIMP -- an image manipulation program
 
1
; GIMP - The GNU Image Manipulation Program
2
2
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 
3
;
4
4
; This program is free software; you can redistribute it and/or modify
5
5
; it under the terms of the GNU General Public License as published by
6
6
; the Free Software Foundation; either version 2 of the License, or
7
 
; (at your option) any later version.  
8
 
 
7
; (at your option) any later version.
 
8
;
9
9
; This program is distributed in the hope that it will be useful,
10
10
; but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
12
; GNU General Public License for more details.
13
 
 
13
;
14
14
; You should have received a copy of the GNU General Public License
15
15
; along with this program; if not, write to the Free Software
16
16
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
17
;
18
18
;
19
 
; drop-shadow.scm   version 1.04   1999/12/21 
 
19
; drop-shadow.scm   version 1.04   1999/12/21
20
20
;
21
21
; CHANGE-LOG:
22
22
; 1.00 - initial release
26
26
;
27
27
;
28
28
; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org>
29
 
30
 
;  
31
 
; Adds a drop-shadow of the current selection or alpha-channel. 
32
 
;
33
 
; This script is derived from my script add-shadow, which has become 
34
 
; obsolete now. Thanks to Andrew Donkin (ard@cs.waikato.ac.nz) for his 
 
29
;
 
30
;
 
31
; Adds a drop-shadow of the current selection or alpha-channel.
 
32
;
 
33
; This script is derived from my script add-shadow, which has become
 
34
; obsolete now. Thanks to Andrew Donkin (ard@cs.waikato.ac.nz) for his
35
35
; idea to add alpha-support to add-shadow.
36
36
 
37
 
  
 
37
 
38
38
(define (script-fu-drop-shadow image
39
 
                               drawable
40
 
                               shadow-transl-x
41
 
                               shadow-transl-y
42
 
                               shadow-blur
43
 
                               shadow-color
44
 
                               shadow-opacity
45
 
                               allow-resize)
46
 
  (let* ((shadow-blur (max shadow-blur 0))
47
 
         (shadow-opacity (min shadow-opacity 100))
48
 
         (shadow-opacity (max shadow-opacity 0))
49
 
         (type (car (gimp-drawable-type-with-alpha drawable)))
50
 
         (image-width (car (gimp-image-width image)))
51
 
         (image-height (car (gimp-image-height image)))
52
 
         (from-selection 0)
53
 
         (active-selection 0)
54
 
         (shadow-layer 0))
55
 
 
56
 
    (gimp-context-push)
57
 
 
58
 
    (gimp-image-set-active-layer image drawable)
59
 
 
60
 
    (gimp-image-undo-group-start image)
61
 
  
62
 
    (gimp-layer-add-alpha drawable)
63
 
    (if (= (car (gimp-selection-is-empty image)) TRUE)
64
 
        (begin
65
 
          (gimp-selection-layer-alpha drawable)
66
 
          (set! from-selection FALSE))
67
 
        (begin
68
 
          (set! from-selection TRUE)
69
 
          (set! active-selection (car (gimp-selection-save image)))))
70
 
 
71
 
    (let* ((selection-bounds (gimp-selection-bounds image))
72
 
           (select-offset-x (cadr selection-bounds))
73
 
           (select-offset-y (caddr selection-bounds))
74
 
           (select-width (- (cadr (cddr selection-bounds)) select-offset-x))
75
 
           (select-height (- (caddr (cddr selection-bounds)) select-offset-y))
76
 
  
77
 
           (shadow-width (+ select-width (* 2 shadow-blur)))
78
 
           (shadow-height (+ select-height (* 2 shadow-blur)))
79
 
           
80
 
           (shadow-offset-x (- select-offset-x shadow-blur))
81
 
           (shadow-offset-y (- select-offset-y shadow-blur)))
82
 
 
83
 
      (if (= allow-resize TRUE)
84
 
          (let* ((new-image-width image-width)
85
 
                 (new-image-height image-height)
86
 
                 (image-offset-x 0)
87
 
                 (image-offset-y 0))
88
 
 
89
 
            (if (< (+ shadow-offset-x shadow-transl-x) 0)
90
 
                (begin
91
 
                  (set! image-offset-x (- 0 (+ shadow-offset-x
92
 
                                               shadow-transl-x)))
93
 
                  (set! shadow-offset-x (- 0 shadow-transl-x))
94
 
                  (set! new-image-width (- new-image-width image-offset-x))))
95
 
 
96
 
            (if (< (+ shadow-offset-y shadow-transl-y) 0)
97
 
                (begin
98
 
                  (set! image-offset-y (- 0 (+ shadow-offset-y
99
 
                                               shadow-transl-y)))
100
 
                  (set! shadow-offset-y (- 0 shadow-transl-y))
101
 
                  (set! new-image-height (- new-image-height image-offset-y))))
102
 
 
103
 
            (if (> (+ (+ shadow-width shadow-offset-x) shadow-transl-x)
104
 
                   new-image-width)
105
 
                (set! new-image-width
106
 
                      (+ (+ shadow-width shadow-offset-x) shadow-transl-x)))
107
 
 
108
 
            (if (> (+ (+ shadow-height shadow-offset-y) shadow-transl-y)
109
 
                   new-image-height)
110
 
                (set! new-image-height
111
 
                      (+ (+ shadow-height shadow-offset-y) shadow-transl-y)))
112
 
 
113
 
            (gimp-image-resize image
114
 
                               new-image-width
115
 
                               new-image-height
116
 
                               image-offset-x
117
 
                               image-offset-y)))
118
 
 
119
 
      (set! shadow-layer (car (gimp-layer-new image
120
 
                                              shadow-width
121
 
                                              shadow-height
122
 
                                              type
123
 
                                              "Drop-Shadow"
124
 
                                              shadow-opacity
125
 
                                              NORMAL-MODE)))
126
 
      (gimp-image-add-layer image shadow-layer -1)
127
 
      (gimp-layer-set-offsets shadow-layer
128
 
                              shadow-offset-x
129
 
                              shadow-offset-y))
130
 
 
131
 
    (gimp-drawable-fill shadow-layer TRANSPARENT-FILL)
132
 
    (gimp-context-set-background shadow-color)
133
 
    (gimp-edit-fill shadow-layer BACKGROUND-FILL)
134
 
    (gimp-selection-none image)
135
 
    (gimp-layer-set-preserve-trans shadow-layer FALSE)
136
 
    (if (>= shadow-blur 1.0) (plug-in-gauss-rle 1
137
 
                                                image
138
 
                                                shadow-layer
139
 
                                                shadow-blur
140
 
                                                TRUE
141
 
                                                TRUE))
142
 
    (gimp-layer-translate shadow-layer shadow-transl-x shadow-transl-y)
143
 
 
144
 
    (if (= from-selection TRUE)
145
 
        (begin
146
 
          (gimp-selection-load active-selection)
147
 
          (gimp-edit-clear shadow-layer)
148
 
          (gimp-image-remove-channel image active-selection)))
149
 
 
150
 
    (if (and
151
 
         (= (car (gimp-layer-is-floating-sel drawable)) 0)
152
 
         (= from-selection FALSE))
153
 
        (gimp-image-raise-layer image drawable))
154
 
 
155
 
    (gimp-image-set-active-layer image drawable)
156
 
    (gimp-image-undo-group-end image)
157
 
    (gimp-displays-flush)
158
 
 
159
 
    (gimp-context-pop)))
 
39
                               drawable
 
40
                               shadow-transl-x
 
41
                               shadow-transl-y
 
42
                               shadow-blur
 
43
                               shadow-color
 
44
                               shadow-opacity
 
45
                               allow-resize)
 
46
  (let* (
 
47
        (shadow-blur (max shadow-blur 0))
 
48
        (shadow-opacity (min shadow-opacity 100))
 
49
        (shadow-opacity (max shadow-opacity 0))
 
50
        (type (car (gimp-drawable-type-with-alpha drawable)))
 
51
        (image-width (car (gimp-image-width image)))
 
52
        (image-height (car (gimp-image-height image)))
 
53
        (from-selection 0)
 
54
        (active-selection 0)
 
55
        (shadow-layer 0)
 
56
        )
 
57
 
 
58
  (gimp-context-push)
 
59
 
 
60
  (gimp-image-set-active-layer image drawable)
 
61
 
 
62
  (gimp-image-undo-group-start image)
 
63
 
 
64
  (gimp-layer-add-alpha drawable)
 
65
  (if (= (car (gimp-selection-is-empty image)) TRUE)
 
66
      (begin
 
67
        (gimp-selection-layer-alpha drawable)
 
68
        (set! from-selection FALSE))
 
69
      (begin
 
70
        (set! from-selection TRUE)
 
71
        (set! active-selection (car (gimp-selection-save image)))))
 
72
 
 
73
  (let* ((selection-bounds (gimp-selection-bounds image))
 
74
         (select-offset-x (cadr selection-bounds))
 
75
         (select-offset-y (caddr selection-bounds))
 
76
         (select-width (- (cadr (cddr selection-bounds)) select-offset-x))
 
77
         (select-height (- (caddr (cddr selection-bounds)) select-offset-y))
 
78
 
 
79
         (shadow-width (+ select-width (* 2 shadow-blur)))
 
80
         (shadow-height (+ select-height (* 2 shadow-blur)))
 
81
 
 
82
         (shadow-offset-x (- select-offset-x shadow-blur))
 
83
         (shadow-offset-y (- select-offset-y shadow-blur)))
 
84
 
 
85
    (if (= allow-resize TRUE)
 
86
        (let* ((new-image-width image-width)
 
87
               (new-image-height image-height)
 
88
               (image-offset-x 0)
 
89
               (image-offset-y 0))
 
90
 
 
91
          (if (< (+ shadow-offset-x shadow-transl-x) 0)
 
92
              (begin
 
93
                (set! image-offset-x (- 0 (+ shadow-offset-x
 
94
                                             shadow-transl-x)))
 
95
                (set! shadow-offset-x (- 0 shadow-transl-x))
 
96
                (set! new-image-width (- new-image-width image-offset-x))))
 
97
 
 
98
          (if (< (+ shadow-offset-y shadow-transl-y) 0)
 
99
              (begin
 
100
                (set! image-offset-y (- 0 (+ shadow-offset-y
 
101
                                             shadow-transl-y)))
 
102
                (set! shadow-offset-y (- 0 shadow-transl-y))
 
103
                (set! new-image-height (- new-image-height image-offset-y))))
 
104
 
 
105
          (if (> (+ (+ shadow-width shadow-offset-x) shadow-transl-x)
 
106
                 new-image-width)
 
107
              (set! new-image-width
 
108
                    (+ (+ shadow-width shadow-offset-x) shadow-transl-x)))
 
109
 
 
110
          (if (> (+ (+ shadow-height shadow-offset-y) shadow-transl-y)
 
111
                 new-image-height)
 
112
              (set! new-image-height
 
113
                    (+ (+ shadow-height shadow-offset-y) shadow-transl-y)))
 
114
 
 
115
          (gimp-image-resize image
 
116
                             new-image-width
 
117
                             new-image-height
 
118
                             image-offset-x
 
119
                             image-offset-y)
 
120
        )
 
121
    )
 
122
 
 
123
    (set! shadow-layer (car (gimp-layer-new image
 
124
                                            shadow-width
 
125
                                            shadow-height
 
126
                                            type
 
127
                                            "Drop Shadow"
 
128
                                            shadow-opacity
 
129
                                            NORMAL-MODE)))
 
130
   (gimp-image-add-layer image shadow-layer -1)
 
131
    (gimp-layer-set-offsets shadow-layer
 
132
                            shadow-offset-x
 
133
                            shadow-offset-y))
 
134
 
 
135
  (gimp-drawable-fill shadow-layer TRANSPARENT-FILL)
 
136
  (gimp-context-set-background shadow-color)
 
137
  (gimp-edit-fill shadow-layer BACKGROUND-FILL)
 
138
  (gimp-selection-none image)
 
139
  (gimp-layer-set-lock-alpha shadow-layer FALSE)
 
140
  (if (>= shadow-blur 1.0) (plug-in-gauss-rle 1
 
141
                                              image
 
142
                                              shadow-layer
 
143
                                              shadow-blur
 
144
                                              TRUE
 
145
                                              TRUE))
 
146
  (gimp-layer-translate shadow-layer shadow-transl-x shadow-transl-y)
 
147
 
 
148
  (if (= from-selection TRUE)
 
149
      (begin
 
150
        (gimp-selection-load active-selection)
 
151
        (gimp-edit-clear shadow-layer)
 
152
        (gimp-image-remove-channel image active-selection)))
 
153
 
 
154
  (if (and
 
155
       (= (car (gimp-layer-is-floating-sel drawable)) 0)
 
156
       (= from-selection FALSE))
 
157
      (gimp-image-raise-layer image drawable))
 
158
 
 
159
  (gimp-image-set-active-layer image drawable)
 
160
  (gimp-image-undo-group-end image)
 
161
  (gimp-displays-flush)
 
162
 
 
163
  (gimp-context-pop)
 
164
  )
 
165
)
160
166
 
161
167
(script-fu-register "script-fu-drop-shadow"
162
 
                    _"_Drop-Shadow..."
163
 
                    "Add a drop-shadow of the current selection or alpha-channel"
164
 
                    "Sven Neumann <sven@gimp.org>"
165
 
                    "Sven Neumann"
166
 
                    "1999/12/21"
167
 
                    "RGB* GRAY*"
168
 
                    SF-IMAGE       "Image"          0
169
 
                    SF-DRAWABLE    "Drawable"       0
170
 
                    SF-ADJUSTMENT _"Offset X"       '(8 -4096 4096 1 10 0 1)
171
 
                    SF-ADJUSTMENT _"Offset Y"       '(8 -4096 4096 1 10 0 1)
172
 
                    SF-ADJUSTMENT _"Blur radius"    '(15 0 1024 1 10 0 1)
173
 
                    SF-COLOR      _"Color"          '(0 0 0)
174
 
                    SF-ADJUSTMENT _"Opacity"        '(80 0 100 1 10 0 0)
175
 
                    SF-TOGGLE     _"Allow resizing" TRUE)
 
168
  _"_Drop Shadow..."
 
169
  _"Add a drop shadow to the selected region (or alpha)"
 
170
  "Sven Neumann <sven@gimp.org>"
 
171
  "Sven Neumann"
 
172
  "1999/12/21"
 
173
  "RGB* GRAY*"
 
174
  SF-IMAGE      "Image"           0
 
175
  SF-DRAWABLE   "Drawable"        0
 
176
  SF-ADJUSTMENT _"Offset X"       '(8 -4096 4096 1 10 0 1)
 
177
  SF-ADJUSTMENT _"Offset Y"       '(8 -4096 4096 1 10 0 1)
 
178
  SF-ADJUSTMENT _"Blur radius"    '(15 0 1024 1 10 0 1)
 
179
  SF-COLOR      _"Color"          "black"
 
180
  SF-ADJUSTMENT _"Opacity"        '(80 0 100 1 10 0 0)
 
181
  SF-TOGGLE     _"Allow resizing" TRUE
 
182
)
176
183
 
177
184
(script-fu-menu-register "script-fu-drop-shadow"
178
 
                         _"<Image>/Script-Fu/Shadow")
 
185
                         "<Image>/Filters/Light and Shadow/Shadow")