Anchoring a layer in script-fu
This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
Anchoring a layer in script-fu | Dave 77459 | 21 Oct 18:20 |
Anchoring a layer in script-fu
I am automating a "LAB Enhancement" process. It is found here:
http://www.dslreports.com/forum/remark,15173919
In short, you decompose to LAB. You monkey with the A and B channels, then use curves on L. Finally, you recompose.
One issue is that you have to copy the resulting A1 and B1 channels, and then anchor them back into the original A and B channels so that you can recompose. Merging down into A or B apparently creates new layers and you lose the ability to recompose.
The attached script for version 2.6.2 gets to the last step that I am going to (I'm stopping before applying curves to the L channel because I'll do that manually depending on the image). I create the altered A1 and B1 channels. I paste B1 and anchor it into B.
However, when I paste A1, it is anchoring into B, instead of A. A is the top layer, but I can't get the script to anchor into it. When I anchor manually, it also anchors into B. I'm frustrated and mystified in equal measure.
Another side effect is that running this script wipes out the filters, and I have to refresh them. :-(
Can any Script-fu wizards out there tell me what I am doing wrong?
Dave
---- script follows and is attached ----
; LAB Enhance
; David Hathaway
;
; Based on:
;
; http://www.dslreports.com/forum/remark,15173919
;
; v 0.5 - 21 OCT 2009 (first working version)
(define (LAB-Enhance img
drawable)
(gimp-image-undo-group-start img)
; set some system variables
(let*
(
(width (car (gimp-image-width img)))
(height (car (gimp-image-height img)))
(blend-layer)
(b-copy1-layer)
(b-copy2-layer)
(a-copy1-layer)
(a-copy2-layer)
(layers (gimp-image-get-layers img))
(B1)
(B2)
(B3)
(editcopy)
(A1)
(A2)
(A3)
)
; copy A channel and add as second layer
(set! A1 (car (gimp-layer-new-from-drawable (
aref (cadr layers) 1)
img)))
(gimp-drawable-set-name A1 "A 1")
(gimp-image-add-layer img A1 1)
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; copy B channel and set as 4th layer (set! B1 (car (gimp-layer-new-from-drawable ( aref (cadr layers) 2) img)))
(gimp-drawable-set-name B1 "B 1") (gimp-image-add-layer img B1 3)
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; copy the B channel copy and make overlay, inserting as 4th layer (set! B2 (car (gimp-layer-new-from-drawable ( aref (cadr layers) 2) img)))
(gimp-drawable-set-name B2 "B 2") (gimp-layer-set-mode B2 OVERLAY-MODE) (gimp-image-add-layer img B2 3)
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; merge new B channels (set! B3 (gimp-image-merge-down img B2 EXPAND-AS-NECESSARY))
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; copy the A channel copy and make overlay, inserting as 2nd layer (set! A2 (car (gimp-layer-new-from-drawable ( aref (cadr layers) 1) img)))
(gimp-drawable-set-name A2 "A 2") (gimp-layer-set-mode A2 OVERLAY-MODE) (gimp-image-add-layer img A2 1)
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; merge new B channels (set! A3 (gimp-image-merge-down img A2 EXPAND-AS-NECESSARY))
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; move B to top (gimp-image-raise-layer-to-top img (aref (cadr layers) 2))
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; cut B1, paste into layer, and anchor
(gimp-image-set-active-layer img (aref (cadr (gimp-image-get-layers img))
4))
(gimp-selection-all img)
(gimp-edit-cut (aref (cadr (gimp-image-get-layers img)) 4))
(gimp-image-set-active-layer img (aref (cadr (gimp-image-get-layers img))
0))
(gimp-floating-sel-anchor (car (gimp-edit-paste drawable TRUE)))
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; move A to top (gimp-image-raise-layer-to-top img (aref (cadr layers) 1)) (gimp-image-set-active-layer img (aref (cadr layers) 1))
(gimp-image-undo-group-end img) (gimp-image-undo-group-start img)
; cut A1, paste into layer, and anchor
(gimp-image-set-active-layer img (aref (cadr (gimp-image-get-layers img))
3))
(gimp-selection-all img)
(gimp-edit-cut (aref (cadr (gimp-image-get-layers img)) 3))
(gimp-image-set-active-layer img (aref (cadr (gimp-image-get-layers img))
0))
(gimp-edit-paste drawable TRUE)
; (gimp-floating-sel-anchor (car (gimp-edit-paste drawable TRUE)))
; move L back to top ; (gimp-image-raise-layer-to-top img (aref (cadr layers) 0)) ; (gimp-image-set-active-layer img (aref (cadr (gimp-image-get-layers img)) 0))
) ; let*
; Flush the display
(gimp-image-undo-group-end img)
(gimp-displays-flush)
)
(script-fu-register "LAB-Enhance"
"LAB-Enhance"
"Perform LAB Enhancement"
"David Hathaway "
"(c) David Hathaway"
"2009 10 21"
"GRAYSCALE*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Layer to start on (unused)" 0)
(script-fu-menu-register "LAB-Enhance"
"/Filters/Dave77459")