Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
st7789_mpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
st7789_mpy
Commits
c6a3e747
Commit
c6a3e747
authored
Oct 24, 2021
by
russhughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring
parent
19613e69
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
24 deletions
+21
-24
utils/font_from_romfont.py
utils/font_from_romfont.py
+6
-10
utils/imgtobitmap.py
utils/imgtobitmap.py
+8
-6
utils/monofont2bitmap.py
utils/monofont2bitmap.py
+7
-7
utils/png_from_font.py
utils/png_from_font.py
+0
-1
No files found.
utils/font_from_romfont.py
View file @
c6a3e747
...
...
@@ -28,7 +28,7 @@ def convert_font(file_in, file_out, width, height, first=0x0, last=0xff):
print
(
f'HEIGHT =
{
height
}
'
,
file
=
font_file
)
print
(
f'FIRST = 0x
{
first
:
02
x
}
'
,
file
=
font_file
)
print
(
f'LAST = 0x
{
last
:
02
x
}
'
,
file
=
font_file
)
print
(
f
'_FONT =
\\\n
'
,
sep
=
''
,
end
=
''
,
file
=
font_file
)
print
(
'_FONT =
\\\n
'
,
sep
=
''
,
end
=
''
,
file
=
font_file
)
for
chunk
in
iter
(
lambda
:
bin_file
.
read
(
chunk_size
),
b''
):
print
(
'b
\'
'
,
sep
=
''
,
end
=
''
,
file
=
font_file
)
for
data
in
chunk
:
...
...
@@ -42,12 +42,11 @@ def convert_font(file_in, file_out, width, height, first=0x0, last=0xff):
print
(
'FONT = memoryview(_FONT)'
,
file
=
font_file
)
def
auto_int
(
x
):
return
int
(
x
,
0
)
return
int
(
x
,
0
)
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Convert
f
omfont.bin font files in input to python in font_directory.'
)
description
=
'Convert
R
omfont.bin font files in input to python in font_directory.'
)
parser
.
add_argument
(
'input'
,
help
=
'file or directory containing binary font file(s).'
)
parser
.
add_argument
(
'output'
,
help
=
'file or directory to contain python font file(s).'
)
parser
.
add_argument
(
'-f'
,
'--first-char'
,
type
=
auto_int
,
default
=
0x20
)
...
...
@@ -57,11 +56,7 @@ def main():
file_re
=
re
.
compile
(
r'^(.*)(\d+)x(\d+)\.bin$'
)
is_dir
=
os
.
path
.
isdir
(
args
.
input
)
if
is_dir
:
bin_files
=
os
.
listdir
(
args
.
input
)
else
:
bin_files
=
[
args
.
input
]
bin_files
=
os
.
listdir
(
args
.
input
)
if
is_dir
else
[
args
.
input
]
for
bin_file_name
in
bin_files
:
match
=
file_re
.
match
(
bin_file_name
)
if
match
:
...
...
@@ -88,4 +83,5 @@ def main():
font_height
,
args
.
first_char
,
args
.
last_char
)
main
()
\ No newline at end of file
main
()
utils/imgtobitmap.py
View file @
c6a3e747
...
...
@@ -40,9 +40,9 @@ def main():
# get rgb values and convert to 565
color565
=
(
((
palette
[
color
*
3
]
&
0xF8
)
<<
8
)
|
((
palette
[
color
*
3
+
1
]
&
0xFC
)
<<
3
)
|
((
palette
[
color
*
3
+
2
]
&
0xF8
)
>>
3
))
((
palette
[
color
*
3
]
&
0xF8
)
<<
8
)
|
((
palette
[
color
*
3
+
1
]
&
0xFC
)
<<
3
)
|
((
palette
[
color
*
3
+
2
]
&
0xF8
)
>>
3
))
# swap bytes in 565
color
=
((
color565
&
0xff
)
<<
8
)
+
((
color565
&
0xff00
)
>>
8
)
...
...
@@ -59,9 +59,11 @@ def main():
for
x
in
range
(
img
.
width
):
pixel
=
img
.
getpixel
((
x
,
y
))
color
=
pixel
bstring
=
''
for
bit
in
range
(
bits
,
0
,
-
1
):
bstring
+=
'1'
if
(
color
&
(
1
<<
bit
-
1
))
else
'0'
bstring
=
''
.
join
(
'1'
if
(
color
&
(
1
<<
bit
-
1
))
else
'0'
for
bit
in
range
(
bits
,
0
,
-
1
)
)
image_bitstring
+=
bstring
bitmap_bits
=
len
(
image_bitstring
)
...
...
utils/monofont2bitmap.py
View file @
c6a3e747
...
...
@@ -45,12 +45,10 @@ def to_int(str):
def
get_characters
(
str
):
return
''
.
join
(
[
chr
(
b
)
for
a
in
[
return
''
.
join
(
chr
(
b
)
for
a
in
[
(
lambda
sub
:
range
(
sub
[
0
],
sub
[
-
1
]
+
1
))
(
list
(
map
(
to_int
,
ele
.
split
(
'-'
))))
for
ele
in
str
.
split
(
','
)]
for
b
in
a
])
for
ele
in
str
.
split
(
','
)]
for
b
in
a
)
def
process_char
(
img
,
bits
):
global
image_bitstring
...
...
@@ -62,9 +60,11 @@ def process_char(img, bits):
for
x
in
range
(
img
.
width
):
pixel
=
img
.
getpixel
((
x
,
y
))
color
=
pixel
bit_string
=
''
for
bit
in
range
(
bits
,
0
,
-
1
):
bit_string
+=
'1'
if
(
color
&
(
1
<<
bit
-
1
))
else
'0'
bit_string
=
''
.
join
(
'1'
if
(
color
&
(
1
<<
bit
-
1
))
else
'0'
for
bit
in
range
(
bits
,
0
,
-
1
)
)
image_bitstring
+=
bit_string
...
...
utils/png_from_font.py
View file @
c6a3e747
...
...
@@ -27,7 +27,6 @@ def create_png(font_file_name, png_file_name):
with
open
(
png_file_name
,
'wb'
)
as
png_file
:
image
=
png
.
Writer
((
16
+
2
)
*
font
.
WIDTH
,
(
row_count
+
3
)
*
font
.
HEIGHT
,
bitdepth
=
1
)
image_data
=
[[
0
for
j
in
range
((
16
+
2
)
*
font
.
WIDTH
)]
for
i
in
range
((
row_count
+
3
)
*
font
.
HEIGHT
)]
font_count
=
len
(
font
.
FONT
)
+
1
for
chart_row
in
range
(
row_count
+
2
):
for
chart_col
in
range
(
16
):
chart_idx
=
chart_row
*
16
+
chart_col
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment