diff options
author | Nick Brassel <nick@tzarc.org> | 2022-11-09 02:47:07 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-08 15:47:07 +0000 |
commit | 9daf77b59373196839d022d621f015e074aa427a (patch) | |
tree | a481197569920ab942155131613bff5e4a982b0b | |
parent | bb0856d231a8de244e3057dd095d11e9298414f3 (diff) |
Add raw output option for QGF/QFF files. (#18998)
-rw-r--r-- | docs/quantum_painter.md | 10 | ||||
-rw-r--r-- | lib/python/qmk/cli/painter/convert_graphics.py | 7 | ||||
-rw-r--r-- | lib/python/qmk/cli/painter/make_font.py | 12 |
3 files changed, 23 insertions, 6 deletions
diff --git a/docs/quantum_painter.md b/docs/quantum_painter.md index ed9cec171b..781b467a45 100644 --- a/docs/quantum_painter.md +++ b/docs/quantum_painter.md @@ -55,10 +55,11 @@ This command converts images to a format usable by QMK, i.e. the QGF File Format **Usage**: ``` -usage: qmk painter-convert-graphics [-h] [-d] [-r] -f FORMAT [-o OUTPUT] -i INPUT [-v] +usage: qmk painter-convert-graphics [-h] [-w] [-d] [-r] -f FORMAT [-o OUTPUT] -i INPUT [-v] -optional arguments: +options: -h, --help show this help message and exit + -w, --raw Writes out the QGF file as raw data instead of c/h combo. -d, --no-deltas Disables the use of delta frames when encoding animations. -r, --no-rle Disables the use of RLE when encoding images. -f FORMAT, --format FORMAT @@ -146,10 +147,11 @@ This command expects an image that conforms to the following format: **Usage**: ``` -usage: qmk painter-convert-font-image [-h] [-r] -f FORMAT [-u UNICODE_GLYPHS] [-n] [-o OUTPUT] [-i INPUT] +usage: qmk painter-convert-font-image [-h] [-w] [-r] -f FORMAT [-u UNICODE_GLYPHS] [-n] [-o OUTPUT] [-i INPUT] -optional arguments: +options: -h, --help show this help message and exit + -w, --raw Writes out the QFF file as raw data instead of c/h combo. -r, --no-rle Disable the use of RLE to minimise converted image size. -f FORMAT, --format FORMAT Output format, valid types: pal256, pal16, pal4, pal2, mono256, mono16, mono4, mono2 diff --git a/lib/python/qmk/cli/painter/convert_graphics.py b/lib/python/qmk/cli/painter/convert_graphics.py index bbc30d26ff..2519c49b25 100644 --- a/lib/python/qmk/cli/painter/convert_graphics.py +++ b/lib/python/qmk/cli/painter/convert_graphics.py @@ -15,6 +15,7 @@ from PIL import Image @cli.argument('-f', '--format', required=True, help='Output format, valid types: %s' % (', '.join(valid_formats.keys()))) @cli.argument('-r', '--no-rle', arg_only=True, action='store_true', help='Disables the use of RLE when encoding images.') @cli.argument('-d', '--no-deltas', arg_only=True, action='store_true', help='Disables the use of delta frames when encoding animations.') +@cli.argument('-w', '--raw', arg_only=True, action='store_true', help='Writes out the QGF file as raw data instead of c/h combo.') @cli.subcommand('Converts an input image to something QMK understands') def painter_convert_graphics(cli): """Converts an image file to a format that Quantum Painter understands. @@ -53,6 +54,12 @@ def painter_convert_graphics(cli): input_img.save(out_data, "QGF", use_deltas=(not cli.args.no_deltas), use_rle=(not cli.args.no_rle), qmk_format=format, verbose=cli.args.verbose) out_bytes = out_data.getvalue() + if cli.args.raw: + raw_file = cli.args.output / (cli.args.input.stem + ".qgf") + with open(raw_file, 'wb') as raw: + raw.write(out_bytes) + return + # Work out the text substitutions for rendering the output data subs = { 'generated_type': 'image', diff --git a/lib/python/qmk/cli/painter/make_font.py b/lib/python/qmk/cli/painter/make_font.py index 0762843fd3..c0189920d2 100644 --- a/lib/python/qmk/cli/painter/make_font.py +++ b/lib/python/qmk/cli/painter/make_font.py @@ -33,6 +33,7 @@ def painter_make_font_image(cli): @cli.argument('-u', '--unicode-glyphs', default='', help='Also generate the specified unicode glyphs.') @cli.argument('-f', '--format', required=True, help='Output format, valid types: %s' % (', '.join(valid_formats.keys()))) @cli.argument('-r', '--no-rle', arg_only=True, action='store_true', help='Disable the use of RLE to minimise converted image size.') +@cli.argument('-w', '--raw', arg_only=True, action='store_true', help='Writes out the QFF file as raw data instead of c/h combo.') @cli.subcommand('Converts an input font image to something QMK firmware understands') def painter_convert_font_image(cli): # Work out the format @@ -53,6 +54,13 @@ def painter_convert_font_image(cli): # Render out the data out_data = BytesIO() font.save_to_qff(format, (False if cli.args.no_rle else True), out_data) + out_bytes = out_data.getvalue() + + if cli.args.raw: + raw_file = cli.args.output / (cli.args.input.stem + ".qff") + with open(raw_file, 'wb') as raw: + raw.write(out_bytes) + return # Work out the text substitutions for rendering the output data subs = { @@ -62,8 +70,8 @@ def painter_convert_font_image(cli): 'year': datetime.date.today().strftime("%Y"), 'input_file': cli.args.input.name, 'sane_name': re.sub(r"[^a-zA-Z0-9]", "_", cli.args.input.stem), - 'byte_count': out_data.getbuffer().nbytes, - 'bytes_lines': render_bytes(out_data.getbuffer().tobytes()), + 'byte_count': len(out_bytes), + 'bytes_lines': render_bytes(out_bytes), 'format': cli.args.format, } |