From df05357a4d72357342c4c1baa3a1f7dde7a83974 Mon Sep 17 00:00:00 2001 From: Rangi Date: Tue, 15 Aug 2023 19:34:16 -0400 Subject: [PATCH] =?UTF-8?q?Add=20dupeframes.py=20tool=20to=20find=20duplic?= =?UTF-8?q?ate=20animated=20Pok=C3=A9mon=20frames?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1067 --- tools/dupeframes.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 tools/dupeframes.py diff --git a/tools/dupeframes.py b/tools/dupeframes.py new file mode 100755 index 000000000..0aba707e6 --- /dev/null +++ b/tools/dupeframes.py @@ -0,0 +1,34 @@ +#!/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 + +def check_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)] + for i in range(num_frames): + for j in range(i + 1, num_frames): + if frames[i] == frames[j]: + print(f'{filename}: frame {j} is a duplicate of frame {i}', file=sys.stderr) + +def main(): + for filename in sorted(glob.glob('gfx/pokemon/*/front.png')): + check_duplicate_frames(filename) + +if __name__ == '__main__': + main()