mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 13:03:13 +00:00
eb31fed0e2
* Desktop: slideshow implementation * Updater: handling splashscreen installation; added format version field to slideshow binary * Desktop: added bidirectional slideshow navigation + instant cancel by "back" button; Updater: rebalanced update stages weights * Updater: fixed missing field init; fixed potential loop when baking slideshows * Assets: fixed "update complete" image to match original * Desktop: added check for slideshow file version * Scripts: slideshow.py cleanup * Desktop: removed first start intro sequence * Desktop: removed first start remnants
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import struct
|
|
|
|
from flipper.app import App
|
|
from flipper.assets.icon import file2image
|
|
|
|
|
|
class Main(App):
|
|
MAGIC = 0x72676468
|
|
VERSION = 1
|
|
|
|
def init(self):
|
|
self.parser.add_argument("-i", "--input", help="input folder", required=True)
|
|
self.parser.add_argument("-o", "--output", help="output file", required=True)
|
|
|
|
self.parser.set_defaults(func=self.pack)
|
|
|
|
def pack(self):
|
|
if not os.path.exists(self.args.input):
|
|
self.logger.error(f'"{self.args.input}" does not exist')
|
|
return 1
|
|
|
|
file_idx = 0
|
|
images = []
|
|
while True:
|
|
frame_filename = os.path.join(self.args.input, f"frame_{file_idx:02}.png")
|
|
if not os.path.exists(frame_filename):
|
|
break
|
|
|
|
self.logger.debug(f"working on {frame_filename}")
|
|
try:
|
|
images.append(file2image(frame_filename))
|
|
self.logger.debug(f"Processed frame #{file_idx}")
|
|
file_idx += 1
|
|
except Exception as e:
|
|
self.logger.error(e)
|
|
break
|
|
|
|
widths = set(img.width for img in images)
|
|
heights = set(img.height for img in images)
|
|
if len(widths) != 1 or len(heights) != 1:
|
|
self.logger.error("All images must have same dimensions!")
|
|
return 2
|
|
|
|
data = struct.pack(
|
|
"<IBBBB", self.MAGIC, self.VERSION, widths.pop(), heights.pop(), len(images)
|
|
)
|
|
for image in images:
|
|
data += struct.pack("<H", len(image.data))
|
|
data += image.data
|
|
|
|
with open(self.args.output, mode="wb") as file:
|
|
file.write(data)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
Main()()
|