GIMP Script-fu

Changes On Branch sg-indexed-decompose
Login

Changes On Branch sg-indexed-decompose

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch sg-indexed-decompose Excluding Merge-Ins

This is equivalent to a diff from 2b68df9d38 to 576710206a

2013-04-16
01:11
Changed descriptive blurb. Leaf check-in: 576710206a user: saul tags: sg-indexed-decompose
2013-04-15
05:12
Minor comment change. check-in: 73d931c47f user: saul tags: sg-indexed-decompose
2013-04-14
03:33
Original version 'script-fu-decompose-indexed' from 2006 check-in: af3f854625 user: saul tags: sg-indexed-decompose
03:27
Create new branch named "sg-decomp-to-layers" Leaf check-in: 2b68df9d38 user: saul tags: sg-decomp-to-layers
2010-07-28
13:29
initial empty check-in check-in: cf23bd898b user: saulgoode tags: trunk, root

Added sg-indexed-decompose.scm.


















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
; 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.

(define (script-fu-indexed-decompose orig-image orig-layer)
  (gimp-image-undo-group-start orig-image)
  (gimp-context-push)
  (let* ((buffer (car (gimp-edit-named-copy orig-layer "temp")))
         (image (car (gimp-edit-named-paste-as-new buffer)))
         (layer (car (gimp-image-get-active-layer image))) )
    (gimp-buffer-delete buffer)
    (gimp-context-set-antialias TRUE) 
    (gimp-context-set-feather FALSE) 
    (gimp-context-set-feather-radius 0.0 0.0) 
    (gimp-context-set-sample-merged FALSE) 
    (gimp-context-set-sample-criterion SELECT-CRITERION-COMPOSITE) 
    (gimp-context-set-sample-threshold (/ 255)) 
    (gimp-context-set-sample-transparent FALSE) 
    (let ((offset-x (+ (car (gimp-drawable-offsets orig-layer))
                       (if (zero? (car (gimp-drawable-mask-intersect orig-layer)))
                         0
                         (cadr (gimp-drawable-mask-intersect orig-layer)) )))
          (offset-y (+ (cadr (gimp-drawable-offsets orig-layer))
                       (if (zero? (car (gimp-drawable-mask-intersect orig-layer)))
                         0
                         (caddr (gimp-drawable-mask-intersect orig-layer)) )))
          (parent (car (gimp-item-get-parent orig-layer)))
          (group (car (gimp-layer-group-new orig-image))) )
      (when (= parent -1)
        (set! parent 0) )
      (gimp-image-set-active-layer orig-image orig-layer)
      (gimp-image-insert-layer orig-image group parent -1)
      (gimp-item-set-name group "decomposed")
      (when (zero? (car (gimp-drawable-is-rgb layer)))
        (gimp-image-convert-rgb image) )
      (gimp-image-convert-indexed image NO-DITHER MAKE-PALETTE 256 0 TRUE "")
      (let* ((color-map (vector->list (cadr (gimp-image-get-colormap image))))
             (prog-max (length color-map)) )
        (let loop ((colors color-map)
                   (prog-cnt 0) )
          (gimp-progress-update (/ prog-cnt prog-max))
          (unless (null? colors)
            (let ((red (car colors))
                  (green (cadr colors))
                  (blue (caddr colors)) )
              (gimp-image-select-color image CHANNEL-OP-REPLACE layer (list red green blue))
              (let ((new-layer (car (gimp-layer-copy layer TRUE))))
                (gimp-image-insert-layer image new-layer 0 -1)
                (gimp-selection-invert image)
                (gimp-edit-clear new-layer)
                (let ((color-layer (car (gimp-layer-new-from-drawable new-layer orig-image))))
                  (gimp-layer-set-offsets color-layer offset-x offset-y)
                  (gimp-image-insert-layer orig-image color-layer group -1)
                  (gimp-drawable-set-name color-layer (string-append "RGB=[" 
                                                                     (number->string red) 
                                                                     ", " 
                                                                     (number->string green) 
                                                                     ", " 
                                                                     (number->string blue) 
                                                                     "]" )))
                (gimp-image-remove-layer image new-layer)
                (loop (cdddr colors) (+ 3 prog-cnt)) ))))))
    (gimp-context-pop)
    (gimp-progress-end)
    (gimp-image-delete image)
    (gimp-displays-flush)
    )
  (gimp-image-undo-group-end orig-image)
  )

(script-fu-register "script-fu-indexed-decompose"
 "Indexed Decompose"
 "Separate layer based on color"
 "Saul Goode"
 "Saul Goode"
 "April 2013"
 "*"
 SF-IMAGE    "Image"    0
 SF-DRAWABLE "Drawable" 0
 )
(script-fu-menu-register "script-fu-indexed-decompose"
  "<Image>/Filters/Colors"
  )