This commit is contained in:
Willy-JL
2023-02-02 21:38:45 +00:00
parent 651548913e
commit e33023463a
50 changed files with 336 additions and 256 deletions
+54 -38
View File
@@ -6,69 +6,85 @@ import os
import sys
def padded_hex(i, l):
given_int = i
given_len = l
hex_result = hex(given_int)[2:] # remove '0x' from beginning of str
hex_result = hex(given_int)[2:] # remove '0x' from beginning of str
num_hex_chars = len(hex_result)
extra_zeros = '0' * (given_len - num_hex_chars) # may not get used..
extra_zeros = "0" * (given_len - num_hex_chars) # may not get used..
return ('0x' + hex_result if num_hex_chars == given_len else
'?' * given_len if num_hex_chars > given_len else
'0x' + extra_zeros + hex_result if num_hex_chars < given_len else
None)
return (
"0x" + hex_result
if num_hex_chars == given_len
else "?" * given_len
if num_hex_chars > given_len
else "0x" + extra_zeros + hex_result
if num_hex_chars < given_len
else None
)
parser = argparse.ArgumentParser(description='Turn cooked Flipper .bm files back into .xbm')
parser.add_argument('infile', metavar='i',
help='Input file')
parser.add_argument('outfile', metavar='o',
help='File to write to')
parser.add_argument('Width', metavar='W', type=int, nargs="?", default="128",
help='Width of the image. Find from meta.txt or directory name')
parser.add_argument('Height', metavar='H', type=int, nargs="?", default="64",
help='Height of the image. Find from meta.txt or directory name')
parser = argparse.ArgumentParser(
description="Turn cooked Flipper .bm files back into .xbm"
)
parser.add_argument("infile", metavar="i", help="Input file")
parser.add_argument("outfile", metavar="o", help="File to write to")
parser.add_argument(
"Width",
metavar="W",
type=int,
nargs="?",
default="128",
help="Width of the image. Find from meta.txt or directory name",
)
parser.add_argument(
"Height",
metavar="H",
type=int,
nargs="?",
default="64",
help="Height of the image. Find from meta.txt or directory name",
)
args = vars(parser.parse_args())
r = open(args["infile"],"rb")
w = open(args["outfile"],"w")
r = open(args["infile"], "rb")
w = open(args["outfile"], "w")
fileStream=r.read()
filename=os.path.splitext(os.path.basename(args["outfile"]))[0]
fileStream = r.read()
filename = os.path.splitext(os.path.basename(args["outfile"]))[0]
imageWidth=args["Width"]
imageHeight=args["Height"]
imageWidth = args["Width"]
imageHeight = args["Height"]
#remove headers and padding
if(fileStream[0:2] == bytes([0x01,0x00])):
unpad=fileStream[4:]
# remove headers and padding
if fileStream[0:2] == bytes([0x01, 0x00]):
unpad = fileStream[4:]
else:
if(fileStream[0:1] == bytes([0x00])):
unpad=fileStream[2:]
if fileStream[0:1] == bytes([0x00]):
unpad = fileStream[2:]
#lzss decompress
# lzss decompress
data_decoded_str = subprocess.check_output(
["heatshrink", "-d","-w8","-l4"], input=unpad
["heatshrink", "-d", "-w8", "-l4"], input=unpad
)
#turn it back into xbm
# turn it back into xbm
b=list(data_decoded_str)
c=', '.join(padded_hex(my_int,2) for my_int in b)
b = list(data_decoded_str)
c = ", ".join(padded_hex(my_int, 2) for my_int in b)
width_out = "#define "+ filename+ "_width "+ str(imageWidth) + "\n"
height_out = "#define "+ filename+ "_height "+ str(imageHeight) + "\n"
bytes_out = "static unsigned char "+ filename+ "_bits[] = {"+ str(c) + "};"
width_out = "#define " + filename + "_width " + str(imageWidth) + "\n"
height_out = "#define " + filename + "_height " + str(imageHeight) + "\n"
bytes_out = "static unsigned char " + filename + "_bits[] = {" + str(c) + "};"
data=width_out+height_out+bytes_out
data = width_out + height_out + bytes_out
w.write(data)
r.close()
w.close()
w.close()
+7 -7
View File
@@ -6,17 +6,17 @@ import os
import sys
parser = argparse.ArgumentParser(description='Turn .xbm files into cooked .bm files for flipper FS')
parser = argparse.ArgumentParser(
description="Turn .xbm files into cooked .bm files for flipper FS"
)
parser.add_argument('infile', metavar='i',
help='Input file')
parser.add_argument('outfile', metavar='o',
help='File to write to')
parser.add_argument("infile", metavar="i", help="Input file")
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")
r = open(args["infile"], "r")
w = open(args["outfile"], "wb")
output = subprocess.check_output(["cat", args["infile"]])
+53 -31
View File
@@ -5,60 +5,82 @@ import io
import os
import sys
def padded_hex(i, l):
given_int = i
given_len = l
hex_result = hex(given_int)[2:] # remove '0x' from beginning of str
hex_result = hex(given_int)[2:] # remove '0x' from beginning of str
num_hex_chars = len(hex_result)
extra_zeros = '0' * (given_len - num_hex_chars) # may not get used..
extra_zeros = "0" * (given_len - num_hex_chars) # may not get used..
return ('0x' + hex_result if num_hex_chars == given_len else
'?' * given_len if num_hex_chars > given_len else
'0x' + extra_zeros + hex_result if num_hex_chars < given_len else
None)
return (
"0x" + hex_result
if num_hex_chars == given_len
else "?" * given_len
if num_hex_chars > given_len
else "0x" + extra_zeros + hex_result
if num_hex_chars < given_len
else None
)
parser = argparse.ArgumentParser(description='Turn icon char arrays back into .xbm')
parser = argparse.ArgumentParser(description="Turn icon char arrays back into .xbm")
parser.add_argument('infile', metavar='i',
help='Input file')
parser.add_argument('outfile', metavar='o',
help='File to write to')
parser.add_argument('Width', metavar='W', type=int, nargs="?", default="128",
help='Width of the image. Find from meta.txt or directory name')
parser.add_argument('Height', metavar='H', type=int, nargs="?", default="64",
help='Height of the image. Find from meta.txt or directory name')
parser.add_argument('Trim', metavar='T', type=int, nargs="?", default="8",
help='Number of bytes off the start/header to trim. Multiples of 2 required.')
parser.add_argument("infile", metavar="i", help="Input file")
parser.add_argument("outfile", metavar="o", help="File to write to")
parser.add_argument(
"Width",
metavar="W",
type=int,
nargs="?",
default="128",
help="Width of the image. Find from meta.txt or directory name",
)
parser.add_argument(
"Height",
metavar="H",
type=int,
nargs="?",
default="64",
help="Height of the image. Find from meta.txt or directory name",
)
parser.add_argument(
"Trim",
metavar="T",
type=int,
nargs="?",
default="8",
help="Number of bytes off the start/header to trim. Multiples of 2 required.",
)
args = vars(parser.parse_args())
r = open(args["infile"],"r")
w = open(args["outfile"],"w")
imageWidth=args["Width"]
imageHeight=args["Height"]
trimStart=args["Trim"]
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.
output = subprocess.check_output(["cat", args["infile"]]) # yes this is terrible.
f = io.StringIO(output.decode().strip())
data = f.read().strip().replace(";","").replace("{","").replace("}","")
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
["heatshrink", "-d", "-w8", "-l4"], input=data_bin
)
b=list(data_decoded_str)
b = list(data_decoded_str)
c=', '.join(padded_hex(my_int,2) for my_int in b)
c = ", ".join(padded_hex(my_int, 2) for my_int in b)
width_out = "#define icon_width "+ str(imageWidth) + "\n"
height_out = "#define icon_height "+ str(imageHeight) + "\n"
bytes_out = "static unsigned char icon_bits[] = {"+ str(c) + "};"
width_out = "#define icon_width " + str(imageWidth) + "\n"
height_out = "#define icon_height " + str(imageHeight) + "\n"
bytes_out = "static unsigned char icon_bits[] = {" + str(c) + "};"
data=width_out+height_out+bytes_out
data = width_out + height_out + bytes_out
w.write(data)
r.close()
+48 -31
View File
@@ -5,64 +5,81 @@ import io
import os
import sys
def padded_hex(i, l):
given_int = i
given_len = l
hex_result = hex(given_int)[2:] # remove '0x' from beginning of str
hex_result = hex(given_int)[2:] # remove '0x' from beginning of str
num_hex_chars = len(hex_result)
extra_zeros = '0' * (given_len - num_hex_chars) # may not get used..
extra_zeros = "0" * (given_len - num_hex_chars) # may not get used..
return ('0x' + hex_result if num_hex_chars == given_len else
'?' * given_len if num_hex_chars > given_len else
'0x' + extra_zeros + hex_result if num_hex_chars < given_len else
None)
return (
"0x" + hex_result
if num_hex_chars == given_len
else "?" * given_len
if num_hex_chars > given_len
else "0x" + extra_zeros + hex_result
if num_hex_chars < given_len
else None
)
parser = argparse.ArgumentParser(description='Turn icon char arrays back into .xbm')
parser = argparse.ArgumentParser(description="Turn icon char arrays back into .xbm")
parser.add_argument('infile', metavar='i',
help='Input file')
parser.add_argument('Width', metavar='W', type=int, nargs="?", default="128",
help='Width of the image. Find from meta.txt or directory name')
parser.add_argument('Height', metavar='H', type=int, nargs="?", default="64",
help='Height of the image. Find from meta.txt or directory name')
parser.add_argument("infile", metavar="i", help="Input file")
parser.add_argument(
"Width",
metavar="W",
type=int,
nargs="?",
default="128",
help="Width of the image. Find from meta.txt or directory name",
)
parser.add_argument(
"Height",
metavar="H",
type=int,
nargs="?",
default="64",
help="Height of the image. Find from meta.txt or directory name",
)
args = vars(parser.parse_args())
r = open(args["infile"],"r")
infile=args["infile"].split(".")[0]
r = open(args["infile"], "r")
infile = args["infile"].split(".")[0]
imageWidth=args["Width"]
imageHeight=args["Height"]
dims=str(imageWidth)+"x"+str(imageHeight)
imageWidth = args["Width"]
imageHeight = args["Height"]
dims = str(imageWidth) + "x" + str(imageHeight)
output = subprocess.check_output(["cat", args["infile"]]) #yes this is terrible.
output = subprocess.check_output(["cat", args["infile"]]) # yes this is terrible.
f = io.StringIO(output.decode().strip())
data = f.read().strip().replace(";","").replace("{","").replace("}","")
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
["heatshrink", "-e", "-w8", "-l4"], input=data_bin
)
b=list(data_encoded_str)
b = list(data_encoded_str)
c=','.join(padded_hex(my_int,2) for my_int in b)
c = ",".join(padded_hex(my_int, 2) for my_int in b)
# a bit ugly.
framename="_I_"+infile+"_"+dims
framename = "_I_" + infile + "_" + dims
print(len(b))
#d=len(b)
# d=len(b)
# if b > 255 split 0x1234 into 0x34,0x12
#d=hex(len(b))
# d=hex(len(b))
char_out = "const uint8_t "+framename+"_0[] = {"+ str(c) + ",};"
char_out2 = "const uint8_t "+framename+"[] = {"+framename+"_0};"
#data=bytes_out
char_out = "const uint8_t " + framename + "_0[] = {" + str(c) + ",};"
char_out2 = "const uint8_t " + framename + "[] = {" + framename + "_0};"
# data=bytes_out
print(char_out)
print(char_out2)
#w.write(data)
#w.close()
# w.write(data)
# w.close()