(define (sg-fuzzy-select-along-path image path operation antialias? feather? radius transparent? merged? thresh criterion) (let* ( (x1 0) (y1 0) (x2 (car (gimp-image-width image))) (y2 (car (gimp-image-height image))) (stroke's (vector->list (cadr (gimp-vectors-get-strokes path)))) (stroke nil) (point nil) (x 0) (y 0) (last-x 0) (last-y 0) (dist 0) (source 0) (orig-sel 0) ) (set! source (car (gimp-image-get-active-drawable image))) (set! orig-sel (car (gimp-selection-save image))) (gimp-selection-none image) (when (= merged? FALSE) (set! x1 (car (gimp-drawable-offsets source))) (set! y1 (cadr (gimp-drawable-offsets source))) (set! x2 (+ x1 (car (gimp-drawable-width source)))) (set! y2 (+ y1 (car (gimp-drawable-height source)))) ) (while (pair? stroke's) (set! stroke (car stroke's)) (set! dist (car (gimp-vectors-stroke-get-length path stroke 0.5))) (while (>= dist 0) (set! point (gimp-vectors-stroke-get-point-at-dist path stroke dist 1)) (set! x (truncate (car point))) (set! y (truncate (cadr point))) (when (and (or (<> x last-x) (<> y last-y)) (= (cadddr point) 1)) (when (and (>= x x1) (>= y y1) (< x x2) (< y y2)) (set! last-x x) (set! last-y y) (when (and (= merged? FALSE)) (set! x (- x x1)) (set! y (- y y1)) ) (gimp-fuzzy-select-full source x y thresh CHANNEL-OP-ADD antialias? feather? radius radius merged? transparent? criterion) ) ) (set! dist (- dist 1)) ) (set! stroke's (cdr stroke's)) ) (gimp-channel-combine-masks orig-sel (car (gimp-image-get-selection image)) operation 0 0) (gimp-selection-load orig-sel) (gimp-image-remove-channel image orig-sel) ) ) (define (sg-by-color-select-along-path image path operation antialias? feather? radius transparent? merged? thresh criterion) (let* ( (drawable (car (gimp-image-get-active-drawable image))) (source 0) (x1 0) (y1 0) (x2 (car (gimp-image-width image))) (y2 (car (gimp-image-height image))) (stroke's (vector->list (cadr (gimp-vectors-get-strokes path)))) (stroke nil) (point nil) (x 0) (y 0) (last-x 0) (last-y 0) (dist 0) (orig-sel 0) (color nil) ) (set! orig-sel (car (gimp-selection-save image))) (gimp-selection-none image) (if (= merged? TRUE) (begin (set! source (car (gimp-layer-new-from-visible image image "Source"))) (gimp-image-add-layer image source 0) ) (begin (set! source drawable) (set! x1 (car (gimp-drawable-offsets source))) (set! y1 (cadr (gimp-drawable-offsets source))) (set! x2 (+ x1 (car (gimp-drawable-width source)))) (set! y2 (+ y1 (car (gimp-drawable-height source)))) ) ) (while (pair? stroke's) (set! stroke (car stroke's)) (set! dist (car (gimp-vectors-stroke-get-length path stroke 0.5))) (while (>= dist 0) (set! point (gimp-vectors-stroke-get-point-at-dist path stroke dist 1)) (set! x (truncate (car point))) (set! y (truncate (cadr point))) (when (and (or (<> x last-x) (<> y last-y)) (= (cadddr point) 1)) (when (and (>= x x1) (>= y y1) (< x x2) (< y y2)) (set! last-x x) (set! last-y y) (when (and (= merged? FALSE)) (set! x (- x x1)) (set! y (- y y1)) ) (set! color (vector->list (cadr (gimp-drawable-get-pixel source x y)))) (if (= (length color) 4) (set! color (butlast color)) ) (gimp-by-color-select-full source color thresh CHANNEL-OP-ADD antialias? feather? radius radius merged? transparent? criterion) ) ) (set! dist (- dist 1)) ) (set! stroke's (cdr stroke's)) ) (when (= merged? TRUE) (gimp-image-remove-layer source) ) (gimp-channel-combine-masks orig-sel (car (gimp-image-get-selection image)) operation 0 0) (gimp-selection-load orig-sel) (gimp-image-remove-channel image orig-sel) (if (= (car (gimp-drawable-is-layer drawable)) 1) (gimp-image-set-active-layer image drawable) (if (= (car (gimp-drawable-is-layer-mask drawable)) 1) (begin (set! drawable (car (gimp-layer-from-mask drawable))) (gimp-image-set-active-layer image drawable) (gimp-layer-set-edit-mask drawable TRUE) ) (gimp-image-set-active-channel image drawable) ) ) (gimp-image-set-active-channel image drawable) (gimp-image-set-active-layer image drawable) ) ) (define (sg-select-along-path image path tool operation antialias? feather? radius transparent? merged? thresh criterion) (gimp-image-undo-group-start image) (if (= tool 0) (sg-by-color-select-along-path image path operation antialias? feather? radius transparent? merged? thresh criterion) (sg-fuzzy-select-along-path image path operation antialias? feather? radius transparent? merged? thresh criterion) ) (gimp-image-undo-group-end image) ) (script-fu-register "sg-select-along-path" "Select Along Path..." "Select along path" "Saul Goode" "Saul Goode" "2009-08-30" "*" SF-IMAGE "Image" 0 SF-VECTORS "Vectors" 0 SF-OPTION "Tool" '("Select by color" "Fuzzy select") SF-ENUM "Mode" '("ChannelOps" "Replace the current selection") SF-TOGGLE "Antialiasing" TRUE SF-TOGGLE "Feather edges" FALSE SF-ADJUSTMENT "Feather radius" '(10 0 100 1 10 0 1) SF-TOGGLE "Select transparent areas" TRUE SF-TOGGLE "Sample merged" FALSE SF-ADJUSTMENT "Threshold" '(15 0 255 1 10 0 1) SF-ENUM "Select by" '("SelectCriterion" "Composite") ) (script-fu-menu-register "sg-select-along-path" "")