tangstad/helds
tangstad
/
helds
Archived
1
0
Fork 0

Made shared method for similar code.

This commit is contained in:
Truls Alexander Tangstad 2005-11-09 23:10:57 +00:00
parent 1a67a1b1f2
commit 94b85dba13
1 changed files with 9 additions and 9 deletions

View File

@ -12,8 +12,14 @@ def split_seq(seq, splitsize):
while seq: while seq:
newseq.append(seq[:splitsize]) newseq.append(seq[:splitsize])
seq = seq[splitsize:] seq = seq[splitsize:]
return newseq return newseq
def write_block(f, image, width=8, height=8, offset_x=0, offset_y=0):
for y in range(height):
for x in range(width):
val = image.getpixel((x+offset_x, y+offset_y))
f.write(chr(val))
if __name__=="__main__": if __name__=="__main__":
tiled, args = gnu_getopt(sys.argv[1:], "t") tiled, args = gnu_getopt(sys.argv[1:], "t")
@ -28,10 +34,7 @@ if __name__=="__main__":
width, height = im.size width, height = im.size
print "Converting %dx%d image to binary." % (width, height) print "Converting %dx%d image to binary." % (width, height)
if not tiled: if not tiled:
for y in range(height): write_block(output, im, width, height)
for x in range(width):
val = im.getpixel((x, y))
output.write(chr(val))
else: else:
print "Doing 1D tile conversion." print "Doing 1D tile conversion."
if (width % 8) or (height % 8): if (width % 8) or (height % 8):
@ -40,10 +43,7 @@ if __name__=="__main__":
else: else:
for offset_y in map(lambda n : 8*n, range(height / 8)): for offset_y in map(lambda n : 8*n, range(height / 8)):
for offset_x in map(lambda n : 8*n, range(width / 8)): for offset_x in map(lambda n : 8*n, range(width / 8)):
for y in range(8): write_block(output, im, offset_x=offset_x, offset_y=offset_y)
for x in range(8):
val = im.getpixel((x+offset_x, y+offset_y))
output.write(chr(val))
if len(args) > 2: if len(args) > 2:
pal_output = open(args[2], "wb") pal_output = open(args[2], "wb")