-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCrayonPixelArtAllDitherTypes_02.scm
189 lines (168 loc) · 8.31 KB
/
CrayonPixelArtAllDitherTypes_02.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
; GPLv3
; 02/15/2014 - work with non-rgb, merge option and install info added
;==============================================================
;
; Installation:
; This script should be placed in the user or system-wide script folder.
;
; Windows Vista/7/8)
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Users\YOUR-NAME\.gimp-2.8\scripts
;
; Windows XP
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Documents and Settings\yourname\.gimp-2.8\scripts
;
; Linux
; /home/yourname/.gimp-2.8/scripts
; or
; Linux system-wide
; /usr/share/gimp/2.0/scripts
;
;==============================================================
;
; LICENSE
;
; 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 3 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, see <http://www.gnu.org/licenses/>.
;
;==============================================================
; Original information
(define (script-fu-crayon-pixel-art-all-dither theImage drawable scale_factor interpolation chosen_palette autolevels keepscaled)
;NOTES:
;for some reason it doesn't work on PNGs. currently you need to save as a gif to get it to work.
;if it throws an error on a jpg bc it wasn't in indexed mode you may need to close gimp and reopen to clean up any variables that will prevent the successful execution of the script on subsequent attempts
(let* (
; calls to PDB functions always return a list. We have
; to pick the first element with "car" explicitely, even
; when the function called returns just one value.
(width (car (gimp-drawable-width drawable)))
(height (car (gimp-drawable-height drawable)))
(new_width (* width scale_factor ))
(new_height (* height scale_factor))
(FSDither 0); (gimp-image-new new_width new_height 0));0 for rgb
(FSLBDither 0); (gimp-image-new new_width new_height 0));0 for rgb
(FixedDither 0); (gimp-image-new new_width new_height 0));0 for rgb
(NoDither 0)
(PaletteGen 0)
(adrawable 0);
(InputImageMode 0);mode of the input image. needed so we can prevent errors when getting an RGB image as input.
(scale_back TRUE)
)
;create undo group
(gimp-image-undo-group-start theImage)
(set! InputImageMode ( car (gimp-image-base-type theImage )))
(if (not (= InputImageMode 0))
(gimp-convert-rgb theImage)
);convert to RGB if the image isn't all ready an RGB image
;apply autoleveling if desired
;this is pretty useless if the image is a gif as typically pure white and pure black are two of the colors in the palette so this does nothing in those cases.
(if (= autolevels TRUE)
(begin
(set! adrawable ( car (gimp-image-get-active-drawable theImage)))
(gimp-drawable-levels-stretch adrawable) ;;
)
(begin ; else
(set! adrawable ( car (gimp-image-get-active-drawable theImage)))
)
)
;Scale the Image to blow up the gif so we can see it. this helps to allow for a more pleasing picture to dither. if the image is too small the dithering is awful
(gimp-image-scale theImage new_width new_height);
;Create NO DITHER image
(gimp-edit-named-copy-visible theImage "ImgVisible")
(set! NoDither ( car (gimp-edit-named-paste-as-new "ImgVisible")))
;(gimp-display-new NoDither)
(gimp-image-convert-indexed NoDither 0 4 0 FALSE FALSE chosen_palette )
(set! adrawable ( car (gimp-image-get-active-drawable NoDither)))
(gimp-drawable-set-name adrawable "No Dither")
(if (= keepscaled FALSE)
(gimp-image-scale NoDither width height)
)
(gimp-display-new NoDither)
;Create FS DITHER image
(gimp-edit-named-copy-visible theImage "ImgVisible")
(set! FSDither ( car (gimp-edit-named-paste-as-new "ImgVisible")))
;(gimp-display-new FSDither)
(gimp-image-convert-indexed FSDither 1 4 0 FALSE FALSE chosen_palette )
(set! adrawable ( car (gimp-image-get-active-drawable FSDither)))
(gimp-drawable-set-name adrawable "FS Dither")
(if (= keepscaled FALSE)
(gimp-image-scale FSDither width height)
)
(gimp-display-new FSDither)
;Create FS Low Bleed DITHER image
(gimp-edit-named-copy-visible theImage "ImgVisible")
(set! FSLBDither ( car (gimp-edit-named-paste-as-new "ImgVisible")))
;(gimp-display-new FSLBDither)
(gimp-image-convert-indexed FSLBDither 2 4 0 FALSE FALSE chosen_palette )
(set! adrawable ( car (gimp-image-get-active-drawable FSLBDither)))
(gimp-drawable-set-name adrawable "FSLB Dither")
(if (= keepscaled FALSE)
(gimp-image-scale FSLBDither width height)
)
(gimp-display-new FSLBDither)
;Create FIXED DITHER image
(gimp-edit-named-copy-visible theImage "ImgVisible")
(set! FixedDither ( car (gimp-edit-named-paste-as-new "ImgVisible")))
;(gimp-display-new FixedDither)
(gimp-image-convert-indexed FixedDither 3 4 0 FALSE FALSE chosen_palette )
(set! adrawable ( car (gimp-image-get-active-drawable FixedDither)))
(gimp-drawable-set-name adrawable "Fixed Dither")
(if (= keepscaled FALSE)
(begin
(gimp-image-scale FixedDither width height)
)
)
(gimp-display-new FixedDither)
;Create Generated Palette image
(gimp-edit-named-copy-visible theImage "ImgVisible")
(set! PaletteGen ( car (gimp-edit-named-paste-as-new "ImgVisible")))
;(gimp-display-new FixedDither)
(gimp-image-convert-indexed PaletteGen 0 0 8 TRUE FALSE "GeneratedPaletteCrayonPixelArt" )
(set! adrawable ( car (gimp-image-get-active-drawable PaletteGen)))
(gimp-drawable-set-name adrawable "PaletteGen")
(if (= keepscaled FALSE)
(begin
(gimp-image-scale PaletteGen width height)
)
)
(gimp-display-new PaletteGen)
; empty the buffer
(gimp-buffer-delete "ImgVisible")
(gc)
;create undo group
(gimp-image-undo-group-end theImage)
(gimp-displays-flush)
)
)
(script-fu-register "script-fu-crayon-pixel-art-all-dither"
"Caryon-Pixel-Art-All-Dither"
"Processes an indexed color JPG/GIF (doesnt work on pngs) image creating a pixelized image given a palette. \n Creates 5 images so results can be compared. Final version generates a palette. \nfile:CrayonPixelArtAllDitherTypes_02.scm"
"InkyDinky"
"InkyDinky"
"2011 11 28"
"*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
;SF-ENUM "Dither" '("DitherType" "GIMP_FS_DITHER") google gimp enum types
; SF-OPTION "Dither" '("None" "Floyd-Steinberg" "Floyd-Steinberg Low Bleed" "Fixed")
SF-ADJUSTMENT "Scale Factor" '(2 0 10 1 2 0 SF-SLIDER )
SF-OPTION "Interpolation" '("None" "Linear" "Cubic" "Sinc (Lanczos3)");I wish I knew how to use the enum types but not worth the hassle when can use options and works right away. http://developer.gimp.org/api/2.0/libgimpbase/libgimpbase-gimpbaseenums.html
SF-PALETTE "Palette" "Ega"
SF-TOGGLE "Auto-level image?" TRUE
SF-TOGGLE "Keep scaled up versions" FALSE
)
(script-fu-menu-register "script-fu-crayon-pixel-art-all-dither" "<Image>/Script-Fu/Photo/Graphic/")
; end of file