diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8a7a627 --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.md b/README.md index 06e5d62..2868486 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..d466adc --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +name = "bdf_to_numpy" diff --git a/bdfparse.py b/bdfparse.py index ae4cf08..44e4a0f 100644 --- a/bdfparse.py +++ b/bdfparse.py @@ -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() diff --git a/example.png b/example.png new file mode 100644 index 0000000..545baf2 Binary files /dev/null and b/example.png differ diff --git a/notebook.py b/notebook.py deleted file mode 100644 index cc35d5e..0000000 --- a/notebook.py +++ /dev/null @@ -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) - -#%% diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..73d328c --- /dev/null +++ b/setup.py @@ -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", + ], +)