Issue #360 - scripts that require brushes that GIMP no longer installs

carve-it.scm, chrome-it.scm: apply slightly modified patch from Carol
Spears which replaces hardcoding round brush names by creating a brush
on the fly and setting its radius.

Also fixed both scripts to not use deprecated color API which is
even completely gone from master.

(cherry picked from commit 3d049f565a)
This commit is contained in:
Michael Natterer 2019-07-14 13:59:11 +02:00
parent ab39b6acc7
commit 4bdb8792b5
2 changed files with 51 additions and 39 deletions

View file

@ -6,24 +6,15 @@
; This layer is used as the mask for the carving effect ; This layer is used as the mask for the carving effect
; NOTE: This script requires the image to be carved to either be an ; NOTE: This script requires the image to be carved to either be an
; RGB color or grayscale image with a single layer. An indexed file ; RGB color or grayscale image with a single layer. An indexed file
; can not be used due to the use of gimp-histogram and gimp-levels. ; can not be used due to the use of gimp-drawable-histogram and
; gimp-drawable-levels.
(define (carve-brush brush-size)
(cond ((<= brush-size 5) "Circle (05)")
((<= brush-size 7) "Circle (07)")
((<= brush-size 9) "Circle (09)")
((<= brush-size 11) "Circle (11)")
((<= brush-size 13) "Circle (13)")
((<= brush-size 15) "Circle (15)")
((<= brush-size 17) "Circle (17)")
(else "Circle (19)")))
(define (carve-scale val scale) (define (carve-scale val scale)
(* (sqrt val) scale)) (* (sqrt val) scale))
(define (calculate-inset-gamma img layer) (define (calculate-inset-gamma img layer)
(let* ((stats (gimp-histogram layer 0 0 255)) (let* ((stats (gimp-drawable-histogram layer 0 0.0 1.0))
(mean (car stats))) (mean (car stats)))
(cond ((< mean 127) (+ 1.0 (* 0.5 (/ (- 127 mean) 127.0)))) (cond ((< mean 127) (+ 1.0 (* 0.5 (/ (- 127 mean) 127.0))))
((>= mean 127) (- 1.0 (* 0.5 (/ (- mean 127) 127.0))))))) ((>= mean 127) (- 1.0 (* 0.5 (/ (- mean 127) 127.0)))))))
@ -56,6 +47,7 @@
(offy (carve-scale size 0.25)) (offy (carve-scale size 0.25))
(feather (carve-scale size 0.3)) (feather (carve-scale size 0.3))
(brush-size (carve-scale size 0.3)) (brush-size (carve-scale size 0.3))
(brush-name (car (gimp-brush-new "Carve It")))
(mask-fs 0) (mask-fs 0)
(mask (car (gimp-channel-new img width height "Engraving Mask" 50 '(0 0 0)))) (mask (car (gimp-channel-new img width height "Engraving Mask" 50 '(0 0 0))))
(inset-gamma (calculate-inset-gamma (car (gimp-item-get-image bg-layer)) bg-layer)) (inset-gamma (calculate-inset-gamma (car (gimp-item-get-image bg-layer)) bg-layer))
@ -100,7 +92,17 @@
(set! mask-fat (car (gimp-channel-copy mask))) (set! mask-fat (car (gimp-channel-copy mask)))
(gimp-image-insert-channel img mask-fat -1 0) (gimp-image-insert-channel img mask-fat -1 0)
(gimp-image-select-item img CHANNEL-OP-REPLACE mask-fat) (gimp-image-select-item img CHANNEL-OP-REPLACE mask-fat)
(gimp-context-set-brush (carve-brush brush-size))
(gimp-brush-set-shape brush-name BRUSH-GENERATED-CIRCLE)
(gimp-brush-set-spikes brush-name 2)
(gimp-brush-set-hardness brush-name 1.0)
(gimp-brush-set-spacing brush-name 25)
(gimp-brush-set-aspect-ratio brush-name 1)
(gimp-brush-set-angle brush-name 0)
(cond (<= brush-size 17) (gimp-brush-set-radius brush-name (\ brush-size 2))
(else gimp-brush-set-radius brush-name (\ 19 2)))
(gimp-context-set-brush brush-name)
(gimp-context-set-foreground '(255 255 255)) (gimp-context-set-foreground '(255 255 255))
(gimp-drawable-edit-stroke-selection mask-fat) (gimp-drawable-edit-stroke-selection mask-fat)
(gimp-selection-none img) (gimp-selection-none img)
@ -120,10 +122,16 @@
(set! mask-highlight (car (gimp-channel-copy mask-emboss))) (set! mask-highlight (car (gimp-channel-copy mask-emboss)))
(gimp-image-insert-channel img mask-highlight -1 0) (gimp-image-insert-channel img mask-highlight -1 0)
(gimp-levels mask-highlight 0 180 255 1.0 0 255) (gimp-drawable-levels mask-highlight 0
0.7056 1.0 TRUE
1.0
0.0 1.0 TRUE)
(set! mask-shadow mask-emboss) (set! mask-shadow mask-emboss)
(gimp-levels mask-shadow 0 0 180 1.0 0 255) (gimp-drawable-levels mask-shadow 0
0.0 0.70586 TRUE
1.0
0.0 1.0 TRUE)
(gimp-edit-copy mask-shadow) (gimp-edit-copy mask-shadow)
(set! shadow-layer (car (gimp-edit-paste layer1 FALSE))) (set! shadow-layer (car (gimp-edit-paste layer1 FALSE)))
@ -159,7 +167,7 @@
(gimp-drawable-edit-fill il-mask FILL-BACKGROUND) (gimp-drawable-edit-fill il-mask FILL-BACKGROUND)
(gimp-selection-none img) (gimp-selection-none img)
(gimp-selection-none bg-image) (gimp-selection-none bg-image)
(gimp-levels inset-layer 0 0 255 inset-gamma 0 255) (gimp-drawable-levels inset-layer 0 0.0 1.0 TRUE inset-gamma 0.0 1.0 TRUE)
(gimp-image-remove-channel img mask) (gimp-image-remove-channel img mask)
(gimp-image-remove-channel img mask-fat) (gimp-image-remove-channel img mask-fat)
(gimp-image-remove-channel img mask-highlight) (gimp-image-remove-channel img mask-highlight)
@ -171,6 +179,8 @@
(gimp-item-set-name cast-shadow-layer _"Cast Shadow") (gimp-item-set-name cast-shadow-layer _"Cast Shadow")
(gimp-item-set-name inset-layer _"Inset") (gimp-item-set-name inset-layer _"Inset")
(gimp-brush-delete brush-name)
(gimp-display-new img) (gimp-display-new img)
(gimp-image-undo-enable img) (gimp-image-undo-enable img)

