-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdx-screenshot-2016.scm
466 lines (420 loc) · 22 KB
/
dx-screenshot-2016.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
(define (script-fu-dx-screenshot2016 image
drawable
drop-shadow
shadow-color
shadow-offset-x
shadow-offset-y
shadow-blur
shadow-opacity
draw-border
border-color
border-opacity
border-position
crop-type
amplitude
reverse-phase
target
layers-type
history-type
add-white)
(let* (
(image-width (car (gimp-image-width image)))
(image-height (car (gimp-image-height image)))
(is-GIF (car (gimp-drawable-is-indexed drawable)))
(user-selection-exists (car (gimp-selection-bounds image)))
(border-layer 0)
(target-layer (vector-ref (car (cdr (gimp-image-get-layers image)))
(- (car (gimp-image-get-layers image)) 1)
)) ; The last layer
(target-layer-name (car (gimp-item-get-name target-layer)))
(shadow-layer 0)
(white-layer 0)
(group 0)
(initial-selection 0)
(sel-docked-top FALSE)
(sel-docked-left FALSE) (sel-docked-right FALSE)
(sel-docked-bottom FALSE)
(num-of-docked 0)
(x1 0) (y1 0) (x2 0) (y2 0) (w 0) (h 0) (x 0) (y 0)
(phase 0) (points 0) (point 0)
)
; GIMP 2.9+ default opacity fix
(if (or (char=? (string-ref (car (gimp-version)) 2) #\9) (char=? (string-ref (car (gimp-version)) 2) #\1))(begin
(if (= shadow-opacity 22) (set! shadow-opacity 50))
(if (= border-opacity 12)
(if (= border-position 0) ; inner
(set! border-opacity 38)
; else
(set! border-opacity 25)
))
) ; else
(if (and (= border-position 0) (= border-opacity 12)) ; default inner
(set! border-opacity 20)) ; Inner border should look like outer
)
(gimp-context-push)
(if (= history-type 0) (gimp-image-undo-group-start image))
;BEGIN -----------------------------------------------------------
(if (= history-type 1) (gimp-image-undo-group-start image)) ; Prepare stuff
(if (= is-GIF TRUE) (begin
(gimp-image-convert-rgb image) ; No opacity in INDEXED
(set! layers-type 2))) ; Merge layers
(if (= user-selection-exists FALSE) (begin
(if (= target 0)
(gimp-selection-all image) ; Full image
(begin ; Current layer
(gimp-image-select-rectangle image CHANNEL-OP-REPLACE
(car (gimp-drawable-offsets drawable))
(cadr (gimp-drawable-offsets drawable))
(car (gimp-drawable-width drawable))
(car (gimp-drawable-height drawable)))
(set! user-selection-exists TRUE)
(set! target-layer drawable)
(set! target-layer-name
(car (gimp-item-get-name target-layer)))
(set! crop-type 2) ; No need to crop in this case
)
)
))
(if (gimp-drawable-has-alpha target-layer)
(gimp-layer-add-alpha target-layer))
(gimp-image-set-active-layer image target-layer) ; The main layer
(set! initial-selection (car (gimp-selection-save image)))
(if (= history-type 1) (gimp-image-undo-group-end image))
(if (= history-type 1) (gimp-image-undo-group-start image)) ; Prepare layers
(if (= layers-type 0) (begin ; Group
(if (and (= draw-border TRUE)
(= drop-shadow TRUE)) (begin ; If we need group
(set! group (car (gimp-layer-group-new image)))
(gimp-item-set-name group "Decoration")
(gimp-image-insert-layer image group 0 ; no parent
(- (car (gimp-image-get-item-position image target-layer)) 1)))
; If we don't need group
(set! layers-type 1))
))
(if (= layers-type 1) ; doesn't work if target-layer is in the middle
(gimp-image-lower-item-to-bottom image target-layer))
(if (= history-type 1) (gimp-image-undo-group-end image))
; Check margins for border
(if (= user-selection-exists TRUE) (begin
(if (= (list-ref (gimp-selection-bounds image) 1) 0) (begin
(set! sel-docked-left TRUE)
(set! num-of-docked (+ num-of-docked 1)) ))
(if (= (list-ref (gimp-selection-bounds image) 2) 0) (begin
(set! sel-docked-top TRUE)
(set! num-of-docked (+ num-of-docked 1)) ))
(if (= (list-ref (gimp-selection-bounds image) 3) image-width) (begin
(set! sel-docked-right TRUE)
(set! num-of-docked (+ num-of-docked 1)) ))
(if (= (list-ref (gimp-selection-bounds image) 4) image-height) (begin
(set! sel-docked-bottom TRUE)
(set! num-of-docked (+ num-of-docked 1)) ))
; If the entire image is selected, assume no selection
(if (= num-of-docked 4) (set! user-selection-exists FALSE))
))
; Turn off crop of no selection
(if (= user-selection-exists FALSE) (set! crop-type 2))
(if (= draw-border TRUE) (begin ; --------- Border Start ---------
(if (= history-type 1) (gimp-image-undo-group-start image))
; Fix margins for border
(if (= user-selection-exists TRUE) (begin
; Add 2-pixel margins from the docked sides for boder
; because 1-pixel margin breaks gimp-selection-border
(if (= sel-docked-left TRUE)
(gimp-image-resize image
(+ (car (gimp-image-width image)) 2)
(car (gimp-image-height image))
2 0) )
(if (= sel-docked-right TRUE)
(gimp-image-resize image
(+ (car (gimp-image-width image)) 2)
(car (gimp-image-height image))
0 0) )
(if (= sel-docked-top TRUE)
(gimp-image-resize image
(car (gimp-image-width image))
(+ (car (gimp-image-height image)) 2)
0 2) )
(if (= sel-docked-bottom TRUE)
(gimp-image-resize image
(car (gimp-image-width image))
(+ (car (gimp-image-height image)) 2)
0 0) )
(if (= border-position 1) ; If outer border
; Expand selection by 1px on each side
(gimp-selection-grow image 1))
) (begin ; If the entire image is selected
; Simply expand the image and selection by 2px
(gimp-image-resize image (+ image-width 2)
(+ image-height 2) 1 1)
(if (= border-position 1) (begin ; If outer border
(gimp-selection-all image)
(gimp-image-resize image
(+ (car (gimp-image-width image)) 2)
(+ (car (gimp-image-height image)) 2) 1 1)))
(set! sel-docked-top TRUE)
(set! sel-docked-left TRUE) (set! sel-docked-right TRUE)
(set! sel-docked-bottom TRUE)
))
(set! image-width (car (gimp-image-width image))) ; Updare img
(set! image-height (car (gimp-image-height image))) ; dimensions
; Make a 1-pixel inner border from this edge (beware edges)
(gimp-selection-border image 1)
(if (= crop-type 0) (begin ; wavy-crop
; Remove border from undocked sides.
(set! x1 (list-ref (gimp-selection-bounds image) 1))
(set! y1 (list-ref (gimp-selection-bounds image) 2))
(set! x2 (list-ref (gimp-selection-bounds image) 3))
(set! y2 (list-ref (gimp-selection-bounds image) 4))
(set! w (- x2 x1)) (set! h (- y2 y1))
; w
; (x1, y1) *-------------------------
; |########################|
; |##| |##|
; h |##| |##|
; |##|__________________|##|
; |########################|
; -------------------------* (x2, y2)
; Removing inner lines
(if (= sel-docked-left FALSE) (gimp-image-select-rectangle image
CHANNEL-OP-SUBTRACT x1 (+ y1 1) 1 (- h 2) )) ; x y w h !!!
(if (= sel-docked-right FALSE) (gimp-image-select-rectangle image
CHANNEL-OP-SUBTRACT (- x2 1) (+ y1 1) 1 (- h 2) ))
(if (= sel-docked-top FALSE) (gimp-image-select-rectangle image
CHANNEL-OP-SUBTRACT (+ x1 1) y1 (- w 2) 1))
(if (= sel-docked-bottom FALSE) (gimp-image-select-rectangle image
CHANNEL-OP-SUBTRACT (+ x1 1) (- y2 1) (- w 2) 1))
; Removing corner dots
(if (and (= sel-docked-left FALSE) (= sel-docked-top FALSE))
(gimp-image-select-rectangle image CHANNEL-OP-SUBTRACT
x1 y1 1 1 ))
(if (and (= sel-docked-right FALSE) (= sel-docked-top FALSE))
(gimp-image-select-rectangle image CHANNEL-OP-SUBTRACT
(- x2 1) y1 1 1 ))
(if (and (= sel-docked-left FALSE) (= sel-docked-bottom FALSE))
(gimp-image-select-rectangle image CHANNEL-OP-SUBTRACT
x1 (- y2 1) 1 1 ))
(if (and (= sel-docked-right FALSE) (= sel-docked-bottom FALSE))
(gimp-image-select-rectangle image CHANNEL-OP-SUBTRACT
(- x2 1) (- y2 1) 1 1 ))
))
; Selection may disappear (if (= num-of-docked 0))
(if (= (car (gimp-selection-bounds image)) TRUE) (begin
(set! border-layer (car (gimp-layer-new image image-width
image-height
RGBA-IMAGE "Border"
border-opacity NORMAL-MODE)))
(gimp-drawable-fill border-layer TRANSPARENT-FILL)
(if (= layers-type 0) ; Group
(gimp-image-insert-layer image border-layer group 0)
; else
(gimp-image-insert-layer image border-layer 0 ; no parent
(car (gimp-image-get-item-position image target-layer)) ))
(gimp-context-set-foreground border-color)
(gimp-edit-bucket-fill-full border-layer FG-BUCKET-FILL NORMAL-MODE
100 ; opacity
0 ; threshold
FALSE ; sample-merged
TRUE ; fill-transparent
SELECT-CRITERION-COMPOSITE 0 0)
(plug-in-autocrop-layer RUN-NONINTERACTIVE image border-layer)
))
(if (= history-type 1) (gimp-image-undo-group-end image))
)) ; --------- Border End ---------
(gimp-image-select-item image CHANNEL-OP-REPLACE initial-selection)
(if (= history-type 1) (gimp-image-undo-group-start image))
(if (= crop-type 0) (begin ; --------- Wavy crop Start ---------
(if (< num-of-docked 2)
(gimp-message (string-append
"Wawy crop from 3 or more sides is not recommended!\n"
"Wavy-cropping " (number->string (- 4 num-of-docked)) " sides")))
(if (= sel-docked-left TRUE)
(set! x1 (list-ref (gimp-selection-bounds image) 1))
; else
(set! x1 (+ (list-ref (gimp-selection-bounds image) 1) 1)))
(if (= sel-docked-top TRUE)
(set! y1 (list-ref (gimp-selection-bounds image) 2))
; else
(set! y1 (+ (list-ref (gimp-selection-bounds image) 2) 1)))
(if (= sel-docked-right TRUE)
(set! x2 (list-ref (gimp-selection-bounds image) 3))
; else
(set! x2 (- (list-ref (gimp-selection-bounds image) 3) 1)))
(if (= sel-docked-bottom TRUE)
(set! y2 (list-ref (gimp-selection-bounds image) 4))
; else
(set! y2 (- (list-ref (gimp-selection-bounds image) 4) 1)))
; NOTE: The crop is shifted by 1px to touch the border
(set! points (cons-array (* (+ (* 2 (- x2 x1)) (* 2 (- y2 y1))) 2) 'double)) ; amount of points for points array
(set! x x1)
(set! y y1)
(set! amplitude (/ amplitude 200))
(if (= reverse-phase TRUE) (set! phase 3.1415))
; Top border
(while (< x x2)
(aset points point x) ;x
(set! point (+ point 1))
(if (= sel-docked-top TRUE)
(aset points point y1) ;y
; else
(aset points point (+ (- 0 1) y1 (* (* (- x2 x1) amplitude ) (sin (+ phase (* 6.2832 (/ (- x x1) (- x2 x1)))))))) ;y
)
(set! point (+ point 1))
(set! x (+ x 1))
)
; Right border
(while (< y y2)
(if (= sel-docked-right TRUE)
(aset points point x2) ;x
; else
(aset points point (+ 1 x2 (* (* (- y2 y1) amplitude) (sin (+ phase (* -6.2832 (/ (- y y1) (- y2 y1)))))))) ;x
)
(set! point (+ point 1))
(aset points point y) ;y
(set! point (+ point 1))
(set! y (+ y 1))
)
; Bottom border
(while (> x x1)
(aset points point x) ;x
(set! point (+ point 1))
(if (= sel-docked-bottom TRUE)
(aset points point y2)
; else
(aset points point (+ 1 y2 (* (* (- x2 x1) amplitude) (sin (+ phase (* 6.2832 (/ (- x x1) (- x2 x1)))))))) ;y
)
(set! point (+ point 1))
(set! x (- x 1))
)
; Left border
(while (> y y1)
(if (= sel-docked-left TRUE)
(aset points point x1)
; else
(aset points point (+ (- 0 1) x1 (* (* (- y2 y1) amplitude) (sin (+ phase (* -6.2832 (/ (- y y1) (- y2 y1))))))))
)
(set! point (+ point 1))
(aset points point y)
(set! point (+ point 1))
(set! y (- y 1))
)
; Actual cropping
(gimp-image-select-polygon image CHANNEL-OP-REPLACE point points)
(gimp-selection-invert image)
(gimp-edit-clear target-layer) ; clears the area
(gimp-selection-invert image)
(gimp-image-set-active-layer image target-layer) ; Obligatory !!!!
(plug-in-autocrop-layer RUN-NONINTERACTIVE image target-layer)
))
(if (= crop-type 1)(begin ; -------- Simple crop --------
(gimp-image-select-item image CHANNEL-OP-REPLACE initial-selection)
(map (lambda (layer) ; Apply
(if (and (not (= layer border-layer)) (not (= layer group)))
(begin ; This
(gimp-layer-resize-to-image-size layer)
(gimp-layer-resize layer
(- (list-ref (cdr (gimp-selection-bounds image)) 2)
(list-ref (cdr (gimp-selection-bounds image)) 0) )
(- (list-ref (cdr (gimp-selection-bounds image)) 3)
(list-ref (cdr (gimp-selection-bounds image)) 1) )
(- 0 (list-ref (cdr (gimp-selection-bounds image)) 0))
(- 0 (list-ref (cdr (gimp-selection-bounds image)) 1))))))
(vector->list (cadr (gimp-image-get-layers image)))) ;To all layers
))
(if (and (= target 1) ; Current layer
(= draw-border FALSE) ; No border !!!
(> crop-type 0)) ; not Wavy Crop
(gimp-selection-none image)) ; We can set (script-fu-drop-shadow ) free
; In other cases, the selection is initial and the shadow applis to it
(gimp-image-remove-channel image initial-selection)
(if (= history-type 1) (gimp-image-undo-group-end image))
(if (= drop-shadow TRUE) (begin ; --------- Shadow ---------
(if (= history-type 1) (gimp-image-undo-group-start image))
(gimp-image-set-active-layer image target-layer) ; Does not seem to work
; (script-fu-drop-shadow always applies shador to border if it exists)
(script-fu-drop-shadow image target-layer
shadow-offset-x
shadow-offset-y
shadow-blur
shadow-color
shadow-opacity
1) ; Resize image if required
(set! shadow-layer (car (gimp-image-get-layer-by-name image
"Drop Shadow")))
(gimp-item-set-name shadow-layer "Shadow")
(if (= layers-type 0) ; Group
(gimp-image-reorder-item image shadow-layer group 0)
; else
(gimp-image-reorder-item image shadow-layer 0
(+ (car (gimp-image-get-item-position image target-layer)) 1) ))
(if (= history-type 1) (gimp-image-undo-group-end image))
)) ; --------- Shadow End ---------
(if (< crop-type 2) (gimp-image-resize-to-layers image)) ; If any crop
(if (= history-type 1) (gimp-image-undo-group-start image))
(gimp-selection-none image)
(if (= add-white TRUE)(begin
(set! white-layer ; Renew
(car (gimp-image-get-layer-by-name image "White")))
(if (>= white-layer 0) (gimp-image-remove-layer image white-layer))
(set! white-layer (car (gimp-layer-new image
(car (gimp-image-width image))
(car (gimp-image-height image))
RGBA-IMAGE "White" 100 NORMAL-MODE)))
(gimp-drawable-fill white-layer WHITE-FILL)
(gimp-image-insert-layer image white-layer 0
(car (gimp-image-get-layers image))) ; To end
))
(if (= history-type 1) (gimp-image-undo-group-end image))
(if (= layers-type 2) (begin ; --------- Merge layers ----------
(if (= history-type 1) (gimp-image-undo-group-start image))
(if (= draw-border TRUE)
(set! target-layer (car (gimp-image-merge-down image
border-layer
EXPAND-AS-NECESSARY)))
) ; 1. If border exists, Border & Target -> Target
(set! target-layer (car (gimp-image-merge-down image target-layer
EXPAND-AS-NECESSARY))
) ; 2. Target & Shadow -> Target
(if (= add-white TRUE)
(set! target-layer (car (gimp-image-merge-down image
target-layer
EXPAND-AS-NECESSARY)))
) ; 3. Target & White -> Target
(gimp-item-set-name target-layer
target-layer-name) ;Important! Recovers duration
(if (= history-type 1) (gimp-image-undo-group-end image))
))
(if (= is-GIF TRUE)(gimp-image-convert-indexed image NO-DITHER
MAKE-PALETTE 255 TRUE TRUE ""))
;END -----------------------------------------------------------
(if (= history-type 0) (gimp-image-undo-group-end image))
(gimp-displays-flush)
(gimp-context-pop)
)) ;let, define
(script-fu-register "script-fu-dx-screenshot2016"
_"_Screenshot processing 2016..."
_"Draws border, adds modern shadow and makes wavy crop. Even in GIFs."
"Vladislav Glagolev <vladislav.glagolev@devexpress.com>, Konstantin Beliakov <Konstantin.Belyakov@devexpress.com>"
"DevExpress Inc."
"01/16/2018" ;<=TIMESTAMP
"RGB* INDEXED* GRAY*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-TOGGLE _"Drop shadow" TRUE
SF-COLOR _"Shadow color" "black"
SF-ADJUSTMENT _"Shadow offset X (-10..10 pixels)" '(0 -10 10 1 10 0)
SF-ADJUSTMENT _"Shadow offset Y (-10..10 pixels)" '(2 -10 10 1 10 0)
SF-ADJUSTMENT _"Shadow blur radius (0..40 pixels)" '(8 0 40 1 10 0 0)
SF-ADJUSTMENT _"Shadow opacity (0-100%)" '(22 0 100 1 10 0 0)
SF-TOGGLE _"Draw border (set if not already exists)" FALSE
SF-COLOR _"Border color" "black"
SF-ADJUSTMENT _"Border opacity (0-100%)" '(12 0 100 1 10 0 0)
SF-OPTION _"Border position" '("Inner" "Outer")
SF-OPTION _"Crop type" '("Wavy crop" "Rectangular crop" "No crop")
SF-ADJUSTMENT _"Waves strength (0-calm, 10-tsunami)" '(3 0 10 1 0 0)
SF-TOGGLE _"Reverse wave phase" FALSE
SF-OPTION _"Target (if no selection)" '("Full image" "Current layer")
SF-OPTION _"Layer arrangement type" '("Group" "Separate layers" "Merge")
SF-OPTION _"History type" '("One step" "Several steps" "Verbose")
SF-TOGGLE _"Add white layer" TRUE
)
(script-fu-menu-register "script-fu-dx-screenshot2016" "<Image>/DX")