1
0
mirror of https://gitlab.com/MisterBiggs/bdfparse.git synced 2025-06-15 14:06:39 +00:00

preparing code for official release

This commit is contained in:
Anson 2019-07-15 23:00:40 -07:00
parent 5ada358204
commit b9fd445da7
7 changed files with 83 additions and 40 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Anson Biggs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,2 +1,24 @@
# bdf to numpy
# .bdf to NumPy
This project takes a .bdf file and turns it into a [NumPy](https://www.numpy.org/) Array with an intended use with LED matrix displays. My [LED Stock Ticker](https://gitlab.com/them-boys/raspberry-pi-stock-ticker) uses this package. A good list of .bdf files can be found [here](https://github.com/hzeller/rpi-rgb-led-matrix/tree/master/fonts)
## Usage
```python
import numpy as np
import matplotlib.pyplot as plt
font = parse_chars("9x18.bdf")
matrix = font["A"]
text = "nson"
for letter in text:
matrix = np.concatenate((matrix, font[letter]), axis=1)
plt.imshow(matrix)
plt.show()
```
Which outputs:
![Example of code output that reads Anson.](example.png)

1
__init__.py Normal file
View File

@ -0,0 +1 @@
name = "bdf_to_numpy"

View File

@ -1,4 +1,5 @@
import numpy as np
import matplotlib.pyplot as plt
def parse_properties(bdfFile):
@ -176,3 +177,14 @@ def parse_chars(bdfFile):
if bdf.readline().startswith("ENDFONT"):
return font
return font
font = parse_chars("9x18.bdf")
matrix = font["A"]
text = "nson"
for letter in text:
matrix = np.concatenate((matrix, font[letter]), axis=1)
plt.imshow(matrix)
plt.show()

BIN
example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -1,39 +0,0 @@
#%%
import numpy as np
import matplotlib.pyplot as plt
#%%
hexs = [
0x00,
0x00,
0x00,
0x00,
0x18,
0x24,
0x24,
0x42,
0x42,
0x7E,
0x42,
0x42,
0x42,
0x42,
0x00,
0x00,
]
bbx = (8, 16, 0, -2)
#%%
rows = []
for row in range(0, bbx[1]):
rows.append(list(f"{hexs[row]:0>42b}")[-(bbx[0] + 1) : -1])
#%%
plt.imshow(np.array(rows, dtype=int))
plt.show()
#%%
np.array(rows, dtype=int)
#%%

26
setup.py Normal file
View File

@ -0,0 +1,26 @@
# Copyright (c) 2019 albig
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="bdf-to-numpy",
version="2019.1",
author="Anson Biggs",
author_email="anson@ansonbiggs.com",
description="A package for reading .bdf files into NumPy arrays.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://gitlab.com/MisterBiggs/bdf-to-numpy",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3.7.3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)