From 04e23a8d56ba60ac75d70493197335ac5b394f00 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Thu, 23 Nov 2023 00:14:10 -0500 Subject: [PATCH] Refactor tools/dupeframes.py --- tools/dupeframes.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/dupeframes.py b/tools/dupeframes.py index 0aba707e6f6..0799bdc4591 100755 --- a/tools/dupeframes.py +++ b/tools/dupeframes.py @@ -12,7 +12,7 @@ import png -def check_duplicate_frames(filename): +def duplicate_frames(filename): with open(filename, 'rb') as file: width, height, rows = png.Reader(file).asRGBA8()[:3] rows = list(rows) @@ -21,14 +21,12 @@ def check_duplicate_frames(filename): 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) + 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')): - check_duplicate_frames(filename) + for (i, j) in duplicate_frames(filename): + print(f'{filename}: frame {j} is a duplicate of frame {i}', file=sys.stderr) if __name__ == '__main__': main()