From bd70b17cd64af4678984549747898c4dd95fcc18 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 6 Aug 2022 21:59:46 +1000 Subject: [PATCH] Correct rotation for animations --- Bootup Logos/img2logo.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Bootup Logos/img2logo.py b/Bootup Logos/img2logo.py index 012bb19..54b8761 100755 --- a/Bootup Logos/img2logo.py +++ b/Bootup Logos/img2logo.py @@ -117,7 +117,7 @@ def get_screen_blob(previous_frame: bytearray, this_frame: bytearray): return outputData -def animated_image_to_bytes(imageIn: Image, negative: bool, dither: bool, threshold: int): +def animated_image_to_bytes(imageIn: Image, negative: bool, dither: bool, threshold: int, flip_frames): """ Convert the gif into our best effort startup animation We are delta-encoding on a byte by byte basis @@ -136,6 +136,8 @@ def animated_image_to_bytes(imageIn: Image, negative: bool, dither: bool, thresh for framenum in range(0, imageIn.n_frames): imageIn.seek(framenum) image = imageIn + if flip_frames: + image = image.rotate(180) frameb = still_image_to_bytes(image, negative, dither, threshold, None) frameData.append(frameb) @@ -218,12 +220,12 @@ def img2hex( image = Image.open(input_filename) except BaseException as e: raise IOError('error reading image file "{}": {}'.format(input_filename, e)) - if flip: - image = image.rotate(180) if getattr(image, "is_animated", False): - data = animated_image_to_bytes(image, negative, dither, threshold) + data = animated_image_to_bytes(image, negative, dither, threshold,flip) else: + if flip: + image = image.rotate(180) # magic/required header data = [DATA_PROGRAMMED_MARKER, 0x00] # Timing value of 0 image_bytes = still_image_to_bytes(image, negative, dither, threshold, preview_filename)