; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; Rectangle/Circle selection using guide script for GIMP 1.2 ; Copyright (C) 2001 Iccii ; ; -------------------------------------------------------------------- ; version 0.1 by Iccii 2002/01/13 ; - Initial relase ; version 0.1a by Raymond Ostertag 2004/09 ; - Changed menu entry ; -------------------------------------------------------------------- ; ; 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. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ; ;; Make selection using guides (define (script-fu-guide-rect-selection img ;; Target Image drawable ;; Target Drawable (unused) selection-type ;; rect/ellipse/diamond operation ;; add/sub/replace/intersect antialias? ;; use antialias option? ) (define (list-ref l n) (nth n l)) (set! exist-guide? (car (gimp-image-find-next-guide img 0))) (set! status (if (equal? exist-guide? FALSE) nil #t)) ;; check the number of gildes (if status (let* ((x-num 0) (y-num 0) (guide 0) (flag #t)) (while flag (set! guide (car (gimp-image-find-next-guide img guide))) (if (= guide 0) (set! flag nil) (if (= (car (gimp-image-get-guide-orientation img guide)) 1) (set! x-num (+ x-num 1)) (set! y-num (+ y-num 1))))) (if (< x-num 2) (gimp-message "Can not find horizontal guides more than 2. Abort!")) (if (< y-num 2) (gimp-message "Can not find vertical guides more than 2. Abort!")) (set! status (if (or (< x-num 2) (< y-num 2)) nil #t)) ) ; end of let* (gimp-message "Found not any guides in this image. Abort!") ) ; end of if status ;; Main (if status (begin ;; get x and y guide position (let* ((guide 0) (flag #t) (x-list '()) (y-list '())) (while flag (set! guide (car (gimp-image-find-next-guide img guide))) (if (= guide 0) (set! flag nil) (let* ((position (car (gimp-image-get-guide-position img guide))) (orientation (car (gimp-image-get-guide-orientation img guide)))) (cond ((= orientation VERTICAL) (set! x-list (cons position x-list))) ((= orientation HORIZONTAL) (set! y-list (cons position y-list))) ('else (gimp-message "orientation error!")) ) ; end of cond ) ; end of let* ) ; end of if ) ; end of while ;; it's a simplest sort algorism ;-) (define (get-minmax minmax lists) ; minmax: 0=min, 1=max (define (min_max-value cou res) (if (= minmax 0) (min (list-ref lists cou) res) (max (list-ref lists cou) res))) (let* ((result (if (= minmax 0) 32767 -32767)) ; <- 32768? (count 0)) (while (< count (length lists)) (set! result (min_max-value count result)) (set! count (+ count 1))) result)) (set! x1 (get-minmax 0 x-list)) ; (x1,y1) +-----+ (x2,y1) (set! x2 (get-minmax 1 x-list)) ; | | (set! y1 (get-minmax 0 y-list)) ; | | (set! y2 (get-minmax 1 y-list)) ; (x1,y2) +-----+ (x2,y2) (set! width (- x2 x1)) (set! height (- y2 y1)) ) ; end of let* ;; make selection area (cond ((= selection-type 0) (gimp-rect-select img x1 y1 width height operation 0 0)) ((= selection-type 1) (gimp-ellipse-select img x1 y1 width height operation antialias? 0 0)) ((= selection-type 2) (let* ((num_segs 8) (segs (cons-array num_segs 'double))) (aset segs 0 (+ x1 (/ width 2))) (aset segs 1 (+ y1 0)) (aset segs 2 (+ x2 0)) (aset segs 3 (+ y1 (/ height 2))) (aset segs 4 (+ x1 (/ width 2))) (aset segs 5 (+ y2 0)) (aset segs 6 (+ x1 0)) (aset segs 7 (+ y1 (/ height 2))) (gimp-free-select img num_segs segs operation antialias? 0 0))) ('else (gimp-mesasge "selection-type error!")) ) ; end of cond )) ; end of (if and (begin (gimp-displays-flush) ) ; end of define (script-fu-register "script-fu-guide-rect-selection" "/Script-Fu/Selection/Guide Rectangle Selection..." "Select rectangular/ellipse/diamond area using guide" "Iccii " "Iccii" "2002, Jan" "RGB* GRAY* INDEXED*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-OPTION "Selection Type" '("Rectangular" "Ellipse" "Diamond") SF-OPTION "Operation" '("Add" "Substract" "Replace" "Intersect") SF-TOGGLE "Antialias" TRUE )