;;; separate.scm ;;; Copyright (C) 2002 David Fifield ;;; Color-separation script for the GIMP. For more information see ;;; http://www.bamsoftware.com/hacks/separate/index.html. ;;; You may use, modify, copy and redistribute this program without ;;; restriction as long as this notice remains intact. (define (script-fu-separate image drawable num use-palette palette) (let* ((image-id (car (gimp-channel-ops-duplicate image))) (layer-id (car (gimp-image-flatten image-id))) (width (car (gimp-image-width image-id))) (height (car (gimp-image-height image-id))) (cmap 0)) (gimp-image-undo-disable image-id) (if (= (car (gimp-drawable-is-rgb layer-id)) 0) (gimp-convert-rgb image-id)) (if (= use-palette 0) (gimp-convert-indexed image-id 0 MAKE-PALETTE num 0 0 "") (gimp-convert-indexed image-id 0 CUSTOM-PALETTE 0 0 1 palette)) (set! cmap (cadr (gimp-image-get-cmap image-id))) (set! num (/ (car (gimp-image-get-cmap image-id)) 3)) (gimp-convert-rgb image-id) (print cmap) (gimp-palette-set-foreground '(0 0 0)) (let ((index 0) (id 0) (color '(0 0 0))) (while (< index num) (set! id (car (gimp-layer-new image-id width height RGB-IMAGE (string-append "Color " (number->string (+ index 1) 10)) 100 NORMAL-MODE))) (set! color (list (aref cmap (* index 3) 0) (aref cmap (+ (* index 3) 1)) (aref cmap (+ (* index 3) 2)))) (gimp-drawable-fill id WHITE-IMAGE-FILL) (gimp-by-color-select layer-id color 0 REPLACE FALSE 0 0 0) (gimp-bucket-fill id FG-BUCKET-FILL NORMAL-MODE 100 0 0 0 0) (gimp-image-add-layer image-id id 0) (set! index (+ index 1)))) (gimp-selection-none image-id) (gimp-image-undo-enable image-id) (gimp-image-clean-all image-id) (gimp-display-new image-id))) (script-fu-register "script-fu-separate" _"/Image/Colors/Separate..." "Separates an image into its component colors." "David Fifield " "David Fifield" "02/04/2002" "" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-ADJUSTMENT _"Number of colors" '(2 2 256 1 10 0 1) SF-TOGGLE "Use custom palette?" FALSE SF-STRING "Custom palette" "Default")