-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgimp-multi-color-dbj-separator.scm
87 lines (79 loc) · 3.2 KB
/
gimp-multi-color-dbj-separator.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
(define (script-fu-knit-multi-color-dbj-separator inImage inLayer)
(let* (
; (palette (cadr (gimp-image-get-colormap inImage)))
; (color-count (/ (car (gimp-image-get-colormap inImage)) 3))
(palette (car (gimp-context-get-palette)))
(color-count (car (gimp-palette-get-info palette)))
(width (car (gimp-drawable-width inLayer)))
(height (car (gimp-drawable-height inLayer)))
(position-x (car (gimp-drawable-offsets inLayer)))
(position-y (cadr (gimp-drawable-offsets inLayer)))
(bg-color (car (gimp-palette-entry-get-color palette 0)))
(fg-color (car (gimp-palette-entry-get-color palette 1)))
)
(gimp-context-push)
(gimp-context-set-paint-mode LAYER-MODE-NORMAL)
(gimp-context-set-opacity 100.0)
(gimp-context-set-feather FALSE)
(gimp-context-set-interpolation 0)
(gimp-image-undo-group-start inImage)
(gimp-context-set-brush-size 1.0)
(gimp-context-set-brush "1. Pixel")
; make a copy of each row per color
(gimp-image-scale inImage width (* height color-count))
(letrec ((loop (lambda (i max)
(if (< i max)
(let* ((color-idx (modulo i color-count)))
(letrec ((pixloop (lambda (j max-j)
(if (< j max-j) (
(let* (
(pixel (car (gimp-image-pick-color inImage inLayer j i FALSE FALSE 0)))
(row-color (car (gimp-palette-entry-get-color palette color-idx)))
(dot (cons-array 2 'double))
)
(aset dot 0 j)
(aset dot 1 i)
(if (equal? pixel row-color)
(gimp-context-set-foreground fg-color)
(gimp-context-set-foreground bg-color)
)
(gimp-pencil inLayer 2 dot) ; screaming into the void
)
)
(pixloop (+ j 1) max-j))
))) (pixloop 0 width)
)
(loop (+ i 1) max)))))
)
(loop 0 height)
)
; double length again
(gimp-image-scale inImage width (* 2 (* height color-count)))
; erase every other row
(letrec ((loop (lambda (i max)
(if (< i max)
(begin
(gimp-image-select-rectangle inImage CHANNEL-OP-REPLACE position-x (+ i position-y) width 1)
(gimp-edit-fill inLayer FILL-BACKGROUND)
(loop (+ i 2) max))))))
(loop 1 (* height (* 2 color-count)))
)
(gimp-selection-none inImage)
(gimp-image-undo-group-end inImage)
(gimp-context-pop)
(gimp-displays-flush)
))
(script-fu-register
"script-fu-knit-multi-color-dbj-separator" ;function name
"DBJ Color Separator" ;menu label
"Splits indexed colored designs for
DBJ knitting with a punchcard or
computerized machine" ;description
"Cathy Wise" ;author
"copyright 2023, Cathy Wise" ;copyright notice
"2023-08-12" ;date created
"INDEXED*" ;image type that the script works on
SF-IMAGE "Image" 0 ;input image
SF-DRAWABLE "Layer" 0 ;input layer
)
(script-fu-menu-register "script-fu-knit-multi-color-dbj-separator" "<Image>/Filters/Knitting/Color Separator")