pokecrystal-board/tools/dupeframes.py

33 lines
886 B
Python
Raw Normal View History

2023-07-26 17:50:16 -07:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Usage: python dupeframes.py
Check for duplicate frames in Pokemon sprites (gfx/pokemon/*/front.png).
"""
import sys
import glob
import png
2023-11-22 21:14:10 -08:00
def duplicate_frames(filename):
2023-07-26 17:50:16 -07:00
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)]
2023-11-22 21:14:10 -08:00
yield from ((i, j) for i in range(num_frames) for j in range(i+1, num_frames) if frames[i] == frames[j])
2023-07-26 17:50:16 -07:00
def main():
for filename in sorted(glob.glob('gfx/pokemon/*/front.png')):
2023-11-22 21:14:10 -08:00
for (i, j) in duplicate_frames(filename):
print(f'{filename}: frame {j} is a duplicate of frame {i}', file=sys.stderr)
2023-07-26 17:50:16 -07:00
if __name__ == '__main__':
main()