wickedhud_b2 sources
[xonotic/mediasource.git] / gfx / hud / wickedhud / whiteborder.scm
1 ;Adds a white border and a faint glow, based on the alpha channel
2 ;Input: fileIn borderGrow borderFeather objectShrink objectFeather glowBlur
3
4 (define (whiteborder fileIn glowBlur borderGrow borderFeather objectShrink objectFeather)
5         (let*
6                 (
7                         (image (car (gimp-file-load 1 fileIn fileIn)))
8                         (bottomLayer (car (gimp-image-get-active-layer image)))
9                         (middleLayer (car (gimp-layer-new-from-drawable bottomLayer image)))
10                         (topLayer (car (gimp-layer-new-from-drawable bottomLayer image)))
11
12                         (borderColor '(255 255 255))
13                         (borderGlow '(223 223 223))
14                 )
15
16         ;add layers
17                 (gimp-image-add-layer image middleLayer -1)
18                 (gimp-image-add-layer image topLayer -1)
19
20         ;bottom layer: create extended glow siluette of the object
21         (gimp-context-set-foreground borderGlow)
22         (gimp-selection-layer-alpha bottomLayer)
23         (gimp-selection-grow image (- borderGrow 1))
24         (gimp-selection-feather image borderFeather)
25         (gimp-edit-fill bottomLayer 0)
26         (gimp-selection-none image)
27         (plug-in-gauss-rle 1 image bottomLayer glowBlur 1 1)
28
29         ;middle layer: create extended siluette of the object
30         (gimp-context-set-foreground borderColor)
31         (gimp-selection-layer-alpha middleLayer)
32         (gimp-selection-grow image borderGrow)
33         (gimp-selection-feather image borderFeather)
34         (gimp-edit-fill middleLayer 0)
35
36         ;top layer: reduce border of the object on the top layer
37         (gimp-selection-layer-alpha topLayer)
38         (gimp-selection-shrink image objectShrink)
39         (gimp-selection-feather image objectFeather)
40         (gimp-selection-invert image)
41         (gimp-edit-clear topLayer)
42
43         ;merge and save
44                 (set! bottomLayer (car (gimp-image-merge-visible-layers image 1)))
45                 (gimp-file-save 1 image bottomLayer fileIn fileIn)
46                 (gimp-image-delete image)
47         )
48 )
49