; Image Beveler rel 0.02 ; Created by Graechan ; Comments directed to http://gimpchat.com or http://gimpscripts.com ; ; License: GPLv3 ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; To view a copy of the GNU General Public License ; visit: http://www.gnu.org/licenses/gpl.html ; ; ; ------------ ;| Change Log | ; ------------ ; Rel 0.01 - Initial Release ; Rel o.02 - Added contour curves (define list-contours '("Linear (0)" "Cone (1)" "Cone - Inverted (2)" "Cove - Deep (3)" "Cove-Shallow (4)" "Gaussian (5)" "Half Round (6)" "Ring (7)" "Ring - Double (8)" "Rolling Slope - Descending (9)" "Rounded Steps (10)" "Sawtooth 1 (11)") ) (define (curves-contour drawable channel contour) (let* ((contourtypes #(0 0 0 0 0 0 0 0 0 1 1)) (contourlengths #(6 6 10 14 18 10 18 18 10 256 256)) (contours #(#(0 0 127 255 255 0) #(0 255 127 0 255 255) #(0 64 94 74 150 115 179 179 191 255) #(0 0 5 125 6 125 48 148 79 179 107 217 130 255) #(0 0 33 8 64 38 97 102 128 166 158 209 191 235 222 247 255 255) #(0 0 28 71 87 166 194 240 255 255) #(0 0 33 110 64 237 97 240 128 138 158 33 191 5 222 99 255 255) #(0 0 33 74 64 219 97 186 128 0 158 176 191 201 222 3 255 255) #(3 255 54 99 97 107 179 153 252 0) #(0 5 9 13 16 19 22 25 27 29 30 32 33 34 35 36 38 39 40 41 43 44 46 47 48 49 50 51 52 53 54 55 55 56 56 57 57 58 58 59 59 59 60 60 60 61 61 61 61 62 62 62 62 62 63 63 63 63 63 63 64 64 64 64 64 71 75 78 81 84 86 89 91 93 95 96 98 99 101 102 103 104 105 107 107 108 110 111 112 113 114 115 116 117 118 119 119 120 121 121 122 123 123 123 124 124 124 125 125 125 125 125 125 125 126 126 126 126 126 126 126 125 125 125 125 125 125 125 125 130 134 137 141 145 148 151 153 156 158 160 162 163 165 166 167 168 170 171 171 172 173 174 175 176 177 178 178 179 180 181 181 182 183 183 184 184 185 185 186 186 187 187 188 188 189 189 189 189 190 190 190 190 191 191 191 191 191 191 191 191 191 191 193 194 196 197 198 200 201 203 204 205 207 208 209 211 212 213 214 215 217 218 219 220 220 221 222 222 223 223 224 224 224 224 224 223 223 222 222 221 221 220 219 218 217 216 215 214 213 212 211 210 209 208 206 205 204 203 202 200 199 198 197 196 194 194) #(0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 128 126 124 122 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2)))) (if (= (vector-ref contourtypes (- contour 1)) 0) (gimp-curves-spline drawable channel (vector-ref contourlengths (- contour 1)) (vector-ref contours (- contour 1))) (gimp-curves-explicit drawable channel (vector-ref contourlengths (- contour 1)) (vector-ref contours (- contour 1))) ) ) ) (define (script-fu-image-beveler image layer layer-mode bev-type bev-dir bev-width shape contour prenoise light-angle light-elevation depth postblur gloss keep-selection-in merge ) (let* ( (width (car (gimp-image-width image))) (height (car (gimp-image-height image))) (alpha (car (gimp-drawable-has-alpha layer))) (layer-name (car (gimp-drawable-get-name layer))) (image-channel 0) (bevel-layer 0) (name 0) (*newpoint* (cons-array 6 'double)) (*newpointx1* (cons-array 16 'double)) (y1 0) (y2 0) (y3 0) (y4 0) (y5 0) (y6 0) (keep-selection keep-selection-in) (selection-bounds 0) (bounds-x1 0) (bounds-y1 0) (bounds-x2 0) (bounds-y2 0) ) (gimp-context-push) (gimp-image-undo-group-start image) (gimp-context-set-foreground '(0 0 0)) (gimp-context-set-background '(255 255 255)) (if (= alpha FALSE) (gimp-layer-add-alpha layer)) ;;;;check that a selection was made if not make one ; (if (= (car (gimp-selection-is-empty image)) TRUE) (set! keep-selection FALSE)) (if (= (car (gimp-selection-is-empty image)) TRUE) (gimp-selection-layer-alpha layer)) ;;;;find the selection co-ordinates (set! selection-bounds (cdr (gimp-selection-bounds image))) (set! bounds-x1 (car selection-bounds));x coordinate of upper left corner of selection bounds (set! bounds-y1 (cadr selection-bounds));y coordinate of upper left corner of selection bounds (set! bounds-x2 (caddr selection-bounds));x coordinate of lower right corner of selection bounds (set! bounds-y2 (cadddr selection-bounds));y coordinate of lower right corner of selection bounds ;;;;save the selection (set! image-channel (car (gimp-selection-save image))) (gimp-drawable-set-name image-channel "image-channel") (gimp-image-set-active-layer image layer) ;;;;Add new layer with Bevel (if (= bev-type 0) (set! name "Inner bevel")) (if (= bev-type 1) (set! name "Outer bevel")) (gimp-selection-load image-channel) (gimp-image-set-active-layer image layer) (set! bevel-layer (car (gimp-layer-new image width height RGBA-IMAGE name 100 layer-mode))) (gimp-image-add-layer image bevel-layer -1) ;;;;make outer bevel visible (if (= bev-type 1) (gimp-layer-set-mode bevel-layer NORMAL-MODE)) ;need to make outer bevel visible for scrpit to work (gimp-image-set-active-layer image bevel-layer) (gimp-context-set-foreground '(0 0 0)) (gimp-context-set-background '(255 255 255)) (gimp-drawable-fill bevel-layer FOREGROUND-FILL) (gimp-selection-grow image 3) (gimp-selection-feather image bev-width) (if (= bev-type 0) (gimp-selection-shrink image (/ bev-width 2))) (if (= bev-type 1) (gimp-selection-grow image (- (/ bev-width 2) (/ bev-width 5)))) (gimp-edit-fill bevel-layer BACKGROUND-FILL) ;;;;apply shape curve (if (or (< shape 0) (> shape 0)) (begin (aset *newpoint* 0 0) ; set the arrays (aset *newpoint* 1 0) (aset *newpoint* 2 (round (+ (/ shape 10) 127))) (aset *newpoint* 3 (+ shape 127)) (aset *newpoint* 4 255) (aset *newpoint* 5 255) (gimp-curves-spline bevel-layer 0 6 *newpoint*) ) ) ;;;;apply the shape contours (if (> contour 0) (curves-contour bevel-layer 0 contour)) (gimp-selection-all image) ;;;;invert colours of whole layer if down (if (= bev-dir 1) (gimp-invert bevel-layer)) ;;;;add prenoise (if (> prenoise 0) (plug-in-hsv-noise 1 image bevel-layer 4 0 0 prenoise)) ;;;;emboss the selection (plug-in-emboss RUN-NONINTERACTIVE image bevel-layer light-angle light-elevation depth 1);Emboss ;;;;gloss the bevel-layer (if (> gloss 0) (begin (set! y1 (* 1.0 gloss)) (set! y2 (* 3.0 gloss)) (set! y3 (* 9.6 gloss)) (set! y4 (* 3.2 gloss)) (set! y5 (* 4.0 gloss)) (set! y6 (* 0.4 gloss)) (aset *newpointx1* 0 0) ; set the arrays (aset *newpointx1* 1 0) (aset *newpointx1* 2 63) (aset *newpointx1* 3 (+ 63 y1)) (aset *newpointx1* 4 95) (aset *newpointx1* 5 (+ 95 y2)) (aset *newpointx1* 6 127) (aset *newpointx1* 7 (- 127 y3)) (aset *newpointx1* 8 156) (aset *newpointx1* 9 (+ 156 y4)) (aset *newpointx1* 10 191) (aset *newpointx1* 11 (- 191 y5)) (aset *newpointx1* 12 223) (aset *newpointx1* 13 (+ 223 y6)) (aset *newpointx1* 14 255) (aset *newpointx1* 15 255) ;(0,0, 63,(63 + y1), 95,(95 + y2), 127,(127 - y3), 156,(156 + y4), 191,(191 - y5), 223,(223 + y6), 255,255) (gimp-curves-spline bevel-layer 0 16 *newpointx1*) ) ) ;;;;finish the layers (gimp-selection-load image-channel) (if (= bev-type 0) (begin (gimp-selection-shrink image (- bev-width (round (/ bev-width 3)))) (gimp-edit-clear bevel-layer))) (if (= bev-type 1) (begin (gimp-selection-grow image (+ bev-width 1)) (gimp-selection-invert image) (gimp-edit-clear layer) (gimp-edit-clear bevel-layer))) ;postblur (if (> postblur 0) (plug-in-gauss-rle2 RUN-NONINTERACTIVE image bevel-layer postblur postblur)) (gimp-layer-set-lock-alpha bevel-layer FALSE) ;reload selection (gimp-selection-load image-channel) ;clear excess (if (= bev-type 0) (begin (gimp-selection-shrink image 1) (gimp-selection-invert image) (gimp-edit-clear bevel-layer) (gimp-edit-clear layer) (gimp-selection-invert image))) (if (= bev-type 1) (begin (gimp-selection-shrink image 1) (gimp-edit-clear bevel-layer))) ;;;;Clean up the layers (if (= keep-selection FALSE) (gimp-selection-none image)) (gimp-image-remove-channel image image-channel) (if (= alpha FALSE) (gimp-layer-flatten layer)) (gimp-image-set-active-layer image bevel-layer) (if (= merge TRUE) (set! layer (car (gimp-image-merge-down image bevel-layer EXPAND-AS-NECESSARY)))) (gimp-drawable-set-name layer layer-name) (gimp-displays-flush) (gimp-image-undo-group-end image) (gimp-context-pop) ) ) (script-fu-register "script-fu-image-beveler" "Image Beveler..." "Can Bevel or Carve a selection or drawable with Alpha" "Graechan" "Graechan - http://gimpchat.com" "2011" "RGB*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0 SF-ENUM "LayerMode" '("LayerModeEffects" "hardlight-mode");18 SF-OPTION "Bevel Type" '("Inner Bevel(Hardlight-Mode)" "Outer Bevel(Normal-Mode)") SF-OPTION "Bevel direction" '("Up (Bevel)" "Down (Carve)") SF-ADJUSTMENT "Bevel Width" '(20 1 100 1 10 0 0) SF-ADJUSTMENT "Shape Curve" '(0 -127 128 1 10 0 0) SF-OPTION "Shape Contour" list-contours SF-ADJUSTMENT "Prenoise" '(0 0 25 1 1 0 0) SF-ADJUSTMENT "Light Angle" '(135 0 360 1 10 0 0) SF-ADJUSTMENT "Light Elevation" '(30 0 90 1 10 0 0) SF-ADJUSTMENT "Bevel Depth" '(3 1 60 1 10 0 0) SF-ADJUSTMENT "Post Emboss Blur" '(3 0 50 1 1 0 0) SF-ADJUSTMENT "Gloss" '(0 0 10 1 10 0 0) SF-TOGGLE "Keep selection" FALSE SF-TOGGLE "Merge Down" FALSE ) (script-fu-menu-register "script-fu-image-beveler" "/Filters/Decor")