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:
newseq.append(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__":
tiled, args = gnu_getopt(sys.argv[1:], "t")
@ -28,10 +34,7 @@ if __name__=="__main__":
width, height = im.size
print "Converting %dx%d image to binary." % (width, height)
if not tiled:
for y in range(height):
for x in range(width):
val = im.getpixel((x, y))
output.write(chr(val))
write_block(output, im, width, height)
else:
print "Doing 1D tile conversion."
if (width % 8) or (height % 8):
@ -40,10 +43,7 @@ if __name__=="__main__":
else:
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 y in range(8):
for x in range(8):
val = im.getpixel((x+offset_x, y+offset_y))
output.write(chr(val))
write_block(output, im, offset_x=offset_x, offset_y=offset_y)
if len(args) > 2:
pal_output = open(args[2], "wb")