Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poker updates, script updates #55

Merged
merged 102 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
ed6b23b
Improve directions on how to find dimensions, which are kinda importa…
PixlEmly Jun 3, 2022
9b6a6a2
Merge branch 'unleashed' of https://github.com/PixlEmly/flipperzero-f…
PixlEmly Jun 3, 2022
f0310aa
encode will print out image dimensions
PixlEmly Jun 3, 2022
3e3e917
Merge branch 'RogueMaster:unleashed' into unleashed
PixlEmly Jun 3, 2022
11f4166
Update ReadMe.md
PixlEmly Jun 3, 2022
d2b01dd
QOL
PixlEmly Jun 3, 2022
a46663f
Merge branch 'unleashed' of https://github.com/PixlEmly/flipperzero-f…
PixlEmly Jun 3, 2022
5456f5c
New: decoder for heatshrunk char array icons.
PixlEmly Jun 4, 2022
a172bef
help info
PixlEmly Jun 4, 2022
831b5b0
re-arrange params
PixlEmly Jun 4, 2022
a09acc5
QOL
PixlEmly Jun 4, 2022
6bdf24d
Update ReadMe.md
PixlEmly Jun 4, 2022
d3eb86d
icon encoder added
PixlEmly Jun 4, 2022
4cc1520
Merge branch 'unleashed' of https://github.com/PixlEmly/flipperzero-f…
PixlEmly Jun 4, 2022
b7af240
s
PixlEmly Jun 4, 2022
40cc775
cleanup
PixlEmly Jun 4, 2022
cb27c8c
Update ReadMe.md
PixlEmly Jun 4, 2022
ea0bca1
Update ReadMe.md
PixlEmly Jun 5, 2022
cc71790
Update ReadMe.md
PixlEmly Jun 5, 2022
78f8f27
I can't count
PixlEmly Jun 6, 2022
5adddb8
box tutorial
PixlEmly Jun 9, 2022
0c6fcbb
Box Mover but added stuff
PixlEmly Jun 9, 2022
63f9b7e
Improved bounds checks
PixlEmly Jun 9, 2022
3a6430d
Video Poker game
PixlEmly Jun 9, 2022
4e51aef
Merge branch 'RogueMaster:unleashed' into unleashed
PixlEmly Jun 9, 2022
c6b91e9
Box Mover Splash Screen!
PixlEmly Jun 10, 2022
cfad248
Merge branch 'unleashed' of https://github.com/PixlEmly/flipperzero-f…
PixlEmly Jun 10, 2022
50b591d
Update README.md
PixlEmly Jun 10, 2022
e9ae930
Update README.md
PixlEmly Jun 10, 2022
7592fa5
Merge branch 'RogueMaster:unleashed' into unleashed
PixlEmly Jun 10, 2022
815d687
Update README.md
PixlEmly Jun 10, 2022
69bf5d0
INITIAL Video Poker - it works! It's messy!
PixlEmly Jun 13, 2022
e82d5cb
Still a bit messy. But it seems to be good now.
PixlEmly Jun 13, 2022
1e9c301
Still a bit messy. But it seems to be good now.
PixlEmly Jun 13, 2022
d58b183
Merge branch 'unleashed' of https://github.com/PixlEmly/flipperzero-f…
PixlEmly Jun 13, 2022
fe3b4b3
Improve directions on how to find dimensions, which are kinda importa…
PixlEmly Jun 3, 2022
61d0bbf
encode will print out image dimensions
PixlEmly Jun 3, 2022
59f5a0d
QOL
PixlEmly Jun 3, 2022
907596b
Update ReadMe.md
PixlEmly Jun 3, 2022
4bb7f13
New: decoder for heatshrunk char array icons.
PixlEmly Jun 4, 2022
a987a28
help info
PixlEmly Jun 4, 2022
d1e6c3f
re-arrange params
PixlEmly Jun 4, 2022
54946d0
QOL
PixlEmly Jun 4, 2022
14fd8b8
icon encoder added
PixlEmly Jun 4, 2022
ca21fcb
cleanup
PixlEmly Jun 4, 2022
5cb5068
I can't count
PixlEmly Jun 6, 2022
9158eb6
box tutorial
PixlEmly Jun 9, 2022
cdeaf0e
Box Mover but added stuff
PixlEmly Jun 9, 2022
c852a51
Improved bounds checks
PixlEmly Jun 9, 2022
3f4484b
Video Poker game
PixlEmly Jun 9, 2022
8876a68
Box Mover Splash Screen!
PixlEmly Jun 10, 2022
42ac2fe
INITIAL Video Poker - it works! It's messy!
PixlEmly Jun 13, 2022
8d439c4
Still a bit messy. But it seems to be good now.
PixlEmly Jun 13, 2022
19e5dc2
Update README.md
PixlEmly Jun 10, 2022
fd47251
Update README.md
PixlEmly Jun 10, 2022
c2ca751
Update README.md
PixlEmly Jun 10, 2022
d692a93
Merge branch 'unleashed' of https://github.com/PixlEmly/flipperzero-f…
PixlEmly Jun 13, 2022
6978355
Attribution ;)
PixlEmly Jun 13, 2022
db25fe0
Improve directions on how to find dimensions, which are kinda importa…
PixlEmly Jun 3, 2022
5bb8432
encode will print out image dimensions
PixlEmly Jun 3, 2022
1caa422
QOL
PixlEmly Jun 3, 2022
5992e09
Update ReadMe.md
PixlEmly Jun 3, 2022
e6c6108
New: decoder for heatshrunk char array icons.
PixlEmly Jun 4, 2022
5dedb8a
help info
PixlEmly Jun 4, 2022
f59a4a1
re-arrange params
PixlEmly Jun 4, 2022
6e507af
QOL
PixlEmly Jun 4, 2022
281bde1
icon encoder added
PixlEmly Jun 4, 2022
20abbca
cleanup
PixlEmly Jun 4, 2022
5b19fe3
I can't count
PixlEmly Jun 6, 2022
31ceca3
box tutorial
PixlEmly Jun 9, 2022
52f29df
Box Mover but added stuff
PixlEmly Jun 9, 2022
10cef4b
Improved bounds checks
PixlEmly Jun 9, 2022
e0378e8
Video Poker game
PixlEmly Jun 9, 2022
d94e64c
INITIAL Video Poker - it works! It's messy!
PixlEmly Jun 13, 2022
1a80d50
Still a bit messy. But it seems to be good now.
PixlEmly Jun 13, 2022
188f626
Update README.md
PixlEmly Jun 10, 2022
b389bb2
Improve directions on how to find dimensions, which are kinda importa…
PixlEmly Jun 3, 2022
7488ea8
encode will print out image dimensions
PixlEmly Jun 3, 2022
700cf51
QOL
PixlEmly Jun 3, 2022
05e7669
Update ReadMe.md
PixlEmly Jun 3, 2022
9231898
New: decoder for heatshrunk char array icons.
PixlEmly Jun 4, 2022
71efb77
help info
PixlEmly Jun 4, 2022
669eb2d
re-arrange params
PixlEmly Jun 4, 2022
9e47966
QOL
PixlEmly Jun 4, 2022
3522512
Update ReadMe.md
PixlEmly Jun 4, 2022
42aee38
s
PixlEmly Jun 4, 2022
b193390
Update ReadMe.md
PixlEmly Jun 4, 2022
9c139cf
Update ReadMe.md
PixlEmly Jun 5, 2022
1365c21
Update ReadMe.md
PixlEmly Jun 5, 2022
975c8ab
I can't count
PixlEmly Jun 6, 2022
78dd160
box tutorial
PixlEmly Jun 9, 2022
42cd856
Box Mover but added stuff
PixlEmly Jun 9, 2022
de014f3
Improved bounds checks
PixlEmly Jun 9, 2022
87d2a69
Attribution ;)
PixlEmly Jun 13, 2022
bdc5574
wtf
PixlEmly Jun 15, 2022
ff975d4
fuk
PixlEmly Jun 16, 2022
d1580e0
nuke and cleanup
PixlEmly Jun 16, 2022
84739fd
nuke and cleanup II
PixlEmly Jun 16, 2022
8aa2f0d
nuke and cleanup III
PixlEmly Jun 16, 2022
a506b19
nuke and cleanup IV
PixlEmly Jun 16, 2022
3380410
Poker cleaned up, less globals, better alignment, some comments
PixlEmly Jun 16, 2022
9867e00
Update to scripts
PixlEmly Jun 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -678,4 +678,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 @@ -451,4 +451,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()