more docstring/indent fixes in gfx.py

This commit is contained in:
cogitokat 2013-06-23 15:07:39 -03:00
parent 3ee5295ee3
commit a60bf16901

View File

@ -12,35 +12,35 @@ from trainers import trainer_group_names
if __name__ != "__main__": if __name__ != "__main__":
rom = load_rom() rom = load_rom()
def mkdir_p(path): def mkdir_p(path):
""" """
Make a directory at a given path. Make a directory at a given path.
""" """
try: try:
os.makedirs(path) os.makedirs(path)
except OSError as exc: # Python >2.5 except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST: if exc.errno == errno.EEXIST:
pass pass
else: raise else: raise
def hex_dump(input, debug = True): def hex_dump(input, debug = True):
""" """
Display hex dump in rows of 16 bytes. Display hex dump in rows of 16 bytes.
""" """
dump = '' dump = ''
output = '' output = ''
stream = '' stream = ''
address = 0x00 address = 0x00
margin = 2 + len(hex(len(input))[2:]) margin = 2 + len(hex(len(input))[2:])
# dump # dump
for byte in input: for byte in input:
cool = hex(byte)[2:].zfill(2) cool = hex(byte)[2:].zfill(2)
dump += cool + ' ' dump += cool + ' '
if debug: stream += cool if debug: stream += cool
@ -98,14 +98,14 @@ def get_tiles(image):
def connect(tiles): def connect(tiles):
""" """
Combine 8x8 tiles into a 2bpp image. Combine 8x8 tiles into a 2bpp image.
""" """
out = [] out = []
for tile in tiles: for tile in tiles:
for byte in tile: for byte in tile:
out.append(byte) out.append(byte)
return out return out
def transpose(tiles): def transpose(tiles):
@ -742,15 +742,19 @@ class Decompressed:
flipped = sum(1<<(7-i) for i in range(8) if self.output[self.displacement+byte]>>i&1) flipped = sum(1<<(7-i) for i in range(8) if self.output[self.displacement+byte]>>i&1)
self.output.append(flipped) self.output.append(flipped)
def doReverse(self): def doReverse(self):
"""Repeat reversed bytes from 2bpp output.""" """
for byte in range(self.length): Repeat reversed bytes from 2bpp output.
self.output.append(self.output[self.displacement-byte]) """
for byte in range(self.length):
self.output.append(self.output[self.displacement-byte])
def doRepeat(self): def doRepeat(self):
"""Repeat bytes from 2bpp output.""" """
for byte in range(self.length): Repeat bytes from 2bpp output.
self.output.append(self.output[self.displacement+byte]) """
for byte in range(self.length):
self.output.append(self.output[self.displacement+byte])
@ -1337,7 +1341,7 @@ def to_png(filein, fileout=None, pal_file=None, height=None, width=None):
def to_2bpp(filein, fileout=None, palout=None): def to_2bpp(filein, fileout=None, palout=None):
""" """
Takes a png and converts it to planar 2bpp. Take a png and converts it to planar 2bpp.
""" """
if fileout == None: fileout = '.'.join(filein.split('.')[:-1]) + '.2bpp' if fileout == None: fileout = '.'.join(filein.split('.')[:-1]) + '.2bpp'
@ -1541,7 +1545,7 @@ def append_terminator_to_lzs(directory):
def lz_to_png_by_file(filename): def lz_to_png_by_file(filename):
""" """
Converts a lz file to png. Dumps a 2bpp file too. Convert a lz file to png. Dump a 2bpp file too.
""" """
assert filename[-3:] == ".lz" assert filename[-3:] == ".lz"
lz_data = open(filename, "rb").read() lz_data = open(filename, "rb").read()
@ -1552,7 +1556,7 @@ def lz_to_png_by_file(filename):
def dump_tileset_pngs(): def dump_tileset_pngs():
""" """
Converts .lz format tilesets into .png format tilesets. Convert .lz format tilesets into .png format tilesets.
Also, leaves a bunch of wonderful .2bpp files everywhere for Also, leaves a bunch of wonderful .2bpp files everywhere for
your amusement. your amusement.