logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

qff.h (4286B)


  1. // Copyright 2021 Nick Brassel (@tzarc)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. // Quantum Font File "QFF" File Format.
  5. // See https://docs.qmk.fm/#/quantum_painter_qff for more information.
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include "compiler_support.h"
  9. #include "qp_stream.h"
  10. #include "qp_internal.h"
  11. #include "qgf.h"
  12. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  13. // QFF structures
  14. /////////////////////////////////////////
  15. // Font descriptor
  16. #define QFF_FONT_DESCRIPTOR_TYPEID 0x00
  17. typedef struct QP_PACKED qff_font_descriptor_v1_t {
  18. qgf_block_header_v1_t header; // = { .type_id = 0x00, .neg_type_id = (~0x00), .length = 20 }
  19. uint32_t magic : 24; // constant, equal to 0x464651 ("QFF")
  20. uint8_t qff_version; // constant, equal to 0x01
  21. uint32_t total_file_size; // total size of the entire file, starting at offset zero
  22. uint32_t neg_total_file_size; // negated value of total_file_size, used for detecting parsing errors
  23. uint8_t line_height; // glyph height in pixels
  24. bool has_ascii_table; // whether the font has an ascii table of glyphs (0x20...0x7E)
  25. uint16_t num_unicode_glyphs; // the number of glyphs in the unicode table -- no table specified if zero
  26. qp_image_format_t format : 8; // Frame format, see qp.h.
  27. uint8_t flags; // frame flags, see below.
  28. uint8_t compression_scheme; // compression scheme, see below.
  29. uint8_t transparency_index; // palette index used for transparent pixels (not yet implemented)
  30. } qff_font_descriptor_v1_t;
  31. STATIC_ASSERT(sizeof(qff_font_descriptor_v1_t) == (sizeof(qgf_block_header_v1_t) + 20), "qff_font_descriptor_v1_t must be 25 bytes in v1 of QFF");
  32. #define QFF_MAGIC 0x464651
  33. /////////////////////////////////////////
  34. // ASCII glyph table descriptor
  35. #define QFF_ASCII_GLYPH_DESCRIPTOR_TYPEID 0x01
  36. #define QFF_GLYPH_WIDTH_BITS 6
  37. #define QFF_GLYPH_WIDTH_MASK ((1 << QFF_GLYPH_WIDTH_BITS) - 1)
  38. #define QFF_GLYPH_OFFSET_BITS 18
  39. #define QFF_GLYPH_OFFSET_MASK (((1 << QFF_GLYPH_OFFSET_BITS) - 1) << QFF_GLYPH_WIDTH_BITS)
  40. typedef struct QP_PACKED qff_ascii_glyph_v1_t {
  41. uint32_t value : 24; // Uses QFF_GLYPH_*_(BITS|MASK) as bitfield ordering is compiler-defined
  42. } qff_ascii_glyph_v1_t;
  43. STATIC_ASSERT(sizeof(qff_ascii_glyph_v1_t) == 3, "qff_ascii_glyph_v1_t must be 3 bytes in v1 of QFF");
  44. typedef struct QP_PACKED qff_ascii_glyph_table_v1_t {
  45. qgf_block_header_v1_t header; // = { .type_id = 0x01, .neg_type_id = (~0x01), .length = 285 }
  46. qff_ascii_glyph_v1_t glyph[95]; // 95 glyphs, 0x20..0x7E
  47. } qff_ascii_glyph_table_v1_t;
  48. STATIC_ASSERT(sizeof(qff_ascii_glyph_table_v1_t) == (sizeof(qgf_block_header_v1_t) + (95 * sizeof(qff_ascii_glyph_v1_t))), "qff_ascii_glyph_table_v1_t must be 290 bytes in v1 of QFF");
  49. /////////////////////////////////////////
  50. // Unicode glyph table descriptor
  51. #define QFF_UNICODE_GLYPH_DESCRIPTOR_TYPEID 0x02
  52. typedef struct QP_PACKED qff_unicode_glyph_v1_t {
  53. uint32_t code_point : 24;
  54. uint32_t value : 24; // Uses QFF_GLYPH_*_(BITS|MASK) as bitfield ordering is compiler-defined
  55. } qff_unicode_glyph_v1_t;
  56. STATIC_ASSERT(sizeof(qff_unicode_glyph_v1_t) == 6, "qff_unicode_glyph_v1_t must be 6 bytes in v1 of QFF");
  57. typedef struct QP_PACKED qff_unicode_glyph_table_v1_t {
  58. qgf_block_header_v1_t header; // = { .type_id = 0x02, .neg_type_id = (~0x02), .length = (N * 6) }
  59. qff_unicode_glyph_v1_t glyph[0]; // Extent of '0' signifies that this struct is immediately followed by the glyph data
  60. } qff_unicode_glyph_table_v1_t;
  61. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62. // QFF API
  63. bool qff_validate_stream(qp_stream_t *stream);
  64. uint32_t qff_get_total_size(qp_stream_t *stream);
  65. bool qff_read_font_descriptor(qp_stream_t *stream, uint8_t *line_height, bool *has_ascii_table, uint16_t *num_unicode_glyphs, uint8_t *bpp, bool *has_palette, bool *is_panel_native, painter_compression_t *compression_scheme, uint32_t *total_bytes);