1997-11-24 22:05:25 +00:00
|
|
|
; CHROME-IT
|
|
|
|
; State of the art chrome effect for user-specified mask
|
|
|
|
; This script requires a grayscale image containing a single layer.
|
|
|
|
; This layer is used as the mask for the SOTA chrome effect
|
|
|
|
|
|
|
|
(define (script-fu-sota-chrome-it mask-img mask-drawable chrome-saturation
|
2006-10-16 01:08:54 +00:00
|
|
|
chrome-lightness chrome-factor env-map hc cc carve-white)
|
|
|
|
|
|
|
|
(define (set-pt a index x y)
|
|
|
|
(begin
|
|
|
|
(aset a (* index 2) x)
|
|
|
|
(aset a (+ (* index 2) 1) y)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define (spline-chrome-it)
|
2019-07-14 13:59:11 +02:00
|
|
|
(let* ((a (cons-array 18 'double)))
|
|
|
|
(set-pt a 0 0.0 0.0)
|
|
|
|
(set-pt a 1 0.125 0.9216)
|
|
|
|
(set-pt a 2 0.25 0.0902)
|
|
|
|
(set-pt a 3 0.375 0.9020)
|
|
|
|
(set-pt a 4 0.5 0.0989)
|
|
|
|
(set-pt a 5 0.625 0.9549)
|
|
|
|
(set-pt a 6 0.75 00784)
|
|
|
|
(set-pt a 7 0.875 0.9412)
|
|
|
|
(set-pt a 8 1.0 0.1216)
|
2006-10-16 01:08:54 +00:00
|
|
|
a
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
(define (shadows val)
|
|
|
|
(/ (* 0.96 val) 2.55)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define (midtones val)
|
|
|
|
(/ val 2.55)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define (highlights val)
|
2018-04-26 15:45:04 +02:00
|
|
|
; The result is used as "gimp-drawable-color-balance" color parameter
|
2010-07-21 12:55:48 +02:00
|
|
|
; and thus must be restricted to -100.0 <= highlights <= 100.0.
|
|
|
|
(min (/ (* 1.108 val) 2.55) 100.0)
|
2006-10-16 01:08:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
(define (rval col)
|
|
|
|
(car col)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define (gval col)
|
|
|
|
(cadr col)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define (bval col)
|
|
|
|
(caddr col)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define (sota-scale val scale chrome-factor)
|
|
|
|
(* (sqrt val) (* scale chrome-factor))
|
|
|
|
)
|
|
|
|
|
|
|
|
(define (copy-layer-chrome-it dest-image dest-drawable source-image source-drawable)
|
|
|
|
(gimp-selection-all dest-image)
|
2018-04-16 20:12:12 +02:00
|
|
|
(gimp-drawable-edit-clear dest-drawable)
|
2006-10-16 01:08:54 +00:00
|
|
|
(gimp-selection-none dest-image)
|
|
|
|
(gimp-selection-all source-image)
|
Fix #6026, SF scripts use v3 API for multilayer gimp-edit-copy, -cut, -paste.
Why: in v3 the signature for gimp-edit-foo PDB procedures changed to support multilayer selection.
This finishes the task for ScriptFu scripts in the GIMP repo.
This is not a complete list, since some calls were changed incidentally by prior commits.
You can grep for "edit-copy" etc. in script-fu/scripts to find instances.
This also makes incidental changes, to script calls to plug-in-tile,
which now also has a changed signature to support multilayer.
The changes are simple code transformations.
The changes to gimp-edit-paste calls are more complex,
a mixed bag of a few lines transformed to more lines.
I did not try to understand the larger logic of the changed plugins.
I did not test the changed plugins functionally.
I used a harness to call each changed plugin with improvised parameters,
only checking that the test plugin did not throw runtime errors,
not checking that they produced correct images.
As noted in the issue, this might be undone if the original signatures
for gimp-edit-foo are restored as convenience functions.
2022-05-06 16:40:19 -04:00
|
|
|
(gimp-edit-copy 1 (vector source-drawable))
|
|
|
|
(let* (
|
|
|
|
(pasted (gimp-edit-paste dest-drawable FALSE))
|
|
|
|
(num-pasted (car pasted))
|
|
|
|
(floating-sel (aref (cadr pasted) (- num-pasted 1)))
|
|
|
|
)
|
|
|
|
(gimp-floating-sel-anchor floating-sel)
|
2006-10-16 01:08:54 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(let* (
|
2021-05-13 09:09:26 -04:00
|
|
|
(banding-img (car (gimp-file-load RUN-NONINTERACTIVE env-map)))
|
2022-08-02 16:40:08 -04:00
|
|
|
(banding-layer (aref (cadr (gimp-image-get-selected-drawables banding-img)) 0))
|
2021-04-20 17:47:11 +02:00
|
|
|
(banding-height (car (gimp-drawable-get-height banding-layer)))
|
|
|
|
(banding-width (car (gimp-drawable-get-width banding-layer)))
|
2006-10-16 01:08:54 +00:00
|
|
|
(banding-type (car (gimp-drawable-type banding-layer)))
|
2021-04-20 17:47:11 +02:00
|
|
|
(width (car (gimp-drawable-get-width mask-drawable)))
|
|
|
|
(height (car (gimp-drawable-get-height mask-drawable)))
|
2006-10-16 01:08:54 +00:00
|
|
|
(img (car (gimp-image-new width height GRAY)))
|
|
|
|
(size (min width height))
|
|
|
|
(offx1 (sota-scale size 0.33 chrome-factor))
|
|
|
|
(offy1 (sota-scale size 0.25 chrome-factor))
|
|
|
|
(offx2 (sota-scale size (- 0.33) chrome-factor))
|
|
|
|
(offy2 (sota-scale size (- 0.25) chrome-factor))
|
|
|
|
(feather (sota-scale size 0.5 chrome-factor))
|
|
|
|
(brush-size (sota-scale size 0.5 chrome-factor))
|
2023-12-09 11:02:10 -05:00
|
|
|
(brush (car (gimp-brush-new "Chrome It")))
|
2006-10-16 01:08:54 +00:00
|
|
|
(mask (car (gimp-channel-new img width height "Chrome Stencil" 50 '(0 0 0))))
|
2017-01-09 20:37:30 +01:00
|
|
|
(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)))
|
|
|
|
(layer2 (car (gimp-layer-new img width height GRAYA-IMAGE _"Layer 2" 100 LAYER-MODE-DIFFERENCE)))
|
|
|
|
(layer3 (car (gimp-layer-new img width height GRAYA-IMAGE _"Layer 3" 100 LAYER-MODE-NORMAL)))
|
|
|
|
(shadow (car (gimp-layer-new img width height GRAYA-IMAGE _"Drop Shadow" 100 LAYER-MODE-NORMAL)))
|
2006-10-16 01:08:54 +00:00
|
|
|
(layer-mask 0)
|
2023-12-09 11:02:10 -05:00
|
|
|
(marble-pattern (car (gimp-pattern-get-by-name "Marble #1")))
|
2006-10-16 01:08:54 +00:00
|
|
|
)
|
2004-09-22 17:27:20 +00:00
|
|
|
|
|
|
|
(gimp-context-push)
|
2011-11-09 02:42:34 -05:00
|
|
|
(gimp-context-set-defaults)
|
2004-09-22 17:27:20 +00:00
|
|
|
|
1999-10-17 00:07:55 +00:00
|
|
|
(gimp-image-undo-disable img)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2010-09-28 09:10:07 +04:00
|
|
|
(gimp-image-insert-channel img mask -1 0)
|
2011-03-02 02:55:43 -05:00
|
|
|
(gimp-image-insert-layer img bg-layer 0 0)
|
|
|
|
(gimp-image-insert-layer img shadow 0 0)
|
|
|
|
(gimp-image-insert-layer img layer3 0 0)
|
|
|
|
(gimp-image-insert-layer img layer2 0 0)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
Fix #6026, SF scripts use v3 API for multilayer gimp-edit-copy, -cut, -paste.
Why: in v3 the signature for gimp-edit-foo PDB procedures changed to support multilayer selection.
This finishes the task for ScriptFu scripts in the GIMP repo.
This is not a complete list, since some calls were changed incidentally by prior commits.
You can grep for "edit-copy" etc. in script-fu/scripts to find instances.
This also makes incidental changes, to script calls to plug-in-tile,
which now also has a changed signature to support multilayer.
The changes are simple code transformations.
The changes to gimp-edit-paste calls are more complex,
a mixed bag of a few lines transformed to more lines.
I did not try to understand the larger logic of the changed plugins.
I did not test the changed plugins functionally.
I used a harness to call each changed plugin with improvised parameters,
only checking that the test plugin did not throw runtime errors,
not checking that they produced correct images.
As noted in the issue, this might be undone if the original signatures
for gimp-edit-foo are restored as convenience functions.
2022-05-06 16:40:19 -04:00
|
|
|
(gimp-edit-copy 1 (vector mask-drawable))
|
|
|
|
|
|
|
|
; Clipboard is copy of mask-drawable. Paste into mask, a channel, and anchor it.
|
|
|
|
(let* (
|
|
|
|
(pasted (gimp-edit-paste mask FALSE))
|
|
|
|
(num-pasted (car pasted))
|
|
|
|
(floating-sel (aref (cadr pasted) (- num-pasted 1)))
|
|
|
|
)
|
|
|
|
(gimp-floating-sel-anchor floating-sel)
|
|
|
|
)
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
(if (= carve-white FALSE)
|
2017-09-03 21:28:47 +02:00
|
|
|
(gimp-drawable-invert mask FALSE)
|
2006-10-16 01:08:54 +00:00
|
|
|
)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2004-09-22 18:43:09 +00:00
|
|
|
(gimp-context-set-background '(255 255 255))
|
1997-11-24 22:05:25 +00:00
|
|
|
(gimp-selection-none img)
|
2018-04-16 20:12:12 +02:00
|
|
|
(gimp-drawable-edit-fill layer2 FILL-BACKGROUND)
|
|
|
|
(gimp-drawable-edit-fill layer3 FILL-BACKGROUND)
|
|
|
|
(gimp-drawable-edit-clear shadow)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2010-08-03 00:13:51 +03:00
|
|
|
(gimp-item-set-visible bg-layer FALSE)
|
|
|
|
(gimp-item-set-visible shadow FALSE)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2011-02-21 00:07:19 +02:00
|
|
|
(gimp-image-select-item img CHANNEL-OP-REPLACE mask)
|
2004-09-22 18:43:09 +00:00
|
|
|
(gimp-context-set-background '(0 0 0))
|
1997-11-24 22:05:25 +00:00
|
|
|
(gimp-selection-translate img offx1 offy1)
|
|
|
|
(gimp-selection-feather img feather)
|
2018-04-16 20:12:12 +02:00
|
|
|
(gimp-drawable-edit-fill layer2 FILL-BACKGROUND)
|
1997-11-24 22:05:25 +00:00
|
|
|
(gimp-selection-translate img (* 2 offx2) (* 2 offy2))
|
2018-04-16 20:12:12 +02:00
|
|
|
(gimp-drawable-edit-fill layer3 FILL-BACKGROUND)
|
1997-11-24 22:05:25 +00:00
|
|
|
(gimp-selection-none img)
|
|
|
|
(set! layer2 (car (gimp-image-merge-visible-layers img CLIP-TO-IMAGE)))
|
2017-09-03 21:28:47 +02:00
|
|
|
(gimp-drawable-invert layer2 FALSE)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2011-03-02 02:55:43 -05:00
|
|
|
(gimp-image-insert-layer img layer1 0 0)
|
1997-11-24 22:05:25 +00:00
|
|
|
(copy-layer-chrome-it img layer1 banding-img banding-layer)
|
|
|
|
(gimp-image-delete banding-img)
|
|
|
|
(gimp-layer-scale layer1 width height FALSE)
|
2007-10-01 19:44:23 +00:00
|
|
|
(plug-in-gauss-iir RUN-NONINTERACTIVE img layer1 10 TRUE TRUE)
|
1997-11-24 22:05:25 +00:00
|
|
|
(gimp-layer-set-opacity layer1 50)
|
|
|
|
(set! layer1 (car (gimp-image-merge-visible-layers img CLIP-TO-IMAGE)))
|
2019-07-14 13:59:11 +02:00
|
|
|
(gimp-drawable-curves-spline layer1 HISTOGRAM-VALUE 18 (spline-chrome-it))
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2017-01-09 20:37:30 +01:00
|
|
|
(set! layer-mask (car (gimp-layer-create-mask layer1 ADD-MASK-BLACK)))
|
2003-12-08 22:33:17 +00:00
|
|
|
(gimp-layer-add-mask layer1 layer-mask)
|
2011-02-21 00:07:19 +02:00
|
|
|
(gimp-image-select-item img CHANNEL-OP-REPLACE mask)
|
2004-09-22 18:43:09 +00:00
|
|
|
(gimp-context-set-background '(255 255 255))
|
2018-04-16 20:12:12 +02:00
|
|
|
(gimp-drawable-edit-fill layer-mask FILL-BACKGROUND)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
(set! layer2 (car (gimp-layer-copy layer1 TRUE)))
|
2011-03-02 02:55:43 -05:00
|
|
|
(gimp-image-insert-layer img layer2 0 0)
|
2019-07-14 13:59:11 +02:00
|
|
|
|
2023-12-09 11:02:10 -05:00
|
|
|
(gimp-brush-set-shape brush BRUSH-GENERATED-CIRCLE)
|
|
|
|
(gimp-brush-set-spikes brush 2)
|
|
|
|
(gimp-brush-set-hardness brush 1.0)
|
|
|
|
(gimp-brush-set-spacing brush 25)
|
|
|
|
(gimp-brush-set-aspect-ratio brush 1)
|
|
|
|
(gimp-brush-set-angle brush 0)
|
|
|
|
(cond (<= brush-size 17) (gimp-brush-set-radius brush (\ brush-size 2))
|
|
|
|
(else gimp-brush-set-radius brush (\ 19 2)))
|
|
|
|
(gimp-context-set-brush brush)
|
2019-07-14 13:59:11 +02:00
|
|
|
|
2004-09-22 18:43:09 +00:00
|
|
|
(gimp-context-set-foreground '(255 255 255))
|
2018-04-16 20:12:12 +02:00
|
|
|
(gimp-drawable-edit-stroke-selection layer-mask)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2004-09-22 18:43:09 +00:00
|
|
|
(gimp-context-set-background '(0 0 0))
|
1997-11-24 22:05:25 +00:00
|
|
|
(gimp-selection-feather img (* feather 1.5))
|
|
|
|
(gimp-selection-translate img (* 2.5 offx1) (* 2.5 offy1))
|
2018-04-16 20:12:12 +02:00
|
|
|
(gimp-drawable-edit-fill shadow FILL-BACKGROUND)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
(gimp-selection-all img)
|
2023-12-09 11:02:10 -05:00
|
|
|
(gimp-context-set-pattern marble-pattern)
|
2018-04-16 20:12:12 +02:00
|
|
|
(gimp-drawable-edit-fill bg-layer FILL-PATTERN)
|
1997-11-24 22:05:25 +00:00
|
|
|
(gimp-selection-none img)
|
|
|
|
|
2003-12-04 14:52:49 +00:00
|
|
|
(gimp-image-convert-rgb img)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2018-04-26 15:45:04 +02:00
|
|
|
(gimp-drawable-color-balance layer1 TRANSFER-SHADOWS TRUE
|
|
|
|
(shadows (rval hc))
|
|
|
|
(shadows (gval hc))
|
|
|
|
(shadows (bval hc)))
|
|
|
|
(gimp-drawable-color-balance layer1 TRANSFER-MIDTONES TRUE
|
|
|
|
(midtones (rval hc))
|
|
|
|
(midtones (gval hc))
|
|
|
|
(midtones (bval hc)))
|
|
|
|
(gimp-drawable-color-balance layer1 TRANSFER-HIGHLIGHTS TRUE
|
|
|
|
(highlights (rval hc))
|
|
|
|
(highlights (gval hc))
|
|
|
|
(highlights (bval hc)))
|
|
|
|
|
|
|
|
(gimp-drawable-color-balance layer2 TRANSFER-SHADOWS TRUE
|
|
|
|
(shadows (rval cc))
|
|
|
|
(shadows (gval cc))
|
|
|
|
(shadows (bval cc)))
|
|
|
|
(gimp-drawable-color-balance layer2 TRANSFER-MIDTONES TRUE
|
|
|
|
(midtones (rval cc))
|
|
|
|
(midtones (gval cc))
|
|
|
|
(midtones (bval cc)))
|
|
|
|
(gimp-drawable-color-balance layer2 TRANSFER-HIGHLIGHTS TRUE
|
|
|
|
(highlights (rval cc))
|
|
|
|
(highlights (gval cc))
|
|
|
|
(highlights (bval cc)))
|
|
|
|
(gimp-drawable-hue-saturation layer2 HUE-RANGE-ALL
|
|
|
|
0.0
|
|
|
|
chrome-lightness
|
|
|
|
chrome-saturation
|
|
|
|
0.0)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2010-08-03 00:13:51 +03:00
|
|
|
(gimp-item-set-visible shadow TRUE)
|
|
|
|
(gimp-item-set-visible bg-layer TRUE)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2010-10-10 03:41:21 +04:00
|
|
|
(gimp-item-set-name layer2 _"Chrome")
|
|
|
|
(gimp-item-set-name layer1 _"Highlight")
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
(gimp-image-remove-channel img mask)
|
|
|
|
|
2023-12-09 11:02:10 -05:00
|
|
|
(gimp-resource-delete brush)
|
2019-07-14 13:59:11 +02:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
(gimp-display-new img)
|
2004-09-22 17:27:20 +00:00
|
|
|
(gimp-image-undo-enable img)
|
|
|
|
|
2006-10-16 01:08:54 +00:00
|
|
|
(gimp-context-pop)
|
|
|
|
)
|
|
|
|
)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
(script-fu-register "script-fu-sota-chrome-it"
|
2006-10-16 01:08:54 +00:00
|
|
|
_"Stencil C_hrome..."
|
|
|
|
_"Add a chrome effect to the selected region (or alpha) using a specified (grayscale) stencil"
|
|
|
|
"Spencer Kimball"
|
|
|
|
"Spencer Kimball"
|
|
|
|
"1997"
|
2006-10-20 17:55:14 +00:00
|
|
|
"GRAY"
|
|
|
|
SF-IMAGE "Chrome image" 0
|
|
|
|
SF-DRAWABLE "Chrome mask" 0
|
2006-10-16 01:08:54 +00:00
|
|
|
SF-ADJUSTMENT _"Chrome saturation" '(-80 -100 100 1 10 0 0)
|
2006-10-20 17:55:14 +00:00
|
|
|
SF-ADJUSTMENT _"Chrome lightness" '(-47 -100 100 1 10 0 0)
|
2022-08-02 16:40:08 -04:00
|
|
|
SF-ADJUSTMENT _"Chrome factor" '(0.75 0 1 0.1 0.2 2 0)
|
2006-10-16 01:08:54 +00:00
|
|
|
SF-FILENAME _"Environment map"
|
2006-10-20 17:55:14 +00:00
|
|
|
(string-append gimp-data-directory
|
|
|
|
"/scripts/images/beavis.jpg")
|
|
|
|
SF-COLOR _"Highlight balance" '(211 95 0)
|
|
|
|
SF-COLOR _"Chrome balance" "black"
|
2006-10-16 01:08:54 +00:00
|
|
|
SF-TOGGLE _"Chrome white areas" TRUE
|
|
|
|
)
|
2004-11-18 22:44:28 +00:00
|
|
|
|
|
|
|
(script-fu-menu-register "script-fu-sota-chrome-it"
|
2006-10-16 01:08:54 +00:00
|
|
|
"<Image>/Filters/Decor")
|