Made shared method for similar code.
This commit is contained in:
parent
1a67a1b1f2
commit
94b85dba13
@ -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")
|
||||
|
Reference in New Issue
Block a user