View file

@ -14,31 +14,20 @@
) )
(define (spline-chrome-it) (define (spline-chrome-it)
(let* ((a (cons-array 18 'byte))) (let* ((a (cons-array 18 'double)))
(set-pt a 0 0 0) (set-pt a 0 0.0 0.0)
(set-pt a 1 31 235) (set-pt a 1 0.125 0.9216)
(set-pt a 2 63 23) (set-pt a 2 0.25 0.0902)
(set-pt a 3 95 230) (set-pt a 3 0.375 0.9020)
(set-pt a 4 127 25) (set-pt a 4 0.5 0.0989)
(set-pt a 5 159 210) (set-pt a 5 0.625 0.9549)
(set-pt a 6 191 20) (set-pt a 6 0.75 00784)
(set-pt a 7 223 240) (set-pt a 7 0.875 0.9412)
(set-pt a 8 255 31) (set-pt a 8 1.0 0.1216)
a a
) )
) )
(define (brush brush-size)
(cond ((<= brush-size 5) "Circle Fuzzy (05)")
((<= brush-size 7) "Circle Fuzzy (07)")
((<= brush-size 9) "Circle Fuzzy (09)")
((<= brush-size 11) "Circle Fuzzy (11)")
((<= brush-size 13) "Circle Fuzzy (13)")
((<= brush-size 15) "Circle Fuzzy (15)")
((<= brush-size 17) "Circle Fuzzy (17)")
(else "Circle Fuzzy (19)")
)
)
(define (shadows val) (define (shadows val)
(/ (* 0.96 val) 2.55) (/ (* 0.96 val) 2.55)
@ -99,6 +88,7 @@
(offy2 (sota-scale size (- 0.25) chrome-factor)) (offy2 (sota-scale size (- 0.25) chrome-factor))
(feather (sota-scale size 0.5 chrome-factor)) (feather (sota-scale size 0.5 chrome-factor))
(brush-size (sota-scale size 0.5 chrome-factor)) (brush-size (sota-scale size 0.5 chrome-factor))
(brush-name (car (gimp-brush-new "Chrome It")))
(mask (car (gimp-channel-new img width height "Chrome Stencil" 50 '(0 0 0)))) (mask (car (gimp-channel-new img width height "Chrome Stencil" 50 '(0 0 0))))
(bg-layer (car (gimp-layer-new img width height GRAY-IMAGE _"Background" 100 LAYER-MODE-NORMAL))) (bg-layer (car (gimp-layer-new img width height GRAY-IMAGE _"Background" 100 LAYER-MODE-NORMAL)))
(layer1 (car (gimp-layer-new img banding-width banding-height banding-type _"Layer 1" 100 LAYER-MODE-NORMAL))) (layer1 (car (gimp-layer-new img banding-width banding-height banding-type _"Layer 1" 100 LAYER-MODE-NORMAL)))
@ -154,7 +144,7 @@
(plug-in-gauss-iir RUN-NONINTERACTIVE img layer1 10 TRUE TRUE) (plug-in-gauss-iir RUN-NONINTERACTIVE img layer1 10 TRUE TRUE)
(gimp-layer-set-opacity layer1 50) (gimp-layer-set-opacity layer1 50)
(set! layer1 (car (gimp-image-merge-visible-layers img CLIP-TO-IMAGE))) (set! layer1 (car (gimp-image-merge-visible-layers img CLIP-TO-IMAGE)))
(gimp-curves-spline layer1 HISTOGRAM-VALUE 18 (spline-chrome-it)) (gimp-drawable-curves-spline layer1 HISTOGRAM-VALUE 18 (spline-chrome-it))
(set! layer-mask (car (gimp-layer-create-mask layer1 ADD-MASK-BLACK))) (set! layer-mask (car (gimp-layer-create-mask layer1 ADD-MASK-BLACK)))
(gimp-layer-add-mask layer1 layer-mask) (gimp-layer-add-mask layer1 layer-mask)
@ -164,7 +154,17 @@
(set! layer2 (car (gimp-layer-copy layer1 TRUE))) (set! layer2 (car (gimp-layer-copy layer1 TRUE)))
(gimp-image-insert-layer img layer2 0 0) (gimp-image-insert-layer img layer2 0 0)
(gimp-context-set-brush (brush brush-size))
(gimp-brush-set-shape brush-name BRUSH-GENERATED-CIRCLE)
(gimp-brush-set-spikes brush-name 2)
(gimp-brush-set-hardness brush-name 1.0)
(gimp-brush-set-spacing brush-name 25)
(gimp-brush-set-aspect-ratio brush-name 1)
(gimp-brush-set-angle brush-name 0)
(cond (<= brush-size 17) (gimp-brush-set-radius brush-name (\ brush-size 2))
(else gimp-brush-set-radius brush-name (\ 19 2)))
(gimp-context-set-brush brush-name)
(gimp-context-set-foreground '(255 255 255)) (gimp-context-set-foreground '(255 255 255))
(gimp-drawable-edit-stroke-selection layer-mask) (gimp-drawable-edit-stroke-selection layer-mask)
@ -219,6 +219,8 @@
(gimp-image-remove-channel img mask) (gimp-image-remove-channel img mask)
(gimp-brush-delete brush-name)
(gimp-display-new img) (gimp-display-new img)
(gimp-image-undo-enable img) (gimp-image-undo-enable img)