st7789py_mpy Asset Conversion Utilities

repository·master·Indexed 42 days ago

https://github.com/russhughes/st7789py_mpy

A suite of conversion utilities for transforming fonts, images, and sprite sheets into optimized Python modules for ST7789, ILI9342, GC9107, GC9A01, and ST7735 display drivers. Includes tools like text_font_converter.py, write_font_converter.py, image_converter.py, and sprites_converter.py, along with hardware configurations for M5STACK, LilyGo, and ESP32 devices.

Tokens
11.3K
Snippets
66
Records
70
Agent score
53%

What's inside st7789py_mpy

  1. Compare Bitmap and TrueType fonts

    master

    The driver supports two font types: Bitmap Fonts (fixed-size, extracted from PC VGA/BIOS images) and TrueType Fonts (variable width, converted from .ttf files).

    AttributeBitmap FontsTrueType Fonts
    SourcePC BIOS imagesTrue-Type fonts
    Conversion Tooltext_font_converter.pywrite_font_converter.py
    Character Sets128 and 256 PC character setsUser defined
    Pixel Sizes8x8, 8x16, 16x6, and 16x32width 256 pixels or less
    Rendering Methodtext() methodwrite() method

    All fonts are stored as Python modules and should be imported using standard Python import statements. To save memory, pre-compile these modules to .mpy files or convert them to frozen bytecode in the MicroPython firmware.

  2. Configure M5STACK AtomS3 128x128 (GC9107)

    master

    To use the M5STACK AtomS3 (128x128 resolution with a GC9107 driver), use the configuration defined in tft_configs/atom_s3/tft_config.py. This file contains the necessary hardware parameters for the display driver and initialization.

    # Refer to tft_configs/atom_s3/tft_config.py for the specific configuration implementation
  3. Convert binary font files with text_font_converter.py

    master

    Use text_font_converter.py to convert binary font files (from sources like spacerace's romfont repo) into Python font modules. These modules are designed for use with the text() method in the library. You can specify an input directory containing .bin files and an output directory for the resulting Python modules. You can also limit the character range included in the conversion using -f (first character) and -l (last character).

    text_font_converter.py [-h] [-f FIRST_CHAR] [-l LAST_CHAR] input output
  4. Convert sprite sheets with sprites_converter.py

    master

    Use sprites_converter.py to convert a sprite sheet image into a Python module for use with the indexed bitmap method.

    Requirements for the sprite sheet:

    • The sheet width and height must be multiples of the specified sprite_width and sprite_height.
    • There must be no extra pixels between sprites.
    • All sprites in the sheet must share the same palette.
    sprites_converter [-h] image_file sprite_width sprite_height bits_per_pixel
  5. Use text_font_converter.py to convert binary fonts

    master

    The text_font_converter.py utility converts binary font files (such as those from the spacerace/romfont repository) into Python modules.

    Input/Output Rules:

    • If the input is a directory, the output must be a directory.
    • If the input is a single file, the output can be either a file or a directory.

    Arguments:

    • input: The file or directory containing the binary font file(s).
    • output: The file or directory where the resulting Python font module(s) will be saved.
    • -f FIRST_CHAR (optional): The first character code to include in the conversion (defaults to 0x20).
    • -l LAST_CHAR (optional): The last character code to include in the conversion (defaults to 0x7F).
    # convert the IBM_VGA_8x8.bin font to a python module with 8x8 characters
    text_font_converter.py romfont/font-bin/IBM_VGA_8x8.bin vga_8x8.py -f 32 -l 127
  6. Configure LilyGo T-DISPLAY 135x240

    master

    To use the LilyGo T-DISPLAY (1.14 inch LCD ESP32 control board) with this library, use the configuration provided in tft_configs/ttgo_tdisplay/tft_config.py. This file contains the necessary hardware parameters for the ST7789 driver to work correctly with this specific board's pinout and display dimensions.

    # Reference the configuration from tft_configs/ttgo_tdisplay/tft_config.py
  7. Convert TrueType fonts with write_font_converter.py

    master

    Use write_font_converter.py (located in the utils directory) to convert TrueType (.ttf) fonts into bitmap font modules. TrueType fonts can be converted to any size as long as the widest character is 256 pixels or less.

    Requirements:

    • The freetype Python module must be installed.

    Usage Examples:

    • Convert a font with a specific character string: ./write_font_converter.py NotoSans-Regular.ttf 32 -s "0123456789ABCEDF"
    • Convert a font using a hex range: ./write_font_converter.py Chango-Regular.ttf 16 -c 0x20-0x7f
    ./write_font_converter.py NotoSans-Regular.ttf 32 -s "0123456789ABCEDF"
    ./write_font_converter.py Chango-Regular.ttf 16 -c 0x20-0x7f
  8. Convert images to Python modules with image_converter.py

    master

    Use image_converter.py to convert a standard image file into a Python module. The resulting module is used with the bitmap() method. You must specify the number of bits per pixel (ranging from 1 to 8).

    image_converter.py [-h] image_file bits_per_pixel
  9. Convert TrueType fonts to Python bitmap modules with write_font_converter.py

    master

    Use write_font_converter.py to convert characters from a TrueType (.ttf) font into a Python bitmap module. These modules can be used with the .write() method in the st7789 and ili9342 drivers. The output is typically redirected to a .py file.

    # Convert Chango-Regular.ttf to a python bitmap module with ~32 pixel high characters
    ./write_font_converter.py Chango-Regular.ttf 32 -c 0x20-0x7f > chango_32.py
  10. Convert PC BIOS bitmap fonts with text_font_converter.py

    master

    Use text_font_converter.py (located in the utils directory) to convert PC BIOS bitmap fonts from the romfont repository into Python font modules.

    Options:

    • -i, --input-directory: The directory containing the .bin files to convert.
    • -o, --output-directory: The directory where the resulting Python font files will be written.
    • -f, --first-char: The first character code to include in the output.
    • -l, --last-char: The last character code to include in the output.
    text_font_converter.py -i font-bin -o fonts -f 32 -l 127