Made shared method for similar code.
This commit is contained in:
parent
1a67a1b1f2
commit
94b85dba13
|
@ -14,6 +14,12 @@ def split_seq(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")
|
||||||
|
|
Reference in New Issue