forked from denilsonsa/small_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
act_to_gpl.py
executable file
·45 lines (37 loc) · 1.2 KB
/
act_to_gpl.py
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
#!/usr/bin/env python3
#
# Adobe Photoshop "*.act" palette file conversion to GIMP "*.gpl" palette
# format (which is also recognized by many other tools).
#
# How to use:
# ./act_to_gpl.py some_palette.act > some_palette.gpl
#
# Code based on swatchbook/codecs/adobe_act.py from:
# http://www.selapa.net/swatchbooker/
import os.path
import struct
import sys
def parse_adobe_act(filename):
filesize = os.path.getsize(filename)
with open(filename, 'rb') as file:
if filesize == 772: # CS2
file.seek(768, 0)
nbcolors = struct.unpack('>H', file.read(2))[0]
file.seek(0, 0)
else:
nbcolors = filesize // 3
# List of (R, G, B) tuples.
return [struct.unpack('3B', file.read(3)) for i in range(nbcolors)]
def return_gimp_palette(colors, name, columns=0):
return 'GIMP Palette\nName: {name}\nColumns: {columns}\n#\n{colors}\n'.format(
name=name,
columns=columns,
colors='\n'.join(
'{0} {1} {2}\tUntitled'.format(*color)
for color in colors
),
)
if __name__ == '__main__':
sys.stdout.write(
return_gimp_palette(parse_adobe_act(sys.argv[1]), sys.argv[1])
)