Archived
1
0

Added output of palettes.

Rotated output of data, previously it outputted by column, not row.
This commit is contained in:
2005-11-09 20:29:56 +00:00
parent 8474f213f5
commit b634a9b6dc

@ -2,19 +2,40 @@
from PIL import Image from PIL import Image
import sys import sys
import os import os
import struct
"""Convert image to raw binary using Python Imaging Library.""" """Convert image to raw binary using Python Imaging Library."""
if len(sys.argv) != 3: def split_seq(seq, splitsize):
print "Usage: %s <source> <target>" % os.path.split(sys.argv[0])[1] newseq = []
print "WARNING: It only converts 8x8 pixel images at 8bit the moment." while seq:
sys.exit() newseq.append(seq[:splitsize])
print "elem:", newseq[-1]
seq = seq[splitsize:]
return newseq
im = Image.open(sys.argv[1]) if __name__=="__main__":
output = open(sys.argv[2], "wb") if len(sys.argv) < 3:
for x in range(8): print "Usage: %s <source> <target> [palette]" % os.path.split(sys.argv[0])[1]
for y in range(8): print "WARNING: It only converts 8bit images at the moment... and no tiling."
val = im.getpixel((x, y)) sys.exit()
output.write(chr(val))
im = Image.open(sys.argv[1])
output = open(sys.argv[2], "wb")
width, height = im.size
for y in range(height):
for x in range(width):
val = im.getpixel((x, y))
output.write(chr(val))
if len(sys.argv) > 3:
pal_output = open(sys.argv[3], "wb")
print "entries:", len(im.palette.palette)
for i, color in enumerate(split_seq(im.palette.palette, 3)):
r, g, b = map(lambda col : col >> 3, map(ord, color))
print "rgb:", r, g, b
value = (b << 10) + (g << 5) + r
print "color", i, ":", value
pal_output.write(struct.pack("<h", value))