diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gfx.py | 38 | ||||
-rw-r--r-- | tools/pokemontools/gfx.py | 39 |
2 files changed, 69 insertions, 8 deletions
diff --git a/tools/gfx.py b/tools/gfx.py index f817b374..36e06010 100644 --- a/tools/gfx.py +++ b/tools/gfx.py @@ -1,6 +1,6 @@ """Supplementary scripts for graphics conversion.""" -import os +import os, re import argparse from pokemontools import gfx, lz @@ -40,8 +40,9 @@ def get_pokemon_dimensions(name): if name.startswith('unown_'): name = 'unown' base_stats = get_base_stats() - # TODO: extra space at end = hack for pidgeot/mew (caught by pidgeotto/mewtwo) - start = base_stats.find('\tdb ' + name.upper() + ' ') + # hack for pidgeot/mew (previously caught by being substrings of pidgeotto/mewtwo) + pattern = re.compile('\s+db {0}\s+'.format(name.upper())) + start = pattern.search(base_stats).start() start = base_stats.find('\tdn ', start) end = base_stats.find('\n', start) line = base_stats[start:end].replace(',', ' ') @@ -82,8 +83,39 @@ def filepath_rules(filepath): args['pic'] = True elif 'gfx/trainers' in filedir: + trainer_name = filedir.split('/')[-1] + args['pal_file'] = os.path.join(filedir, trainer_name + '.pal') args['pic'] = True + elif 'gfx/mail' in filedir: + px8 = ['eon_mail_border_2', 'grass', 'lovely_mail_border', 'lovely_mail_underline', + 'morph_mail_border', 'morph_mail_divider', 'portrail_mail_border', + 'portraitmail_border', 'portraitmail_underline', 'small_heart', 'small_note', + 'small_pokeball', 'small_triangle', 'wave'] + px16 = ['eon_mail_border_1', 'flower_1', 'flower_2', 'large_circle', 'large_heart', + 'large_pokeball', 'large_triangle', 'morph_mail_corner', + 'music_mail_border', 'oddish', 'sentret', 'unused_grass'] + px24 = ['cloud', 'ditto', 'dratini', 'eevee', 'lapras', + 'mew', 'natu', 'poliwag'] + if name in px8: + args['width'] = 8 + elif name in px16: + args['width'] = 16 + elif name in px24: + args['width'] = 24 + + elif name == 'dragonite': + args['width'] = 56 + args['rows'] = [(0, 6), (1, 6), (2, 6)] + + elif name == 'large_note': + args['width'] = 16 + args['rows'] = [(1, 1), (0, 2)] + + elif name in ['surf_mail_border', 'flower_mail_border', 'litebluemail_border']: + args['width'] = 24 + args['whitespace'] = [4] + elif os.path.join(filedir, name) in pics: args['pic'] = True diff --git a/tools/pokemontools/gfx.py b/tools/pokemontools/gfx.py index 1beb5446..97e4d838 100644 --- a/tools/pokemontools/gfx.py +++ b/tools/pokemontools/gfx.py @@ -426,6 +426,8 @@ def convert_2bpp_to_png(image, **kwargs): pic_dimensions = kwargs.get('pic_dimensions', None) pal_file = kwargs.get('pal_file', None) interleave = kwargs.get('interleave', False) + rows = kwargs.get('rows', None) + whitespace = kwargs.get('whitespace', None) # Width must be specified to interleave. if interleave and width: @@ -454,13 +456,39 @@ def convert_2bpp_to_png(image, **kwargs): def px_length(img): return len(img) * 4 def tile_length(img): - return len(img) * 4 / (8*8) + return len(img) * 4 // (8*8) if width and height: - tile_width = width / 8 + tile_width = width // 8 more_tile_padding = (tile_width - (tile_length(image) % tile_width or tile_width)) image += pad_color * 0x10 * more_tile_padding + elif width and rows: + newimage = bytearray([]) + padding = bytearray([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) + height = len(rows) * 8 + cur_index = 0 + for offset, tile_width in rows: + for x in range(0, offset): + newimage += padding + next_index = min(len(image),cur_index+ 0x10*tile_width) + newimage += image[cur_index:next_index] + cur_index = next_index + row_padding = max(0, width//8 - offset - tile_width) + for x in range(0, row_padding): + newimage += padding + image = newimage + + elif width and whitespace: + padding = bytearray([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) + cur_offset = 0 + cur_idx = 0 + for idx in whitespace: + next_offset = cur_offset + 0x10*(idx-cur_idx) + image = image[cur_offset:next_offset] + padding + image[next_offset:] + cur_offset = next_offset + 0x10 + cur_idx = idx + elif width and not height: tile_width = width // 8 more_tile_padding = (tile_width - (tile_length(image) % tile_width or tile_width)) @@ -468,7 +496,7 @@ def convert_2bpp_to_png(image, **kwargs): height = px_length(image) / width elif height and not width: - tile_height = height / 8 + tile_height = height // 8 more_tile_padding = (tile_height - (tile_length(image) % tile_height or tile_height)) image += pad_color * 0x10 * more_tile_padding width = px_length(image) / height @@ -820,12 +848,13 @@ def export_1bpp_to_2bpp(filename): to_file(name + '.2bpp', image) -def export_1bpp_to_png(filename, fileout=None): +def export_1bpp_to_png(filename, fileout=None, **arguments): if fileout == None: fileout = os.path.splitext(filename)[0] + '.png' - arguments = read_filename_arguments(filename) + if arguments is None : + arguments = read_filename_arguments(filename) image = io.open(filename, 'rb').read() image = convert_1bpp_to_2bpp(image) |