Created
June 5, 2013 16:24
-
-
Save ganglio/5715233 to your computer and use it in GitHub Desktop.
ACO conversion utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# aco | |
# | |
# Convert an Adobe Color Swatches file to standard hex color codes | |
import sys, re, os | |
def main(): | |
args = sys.argv[1:] | |
print args | |
for filename in args: | |
print "Parsing %s\n" % filename | |
print parse_file(filename) | |
def parse_file(filename, chunksize=8192): | |
try: | |
fp = open(filename,'rb') | |
except: | |
sys.stderr.write('Cannot open %s\n' % filename) | |
return | |
bytes = [ord(b) for b in fp.read(chunksize)] | |
ints = [bytes[i]*256+bytes[i+1] for i in range(0,len(bytes),2)] | |
aco = { | |
'version': ints[0], | |
'count': ints[1] | |
} | |
aco['colors'] = [ { | |
's':ints[i], | |
'r':ints[i+1], | |
'g':ints[i+2], | |
'b':ints[i+3] | |
} for i in range(2,ints[1]*4+2,4)] | |
return aco | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment