;; pandora-combine.scm: Move layers around to make a panorama. ;; Copyright (C) 2006 by Akkana Peck, akkana@shallowsky.com. ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License. ;; Pandora Combine: ;; Start by opening all the images of your panorama as separate ;; layers in a single image, with the bottom layer being the leftmost. ;; Then run pandora-combine on that image. (define (script-fu-pandora-combine img drawable overlap use-mask) ;; Calculate the size for the new image (let* ((layers (gimp-image-get-layers img)) (num-layers (car layers)) (layer-array (cadr layers)) (firstlayer (aref layer-array (- num-layers 1))) ; Pandora assumes that all layers are the same size as the first: ; XXX change this eventually. (layer-w (car (gimp-drawable-width firstlayer))) (layer-h (car (gimp-drawable-height firstlayer))) (overlap-frac (/ overlap 100)) (hslop (/ layer-w 2)) (vslop hslop) (pan-img-w (* layer-w (+ 1 (* (- num-layers .3) (- 1 overlap-frac))))) (pan-img-h (+ layer-h vslop)) (newy (/ vslop 2)) (i 1)) ;(gimp-message (number->string pan-img-w)) (gimp-image-undo-group-start img) (gimp-image-resize img pan-img-w pan-img-h 0 0) ;; Loop over the layers starting with the second, moving each one: (gimp-layer-translate firstlayer 0 newy) (gimp-context-push) (while (< i num-layers) (let* ((thislayer (aref layer-array (- (- num-layers i) 1))) (thislayer-w (car (gimp-drawable-width thislayer))) (newx (* i (* thislayer-w (- 1 overlap-frac)))) ) (gimp-layer-translate thislayer newx newy) (if use-mask (let ((masklayer (car (gimp-layer-create-mask thislayer ADD-BLACK-MASK))) (grad-w (* (* layer-w overlap-frac) .5)) ) (gimp-layer-add-alpha thislayer) (gimp-layer-add-mask thislayer masklayer) (gimp-context-set-foreground '(255 255 255)) (gimp-context-set-background '(0 0 0)) (gimp-edit-blend masklayer FG-BG-RGB-MODE NORMAL-MODE GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE FALSE 0 0 TRUE grad-w 0 0 0) (gimp-layer-set-edit-mask thislayer FALSE) )) ) (set! i (+ i 1)) ) (gimp-context-pop) (gimp-image-undo-group-end img) (gimp-displays-flush) ) ) (script-fu-register "script-fu-pandora-combine" _"/Filters/Combine/Arrange as Panorama..." "Line up layers as a panorama" "Akkana Peck" "Akkana Peck" "March 2006" "*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-ADJUSTMENT _"Overlap (percent)" '(30 0 100 1 10 0 1) SF-TOGGLE _"Use Layer Masks" TRUE )