; grow-sel-by-value.scm ; by Rob Antonishen ; http://ffaat.pointclark.net ; Version 1.3 (20090507) ; Description ; ; Script to grow a selection by values around its perimiter ; ; Changes: ; v1.1 - added option to sample merged, and fixed undo issue by using saulgoode's idea. ; v1.2 - bug fixes / code cleanup, ; - shrink as well as grow ; - feather selection option ; - works for disjointed selections now ; v1.3 - cleanup & speed improvement ; - added remainder of fuzzy selection options ; 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 (script-fu-grow-sel-by-value img inLayer inMode inFeather inTrans inMerged inThresh inCrit) (let* ((inLayer (car (gimp-image-get-active-layer img))) (imgCopy (car (gimp-image-duplicate img))) (layerCopy (car (gimp-image-get-active-layer imgCopy))) (varCounter 0) (varPath 0) (varStroke 0) (varStrokeLength 0) (varCheck 0) (varPos 0) (varBuffName "fuzzybuffer") (varNumStrokes 0) (varStrokeCount 0) (varMsg "")) ; it begins here (gimp-context-push) (gimp-image-undo-group-start img) (gimp-image-undo-freeze imgCopy) (if (and (= (car (gimp-selection-is-empty img)) FALSE) (> inLayer 0)) (begin ;turn selection to path (plug-in-sel2path RUN-NONINTERACTIVE imgCopy layerCopy) (set! varPath (vector-ref (cadr (gimp-image-get-vectors imgCopy)) 0)) (set! varNumStrokes (car (gimp-vectors-get-strokes varPath))) ;for each stroke (while (< varStrokeCount varNumStrokes) (set! varStroke (aref (cadr (gimp-vectors-get-strokes varPath)) varStrokeCount)) (set! varStrokeLength (car (gimp-vectors-stroke-get-length varPath varStroke 1))) (set! varCheck (list-ref (gimp-vectors-stroke-get-point-at-dist varPath varStroke varStrokeLength 1) 3)) ;message to user (set! varMsg (cond (( equal? inMode 0 ) "Growing ") (( equal? inMode 1 ) "Shrinking "))) (set! varMsg (string-append varMsg "Selection Area " (number->string (+ varStrokeCount 1)) " of " (number->string varNumStrokes) "...")) (gimp-progress-set-text varMsg) ;backtrack to get last good length to compensate for inacuracies in the gimp-vectors-stroke-get-length call (while (= varCheck FALSE) (set! varStrokeLength (- varStrokeLength 0.001)) (set! varCheck (list-ref (gimp-vectors-stroke-get-point-at-dist varPath varStroke varStrokeLength 1) 3))) ;walk the path (set! varCounter 0) (while (< varCounter varStrokeLength) (set! varPos (gimp-vectors-stroke-get-point-at-dist varPath varStroke varCounter 1)) (gimp-fuzzy-select-full layerCopy (list-ref varPos 0) (list-ref varPos 1) inThresh inMode TRUE FALSE 0 0 inMerged inTrans inCrit) (gimp-progress-update (/ varCounter varStrokeLength)) (set! varCounter (+ varCounter 1))) (set! varStrokeCount (+ varStrokeCount 1))) ;replace main selection- have to use add as CHANNEL-OP-REPLACE is broken in gimp-channel-combine-masks (gimp-selection-none img) (gimp-channel-combine-masks (car (gimp-image-get-selection img)) (car (gimp-image-get-selection imgCopy)) CHANNEL-OP-ADD 0 0) ;feather after (if (> inFeather 0) (gimp-selection-feather img inFeather)))) ;done (gimp-image-undo-thaw imgCopy) (gimp-image-delete imgCopy) (gimp-image-undo-group-end img) (gimp-context-pop))) (script-fu-register "script-fu-grow-sel-by-value" "/Select/Fuzzy Modify Selection..." "Grow or shrink the selection around its boundaries using the provided threshold." "Rob Antonishen" "Rob Antonishen" "May 2009" "" SF-IMAGE "image" 0 SF-DRAWABLE "drawable" 0 SF-OPTION "Mode" (list "Grow Selection" "Shrink Selection") SF-ADJUSTMENT "Feather radius" (list 0 0 100 1 10 1 SF-SLIDER) SF-TOGGLE "Select transparent areas" FALSE SF-TOGGLE "Sample Merged" FALSE SF-ADJUSTMENT "Theshold" (list 10 0 255 1 10 1 SF-SLIDER) SF-OPTION "Select By" (list "Composite" "Red" "Green" "Blue" "Hue" "Saturation" "Value"))