GIMP Script-fu

Artifact [6b15d4cfd1]
Login

Artifact [6b15d4cfd1]

Artifact 6b15d4cfd1023b39970114e0eec1f80ff074b714:


; 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.

;; 'select-by-color' selects all pixels that are the same color.
;; This mirrors the functionality of Select By Color Tool, but
;; permits specification of the color (rather than picking it from the
;; image.

(define (script-fu-sg-select-similar-colors image drawable
                                   mode
                                   color
                                   antialias?
                                   feather?
                                   feather-radius
                                   transparent?
                                   sample-merged?
                                   threshold
                                   select-criterion
                                   )
  (let* (
      (operation
          (cond ((= mode 0) CHANNEL-OP-REPLACE)
                ((= mode 1) CHANNEL-OP-ADD)
                ((= mode 2) CHANNEL-OP-SUBTRACT)
                ((= mode 3) CHANNEL-OP-INTERSECT)))
      )
    (gimp-image-undo-group-start image)
    (gimp-by-color-select-full drawable
                               color
                               threshold
                               operation
                               antialias?
                               feather?
                               feather-radius
                               feather-radius
                               sample-merged?
                               transparent?
                               select-criterion
                               )
    (gimp-image-undo-group-end image)
    (gimp-displays-flush)
    )
  )

(script-fu-register "script-fu-sg-select-similar-colors"
 "Si_milar colors..."
 "Select all pixels of a specified color"
 "Saul Goode"
 "Saul Goode"
 "7/21/2007"
 "RGB*,GRAY*"
 SF-IMAGE    "Image"    0
 SF-DRAWABLE "Drawable" 0
 SF-OPTION "Mode" '("Replace" "Add" "Subtract" "Intersect")
 SF-COLOR "Color" (car (gimp-context-get-foreground))
 SF-TOGGLE "Antialiasing" TRUE
 SF-TOGGLE "Feather" FALSE
 SF-ADJUSTMENT "Feather Radius" '(0 0 100 1 10 1 0)
 SF-TOGGLE "Select transparent areas" TRUE
 SF-TOGGLE "Sample merged" FALSE
 SF-ADJUSTMENT "Threshold" '(15 0 255 1 10 1 0)
 SF-OPTION "Select by" '("Composite" "Red" "Green" "Blue" "Hue" "Saturation" "Value")
 )

(script-fu-menu-register "script-fu-sg-select-similar-colors"
			 "<Image>/Select" )