Skip to content

Commit

Permalink
Merge pull request #55 from PixlEmly/unleashed
Browse files Browse the repository at this point in the history
Poker updates, script updates
  • Loading branch information
RogueMaster authored Jun 16, 2022
2 parents 33d5275 + 9867e00 commit ddfe8c8
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 152 deletions.
249 changes: 107 additions & 142 deletions applications/VideoPoker/poker.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion applications/applications.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,4 +699,4 @@ const FlipperApplication FLIPPER_SETTINGS_APPS[] = {
#endif
};

const size_t FLIPPER_SETTINGS_APPS_COUNT = COUNT_OF(FLIPPER_SETTINGS_APPS);
const size_t FLIPPER_SETTINGS_APPS_COUNT = COUNT_OF(FLIPPER_SETTINGS_APPS);
2 changes: 1 addition & 1 deletion applications/applications.mk
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,4 @@ endif
SRV_STORAGE ?= 0
ifeq ($(SRV_STORAGE), 1)
CFLAGS += -DSRV_STORAGE
endif
endif
58 changes: 52 additions & 6 deletions scripts/User/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,69 @@
#####################################
encode.py
decode.py
iconencode.py
icondecode.py

A set of python3 scripts for processing the Flipper image files.
These work as-is but I am rolling in improvements.
#####################################
PREREQUISITES


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.py input_image output_image [width] [height]
Dimensions are not stored in .bm so you need to specify.
If you do not enter anything here it will assume 128x64. THIS WILL NOT ALWAYS BE CORRECT.
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.
It may also be part of the directory name for the animation files as well.

If you do not enter anything here it will assume 128x64. THIS WILL NOT ALWAYS BE CORRECT.

##
# encode
Encode an .xbm file into .xb
encode.py input_image output_image
That's it.
You will also get the image dimensions for use in meta.txt
That's it.

##
# iconencode
Compress an icon asset from an XBM to a compressed char array ready to paste
Will assume dimensions of 128x64
Header works like this, you'll have to do this manually for now!

Image Header Format Example
0x01 = Compressed
0x00 = Reserved Section
0xa4,0x01 = 0x1a4, or, 420 - the size of the compressed array, minus this header. Just count the commas ;)
Rest of the data is char array output from heatshrink of the original XBM char array.
Calculated Header: 0x01,0x00,0xa4,0x01
from furi_hal_compress.c:
typedef struct {
uint8_t is_compressed;
uint8_t reserved;
uint16_t compressed_buff_size;
} FuriHalCompressHeader;


##
# icondecode
Decompress an icon asset (as found in assets_icons.c and elsewhere)
icondecodepy input_image output_image [trim] [width] [height]
The icons in this file have a different header format. This will need to be trimmed.
A value of 8 for trim appears to be correct.
As with regular decoding, the width and height are not listed - but can be found in code/const/variable/etc names.
copy just the char array. The script does not care if the curly braces or semicolon are in place.
i.e. the following are all acceptable and equivalent.
{0x00,0x08,0x1C,0x3E,0x7F,};
{0x00,0x08,0x1C,0x3E,0x7F,}
0x00,0x08,0x1C,0x3E,0x7F

6 changes: 4 additions & 2 deletions scripts/User/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def padded_hex(i, l):
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')
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')
help='Height of the image. Find from meta.txt or directory name')

args = vars(parser.parse_args())

Expand Down Expand Up @@ -70,3 +70,5 @@ def padded_hex(i, l):
data=width_out+height_out+bytes_out

w.write(data)
r.close()
w.close()
6 changes: 6 additions & 0 deletions scripts/User/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

output = subprocess.check_output(["cat", args["infile"]])
f = io.StringIO(output.decode().strip())
print("Image Dimensions:")
width = int(f.readline().strip().split(" ")[2])
print("W: ", width)
height = int(f.readline().strip().split(" ")[2])
print("H: ", height)


data = f.read().strip().replace("\n", "").replace(" ", "").split("=")[1][:-1]
data_str = data[1:-1].replace(",", " ").replace("0x", "")
Expand All @@ -41,3 +45,5 @@
else:
data = b"\x00" + data_bin
w.write(data)
r.close()
w.close()
65 changes: 65 additions & 0 deletions scripts/User/icondecode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import logging
import argparse
import subprocess
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
num_hex_chars = len(hex_result)
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)


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.')
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.
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
)

b=list(data_decoded_str)

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) + "};"

data=width_out+height_out+bytes_out

w.write(data)
r.close()
w.close()
68 changes: 68 additions & 0 deletions scripts/User/iconencode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import logging
import argparse
import subprocess
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
num_hex_chars = len(hex_result)
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)


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')
args = vars(parser.parse_args())

r = open(args["infile"],"r")
infile=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.
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
)

b=list(data_encoded_str)

c=','.join(padded_hex(my_int,2) for my_int in b)

# a bit ugly.

framename="_I_"+infile+"_"+dims
print(len(b))
#d=len(b)
# if b > 255 split 0x1234 into 0x34,0x12
#d=hex(len(b))

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()

0 comments on commit ddfe8c8

Please sign in to comment.