mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-01 22:08:55 -07:00
Update user scripts
This commit is contained in:
+2
-11
@@ -6,20 +6,11 @@ icondecode.py
|
||||
|
||||
A set of python3 scripts for processing the Flipper image files.
|
||||
These work as-is but I am rolling in improvements.
|
||||
#####################################
|
||||
PREREQUISITES
|
||||
|
||||
|
||||
You'll need heatshrink installed - a small embedded/RTOS compression and decompression library
|
||||
You can get that here https://github.com/atomicobject/heatshrink
|
||||
|
||||
#####################################
|
||||
HOW TO USE
|
||||
|
||||
##
|
||||
# decode.
|
||||
|
||||
Decode a .mb into .xbm:
|
||||
Decode a .bm into .xbm:
|
||||
decode.py input_image output_image [width] [height]
|
||||
Dimensions are not stored in .bm so you need to specify
|
||||
If you have the meta.txt available for the animation set the dimensions will be in here.
|
||||
@@ -29,7 +20,7 @@ If you do not enter anything here it will assume 128x64. THIS WILL NOT ALWAYS BE
|
||||
|
||||
##
|
||||
# encode
|
||||
Encode an .xbm file into .xb
|
||||
Encode an .xbm file into .bm
|
||||
encode.py input_image output_image
|
||||
You will also get the image dimensions for use in meta.txt
|
||||
That's it.
|
||||
|
||||
+6
-14
@@ -1,9 +1,6 @@
|
||||
import logging
|
||||
import heatshrink2
|
||||
import argparse
|
||||
import subprocess
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def padded_hex(i, l):
|
||||
@@ -50,10 +47,8 @@ parser.add_argument(
|
||||
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
r = open(args["infile"], "rb")
|
||||
w = open(args["outfile"], "w")
|
||||
|
||||
fileStream = r.read()
|
||||
with open(args["infile"], "rb") as f:
|
||||
fileStream = f.read()
|
||||
filename = os.path.splitext(os.path.basename(args["outfile"]))[0]
|
||||
|
||||
|
||||
@@ -70,9 +65,7 @@ else:
|
||||
|
||||
|
||||
# lzss decompress
|
||||
data_decoded_str = subprocess.check_output(
|
||||
["heatshrink", "-d", "-w8", "-l4"], input=unpad
|
||||
)
|
||||
data_decoded_str = heatshrink2.decompress(unpad, window_sz2=8, lookahead_sz2=4)
|
||||
|
||||
# turn it back into xbm
|
||||
|
||||
@@ -85,6 +78,5 @@ bytes_out = "static unsigned char " + filename + "_bits[] = {" + str(c) + "};"
|
||||
|
||||
data = width_out + height_out + bytes_out
|
||||
|
||||
w.write(data)
|
||||
r.close()
|
||||
w.close()
|
||||
with open(args["outfile"], "w") as f:
|
||||
f.write(data)
|
||||
|
||||
+10
-19
@@ -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)
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import logging
|
||||
import heatshrink2
|
||||
import argparse
|
||||
import subprocess
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def padded_hex(i, l):
|
||||
@@ -55,22 +52,19 @@ parser.add_argument(
|
||||
)
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
r = open(args["infile"], "r")
|
||||
w = open(args["outfile"], "w")
|
||||
imageWidth = args["Width"]
|
||||
imageHeight = args["Height"]
|
||||
trimStart = args["Trim"]
|
||||
|
||||
output = subprocess.check_output(["cat", args["infile"]]) # yes this is terrible.
|
||||
with open(args["infile"], "rb") as f:
|
||||
output = f.read()
|
||||
f = io.StringIO(output.decode().strip())
|
||||
|
||||
data = f.read().strip().replace(";", "").replace("{", "").replace("}", "")
|
||||
data_str = data.replace(",", "").replace("0x", "")
|
||||
data_bin = bytearray.fromhex(data_str[trimStart:])
|
||||
|
||||
data_decoded_str = subprocess.check_output(
|
||||
["heatshrink", "-d", "-w8", "-l4"], input=data_bin
|
||||
)
|
||||
data_decoded_str = heatshrink2.decompress(data_bin, window_sz2=8, lookahead_sz2=4)
|
||||
|
||||
b = list(data_decoded_str)
|
||||
|
||||
@@ -82,6 +76,5 @@ bytes_out = "static unsigned char icon_bits[] = {" + str(c) + "};"
|
||||
|
||||
data = width_out + height_out + bytes_out
|
||||
|
||||
w.write(data)
|
||||
r.close()
|
||||
w.close()
|
||||
with open(args["outfile"], "w") as f:
|
||||
f.write(data)
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import logging
|
||||
import heatshrink2
|
||||
import argparse
|
||||
import subprocess
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def padded_hex(i, l):
|
||||
@@ -46,23 +43,21 @@ parser.add_argument(
|
||||
)
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
r = open(args["infile"], "r")
|
||||
infile = args["infile"].split(".")[0]
|
||||
filename = args["infile"].split(".")[0]
|
||||
|
||||
imageWidth = args["Width"]
|
||||
imageHeight = args["Height"]
|
||||
dims = str(imageWidth) + "x" + str(imageHeight)
|
||||
|
||||
output = subprocess.check_output(["cat", args["infile"]]) # yes this is terrible.
|
||||
with open(args["infile"], "rb") as f:
|
||||
output = f.read()
|
||||
f = io.StringIO(output.decode().strip())
|
||||
|
||||
data = f.read().strip().replace(";", "").replace("{", "").replace("}", "")
|
||||
data_str = data.replace(",", "").replace("0x", "")
|
||||
data_bin = bytearray.fromhex(data_str)
|
||||
|
||||
data_encoded_str = subprocess.check_output(
|
||||
["heatshrink", "-e", "-w8", "-l4"], input=data_bin
|
||||
)
|
||||
data_encoded_str = heatshrink2.compress(data_bin, window_sz2=8, lookahead_sz2=4)
|
||||
|
||||
b = list(data_encoded_str)
|
||||
|
||||
@@ -70,7 +65,7 @@ c = ",".join(padded_hex(my_int, 2) for my_int in b)
|
||||
|
||||
# a bit ugly.
|
||||
|
||||
framename = "_I_" + infile + "_" + dims
|
||||
framename = "_I_" + filename + "_" + dims
|
||||
print(len(b))
|
||||
# d=len(b)
|
||||
# if b > 255 split 0x1234 into 0x34,0x12
|
||||
|
||||
Reference in New Issue
Block a user