; selection_grow_directional.scm ; by Rob Antonishen ; http://ffaat.pointclark.net ; Version 1.1 (20090716) ; Changes: ; 1.1 using new image to avoid the flickering of the layers dialog. ; made grow code generic to eliminate duplication ; added new menu registers for 10 pixel grows. ; Description ; Grows the selection orthagonally by one pixel ; License: ; ; 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 2 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. ; ; The GNU Public License is available at ; http://www.gnu.org/copyleft/gpl.html (define (selection-grow-base img direction amt) ; direction 0 = HORIZONTAL, 1 = VERTICAL, amt can be -ve (let* ((active (car (gimp-image-get-active-drawable img))) (width (car (gimp-image-width img))) (height (car (gimp-image-height img))) (buffer (car (gimp-edit-named-copy (car (gimp-image-get-selection img)) "growselbuffer"))) (imgWork (car (gimp-edit-named-paste-as-new buffer))) (layerWork (car (gimp-image-get-active-layer imgWork))) (xMove (if (equal? direction HORIZONTAL) (/ amt (abs amt)) 0)) ; -1 or +1 (yMove (if (equal? direction VERTICAL) (/ amt (abs amt)) 0)) ; -1 or +1 (layerDup 0) (chanWork 0) (count 1)) (while (<= count (abs amt)) (set! layerDup (car (gimp-layer-copy layerWork FALSE))) (gimp-image-add-layer imgWork layerDup 0) ;duplicated layer (gimp-layer-translate layerDup (* xMove count) (* yMove count)) ; move (gimp-layer-set-mode layerDup LIGHTEN-ONLY-MODE) ; lighten keeps feathering equal to max of two layers (set! count (+ count 1))) (gimp-image-merge-visible-layers imgWork CLIP-TO-IMAGE) (set! chanWork (car (gimp-channel-new-from-component imgWork GRAY-CHANNEL "temp"))) (gimp-image-undo-group-start img) (gimp-selection-none img) ; must do a clear then add because replace is broken in channel-combine-masks (gimp-channel-combine-masks (car (gimp-image-get-selection img)) chanWork CHANNEL-OP-ADD 0 0) (gimp-image-undo-group-end img) (gimp-displays-flush) ;clean up (gimp-buffer-delete buffer) (gimp-image-delete imgWork))) (define (selection-grow-right img inLayer) (let* () (if (equal? (car (gimp-selection-is-empty img)) FALSE) (selection-grow-base img HORIZONTAL 1)))) (script-fu-register "selection-grow-right" "/Select/Grow Directional/Grow Right" "Grows the current selection 1 px right." "Rob Antonishen" "Rob Antonishen" "June 2009" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0) (define (selection-grow-right-10 img inLayer) (let* () (if (equal? (car (gimp-selection-is-empty img)) FALSE) (selection-grow-base img HORIZONTAL 10)))) (script-fu-register "selection-grow-right-10" "/Select/Grow Directional/Grow Right 10" "Grows the current selection 10 px right." "Rob Antonishen" "Rob Antonishen" "June 2009" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0) (define (selection-grow-left img inLayer) (let* () (if (equal? (car (gimp-selection-is-empty img)) FALSE) (selection-grow-base img HORIZONTAL -1)))) (script-fu-register "selection-grow-left" "/Select/Grow Directional/Grow Left" "Grows the current selection 1 px left." "Rob Antonishen" "Rob Antonishen" "June 2009" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0) (define (selection-grow-left-10 img inLayer) (let* () (if (equal? (car (gimp-selection-is-empty img)) FALSE) (selection-grow-base img HORIZONTAL -10)))) (script-fu-register "selection-grow-left-10" "/Select/Grow Directional/Grow Left 10" "Grows the current selection 10 px left." "Rob Antonishen" "Rob Antonishen" "June 2009" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0) (define (selection-grow-down img inLayer) (let* () (if (equal? (car (gimp-selection-is-empty img)) FALSE) (selection-grow-base img VERTICAL 1)))) (script-fu-register "selection-grow-down" "/Select/Grow Directional/Grow Down" "Grows the current selection 1 px down." "Rob Antonishen" "Rob Antonishen" "June 2009" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0) (define (selection-grow-down-10 img inLayer) (let* () (if (equal? (car (gimp-selection-is-empty img)) FALSE) (selection-grow-base img VERTICAL 10)))) (script-fu-register "selection-grow-down-10" "/Select/Grow Directional/Grow Down 10" "Grows the current selection 10 px down." "Rob Antonishen" "Rob Antonishen" "June 2009" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0) (define (selection-grow-up img inLayer) (let* () (if (equal? (car (gimp-selection-is-empty img)) FALSE) (selection-grow-base img VERTICAL -1)))) (script-fu-register "selection-grow-up" "/Select/Grow Directional/Grow Up" "Grows the current selection 1 px up." "Rob Antonishen" "Rob Antonishen" "June 2009" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0) (define (selection-grow-up-10 img inLayer) (let* () (if (equal? (car (gimp-selection-is-empty img)) FALSE) (selection-grow-base img VERTICAL -10)))) (script-fu-register "selection-grow-up-10" "/Select/Grow Directional/Grow Up 10" "Grows the current selection 10 px up." "Rob Antonishen" "Rob Antonishen" "June 2009" "RGB* GRAY*" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0)