Skip to content

Instantly share code, notes, and snippets.

@mieki256
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mieki256/63df258c3122f8f1f75e to your computer and use it in GitHub Desktop.
Save mieki256/63df258c3122f8f1f75e to your computer and use it in GitHub Desktop.
GIMPでARGB4444に画像を変換するスクリプト。http://registry.gimp.org/taxonomy/term/1275 を改造。
GIMP Palette
Name: 1-Bit Grayscale
Columns: 16
#
0 0 0
255 255 255
GIMP Palette
Name: 3-Bit Grayscale
Columns: 8
#
0 0 0
36 36 36
72 72 72
109 109 109
145 145 145
182 182 182
218 218 218
255 255 255
GIMP Palette
Name: 4-Bit Grayscale
Columns: 16
#
0 0 0
17 17 17
34 34 34
51 51 51
68 68 68
85 85 85
102 102 102
119 119 119
136 136 136
153 153 153
170 170 170
187 187 187
204 204 204
221 221 221
238 238 238
255 255 255
GIMP Palette
Name: 5-Bit Grayscale
Columns: 16
#
0 0 0
8 8 8
16 16 16
25 25 25
33 33 33
41 41 41
49 49 49
58 58 58
66 66 66
74 74 74
82 82 82
90 90 90
99 99 99
107 107 107
115 115 115
123 123 123
132 132 132
140 140 140
148 148 148
156 156 156
165 165 165
173 173 173
181 181 181
189 189 189
197 197 197
206 206 206
214 214 214
222 222 222
230 230 230
239 239 239
247 247 247
255 255 255
GIMP Palette
Name: 6-Bit Grayscale
Columns: 16
#
0 0 0
4 4 4
8 8 8
12 12 12
16 16 16
20 20 20
24 24 24
28 28 28
32 32 32
36 36 36
40 40 40
45 45 45
49 49 49
53 53 53
57 57 57
61 61 61
65 65 65
69 69 69
73 73 73
77 77 77
81 81 81
85 85 85
89 89 89
93 93 93
97 97 97
101 101 101
105 105 105
109 109 109
113 113 113
117 117 117
121 121 121
125 125 125
130 130 130
134 134 134
138 138 138
142 142 142
146 146 146
150 150 150
154 154 154
158 158 158
162 162 162
166 166 166
170 170 170
174 174 174
178 178 178
182 182 182
186 186 186
190 190 190
194 194 194
198 198 198
202 202 202
206 206 206
210 210 210
215 215 215
219 219 219
223 223 223
227 227 227
231 231 231
235 235 235
239 239 239
243 243 243
247 247 247
251 251 251
255 255 255
; GIMP - The GNU Image Manipulation Program
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
;
; 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.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
; Copyright (C) 2011 Xaffron Software skwong@consultant.com
;
; This script
; 1)adds alpha channel to active layer,
; 2)splits active layer into RGBA,
; 3)converts each layer to 1-, 4-, 5- or 6- bit grayscale w/ FS dither, then
; 4)recomposes it.
; The end effect is that images are "Dithered" to either:
; 12-bit color + 4-bit transparency (ARGB4444/4096colors),
; 16-bit color + no transparency (RGB565/4096colors), or
; 15-bit color + 1-bit transparency (ARGB1555/4096colors).
;
; The higher-depth dither is especially useful for mobile developers who need to pre-dither
; assets for 12- or 16-bit screens.
;
; Version 0.1 Initial Version - No frills, barely works.
; Version 0.2 Renamed to dither16bit.scm - Added RGB565 and ARGB1555.
;
; Version 0.2.1 fork dither16bit.scm - Added ARGB4444 (no dither), ARGB3333 (no dither).
;
; INSTALL:
; Copy the dither16bit.scm file to your scripts dir.
; Extract the separate 1Bit, 4Bit, 5Bit and 6BitGrayscale.gpl files from the zipfile
; and copy to your palettes dir.
; Copy the 3BitGrayscale.gpl file to your palettes dir.
; To run, start up GIMP, go to
;Image->Mode->Dither to ARGB4444
;Image->Mode->Dither to RGB565
;Image->Mode->Dither to ARGB1555
;Image->Mode->to ARGB xxxx
;
; Please email me for any issues... I'm pretty swamped, but I'll try to address!
;
(define (script-fu-12bit-not-dither aimg adraw ckind dither dithera)
(let* ((img (car (gimp-drawable-get-image adraw)))
(draw (car (gimp-image-get-active-layer img)))
(owidth (car (gimp-image-width img)))
(oheight (car (gimp-image-height img)))
(paltbl
(cond
((= ckind 0) '("4-Bit Grayscale" "4-Bit Grayscale" "4-Bit Grayscale" "4-Bit Grayscale"))
((= ckind 1) '("5-Bit Grayscale" "5-Bit Grayscale" "5-Bit Grayscale" "1-Bit Grayscale"))
((= ckind 2) '("5-Bit Grayscale" "6-Bit Grayscale" "5-Bit Grayscale" ""))
((= ckind 3) '("3-Bit Grayscale" "3-Bit Grayscale" "3-Bit Grayscale" "3-Bit Grayscale"))
((= ckind 4) '("3-Bit Grayscale" "3-Bit Grayscale" "3-Bit Grayscale" "1-Bit Grayscale"))
))
(palr (car paltbl))
(palg (cadr paltbl))
(palb (caddr paltbl))
(pala (cadddr paltbl)))
(gimp-context-push)
(gimp-image-undo-group-start img)
(if (equal? pala "") #f (gimp-layer-add-alpha draw))
(let* ((layers (if (equal? pala "")
(plug-in-decompose 1 img draw "RGB" 0)
(plug-in-decompose 1 img draw "RGBA" 0)))
(red (car layers))
(green (cadr layers))
(blue (caddr layers))
(alpha (if (equal? pala "") #f (cadddr layers))))
(gimp-image-convert-rgb red)
(gimp-image-convert-indexed red dither 4 4096 FALSE FALSE palr)
(gimp-image-convert-grayscale red)
(gimp-image-convert-rgb green)
(gimp-image-convert-indexed green dither 4 4096 FALSE FALSE palg)
(gimp-image-convert-grayscale green)
(gimp-image-convert-rgb blue)
(gimp-image-convert-indexed blue dither 4 4096 FALSE FALSE palb)
(gimp-image-convert-grayscale blue)
(if (equal? pala "")
(gimp-display-new (car (plug-in-compose 1 red 0 green blue 0 "RGB")))
(begin
(gimp-image-convert-rgb alpha)
(gimp-image-convert-indexed alpha dithera 4 4096 FALSE FALSE pala)
(gimp-image-convert-grayscale alpha)
(gimp-display-new (car (plug-in-compose 1 red 0 green blue alpha "RGBA")))))
(gimp-image-delete red)
(gimp-image-delete green)
(gimp-image-delete blue)
(if (equal? pala "") #f (gimp-image-delete alpha)))
(gimp-selection-none img)
(gimp-image-undo-group-end img)
(gimp-displays-flush)
(gimp-context-pop)
))
(define (script-fu-12bit-dither aimg adraw)
(script-fu-12bit-not-dither aimg adraw 0 1 1))
(define (script-fu-argb1555-dither aimg adraw)
(script-fu-12bit-not-dither aimg adraw 1 1 1))
(define (script-fu-rgb565-dither aimg adraw)
(script-fu-12bit-not-dither aimg adraw 2 1 1))
(script-fu-register
"script-fu-12bit-dither"
_"Dither to ARGB_4444..."
_"Dither to ARGB4444 (4096) colors. Useful for mobile applications."
"Sunny Kwong <skwong@consultant.com>"
"Sunny Kwong"
"4/27/2011"
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
)
(script-fu-register
"script-fu-rgb565-dither"
_"Dither to RGB_565..."
_"Dither to RGB565 (4096) colors. Useful for mobile applications."
"Sunny Kwong <skwong@consultant.com>"
"Sunny Kwong"
"10/23/2012"
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
)
(script-fu-register
"script-fu-argb1555-dither"
_"Dither to ARGB_1555..."
_"Dither to ARGB1555 (4096) colors. Useful for mobile applications."
"Sunny Kwong <skwong@consultant.com>"
"Sunny Kwong"
"10/23/2012"
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
)
(script-fu-register
"script-fu-12bit-not-dither"
_"to ARGB_xxxx..."
_"to ARGB4444 (4096) or ARGB3333 (512) colors."
"Sunny Kwong <skwong@consultant.com>, mieki256"
"Sunny Kwong, mieki256"
"03/03/2015"
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
SF-OPTION "Color" '("ARGB4444" "ARGB1555" "RGB565" "ARGB3333" "ARGB1333")
SF-OPTION "RGB Dither" '("none" "fs-dither" "fslowbleed-dither" "fixed-dither")
SF-OPTION "Alpha Dither" '("none" "fs-dither" "fslowbleed-dither" "fixed-dither")
)
(script-fu-menu-register "script-fu-12bit-dither" "<Image>/Image/Mode")
(script-fu-menu-register "script-fu-rgb565-dither" "<Image>/Image/Mode")
(script-fu-menu-register "script-fu-argb1555-dither" "<Image>/Image/Mode")
(script-fu-menu-register "script-fu-12bit-not-dither" "<Image>/Image/Mode")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment