mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Update user scripts
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import logging
|
||||
import heatshrink2
|
||||
import argparse
|
||||
import subprocess
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -15,12 +12,10 @@ parser.add_argument("outfile", metavar="o", help="File to write to")
|
||||
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
r = open(args["infile"], "r")
|
||||
w = open(args["outfile"], "wb")
|
||||
|
||||
|
||||
output = subprocess.check_output(["cat", args["infile"]])
|
||||
with open(args["infile"], "rb") as f:
|
||||
output = f.read()
|
||||
f = io.StringIO(output.decode().strip())
|
||||
|
||||
print("Image Dimensions:")
|
||||
width = int(f.readline().strip().split(" ")[2])
|
||||
print("W: ", width)
|
||||
@@ -30,20 +25,16 @@ print("H: ", height)
|
||||
|
||||
data = f.read().strip().replace("\n", "").replace(" ", "").split("=")[1][:-1]
|
||||
data_str = data[1:-1].replace(",", " ").replace("0x", "")
|
||||
|
||||
data_bin = bytearray.fromhex(data_str)
|
||||
data_encoded_str = subprocess.check_output(
|
||||
["heatshrink", "-e", "-w8", "-l4"], input=data_bin
|
||||
)
|
||||
|
||||
assert data_encoded_str
|
||||
|
||||
data_encoded_str = heatshrink2.compress(data_bin, window_sz2=8, lookahead_sz2=4)
|
||||
data_enc = bytearray(data_encoded_str)
|
||||
data_enc = bytearray([len(data_enc) & 0xFF, len(data_enc) >> 8]) + data_enc
|
||||
if len(data_enc) < len(data_bin) + 1:
|
||||
|
||||
if len(data_enc) + 2 < len(data_bin) + 1:
|
||||
data = b"\x01\x00" + data_enc
|
||||
else:
|
||||
data = b"\x00" + data_bin
|
||||
w.write(data)
|
||||
r.close()
|
||||
w.close()
|
||||
|
||||
with open(args["outfile"], "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
Reference in New Issue
Block a user