pret / pokecrystal

Disassembly of Pokémon Crystal
https://pret.github.io/pokecrystal/
2.06k stars 770 forks source link

Refactor tools/dupeframes.py #1080

Closed Rangi42 closed 8 months ago

Rangi42 commented 11 months ago
def duplicate_frames(filename):
    with open(filename, 'rb') as file:
        width, height, rows = png.Reader(file).asRGBA8()[:3]
        rows = list(rows)
    if height % width:
        print(f'{filename} is not a vertical strip of square frames!', file=sys.stderr)
        return
    num_frames = height // width
    frames = [rows[i*width:(i+1)*width] for i in range(num_frames)]
    yield from ((i, j) for i in range(num_frames) for j in range(i+1, num_frames) if frames[i] == frames[j])

def main():
    for filename in sorted(glob.glob('gfx/pokemon/*/front.png')):
        for (i, j) in duplicate_frames(filename):
            print(f'{filename}: frame {j} is a duplicate of frame {i}', file=sys.stderr)
mid-kid commented 10 months ago

what?

Rangi42 commented 10 months ago

Compare this to the current dupeframes.py. It's an inconsequential edit mainly to reduce nesting and use my aesthetically-preferred yield from; just made an issue here so I'll eventually remember it.