chore(color): Turn off LVGL compression of font data (#4419)

This commit is contained in:
philmoz
2023-12-18 19:39:56 +10:00
committed by GitHub
parent 3f425e0b46
commit 77e6a7c14f
40 changed files with 67615 additions and 77160 deletions
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -569,6 +570,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 1524, .range_length = 62127, .glyph_id_start = 141, .list_length = 63, .type = 3, .unicode_list = 1632, .glyph_id_ofs_list = 0 }, { .range_start = 1524, .range_length = 62127, .glyph_id_start = 141, .list_length = 63, .type = 3, .unicode_list = 1632, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[11869] __SDRAM;
const etxLz4Font lv_font_arimo_he_13 = { const etxLz4Font lv_font_arimo_he_13 = {
.uncomp_size = 11541, .uncomp_size = 11541,
.comp_size = 8900, .comp_size = 8900,
@@ -590,4 +593,6 @@ const etxLz4Font lv_font_arimo_he_13 = {
.right_class_mapping = 11337, .right_class_mapping = 11337,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 11869,
}; };
File diff suppressed because it is too large Load Diff
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -369,6 +370,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 1524, .range_length = 62127, .glyph_id_start = 141, .list_length = 63, .type = 3, .unicode_list = 1632, .glyph_id_ofs_list = 0 }, { .range_start = 1524, .range_length = 62127, .glyph_id_start = 141, .list_length = 63, .type = 3, .unicode_list = 1632, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[7418] __SDRAM;
const etxLz4Font lv_font_arimo_he_9 = { const etxLz4Font lv_font_arimo_he_9 = {
.uncomp_size = 7090, .uncomp_size = 7090,
.comp_size = 5709, .comp_size = 5709,
@@ -390,4 +393,6 @@ const etxLz4Font lv_font_arimo_he_9 = {
.right_class_mapping = 6886, .right_class_mapping = 6886,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 7418,
}; };
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -681,6 +682,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 1105, .range_length = 62546, .glyph_id_start = 177, .list_length = 63, .type = 3, .unicode_list = 1920, .glyph_id_ofs_list = 0 }, { .range_start = 1105, .range_length = 62546, .glyph_id_start = 177, .list_length = 63, .type = 3, .unicode_list = 1920, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[17343] __SDRAM;
const etxLz4Font lv_font_arimo_ru_13 = { const etxLz4Font lv_font_arimo_ru_13 = {
.uncomp_size = 16983, .uncomp_size = 16983,
.comp_size = 10683, .comp_size = 10683,
@@ -702,4 +705,6 @@ const etxLz4Font lv_font_arimo_ru_13 = {
.right_class_mapping = 16743, .right_class_mapping = 16743,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 17343,
}; };
File diff suppressed because it is too large Load Diff
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -465,6 +466,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 1105, .range_length = 62546, .glyph_id_start = 177, .list_length = 63, .type = 3, .unicode_list = 1920, .glyph_id_ofs_list = 0 }, { .range_start = 1105, .range_length = 62546, .glyph_id_start = 177, .list_length = 63, .type = 3, .unicode_list = 1920, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[12168] __SDRAM;
const etxLz4Font lv_font_arimo_ru_9 = { const etxLz4Font lv_font_arimo_ru_9 = {
.uncomp_size = 11808, .uncomp_size = 11808,
.comp_size = 7225, .comp_size = 7225,
@@ -486,4 +489,6 @@ const etxLz4Font lv_font_arimo_ru_9 = {
.right_class_mapping = 11568, .right_class_mapping = 11568,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 12168,
}; };
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -3115,6 +3116,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 176, .range_length = 63475, .glyph_id_start = 113, .list_length = 627, .type = 3, .unicode_list = 5920, .glyph_id_ofs_list = 0 }, { .range_start = 176, .range_length = 63475, .glyph_id_start = 113, .list_length = 627, .type = 3, .unicode_list = 5920, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[63921] __SDRAM;
const etxLz4Font lv_font_noto_cn_13 = { const etxLz4Font lv_font_noto_cn_13 = {
.uncomp_size = 63657, .uncomp_size = 63657,
.comp_size = 49668, .comp_size = 49668,
@@ -3136,4 +3139,6 @@ const etxLz4Font lv_font_noto_cn_13 = {
.right_class_mapping = 62917, .right_class_mapping = 62917,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 63921,
}; };
File diff suppressed because it is too large Load Diff
+5
View File
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -1964,6 +1965,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 176, .range_length = 63475, .glyph_id_start = 113, .list_length = 627, .type = 3, .unicode_list = 5920, .glyph_id_ofs_list = 0 }, { .range_start = 176, .range_length = 63475, .glyph_id_start = 113, .list_length = 627, .type = 3, .unicode_list = 5920, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[38517] __SDRAM;
const etxLz4Font lv_font_noto_cn_9 = { const etxLz4Font lv_font_noto_cn_9 = {
.uncomp_size = 38253, .uncomp_size = 38253,
.comp_size = 31262, .comp_size = 31262,
@@ -1985,4 +1988,6 @@ const etxLz4Font lv_font_noto_cn_9 = {
.right_class_mapping = 37513, .right_class_mapping = 37513,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 38517,
}; };
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -2302,6 +2303,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 12527, .range_length = 51124, .glyph_id_start = 231, .list_length = 342, .type = 3, .unicode_list = 4719, .glyph_id_ofs_list = 0 }, { .range_start = 12527, .range_length = 51124, .glyph_id_start = 231, .list_length = 342, .type = 3, .unicode_list = 4719, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[60102] __SDRAM;
const etxLz4Font lv_font_noto_jp_13 = { const etxLz4Font lv_font_noto_jp_13 = {
.uncomp_size = 59742, .uncomp_size = 59742,
.comp_size = 36610, .comp_size = 36610,
@@ -2323,4 +2326,6 @@ const etxLz4Font lv_font_noto_jp_13 = {
.right_class_mapping = 59169, .right_class_mapping = 59169,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 60102,
}; };
File diff suppressed because it is too large Load Diff
+5
View File
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -1483,6 +1484,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 12527, .range_length = 51124, .glyph_id_start = 231, .list_length = 342, .type = 3, .unicode_list = 4719, .glyph_id_ofs_list = 0 }, { .range_start = 12527, .range_length = 51124, .glyph_id_start = 231, .list_length = 342, .type = 3, .unicode_list = 4719, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[41981] __SDRAM;
const etxLz4Font lv_font_noto_jp_9 = { const etxLz4Font lv_font_noto_jp_9 = {
.uncomp_size = 41621, .uncomp_size = 41621,
.comp_size = 23514, .comp_size = 23514,
@@ -1504,4 +1507,6 @@ const etxLz4Font lv_font_noto_jp_9 = {
.right_class_mapping = 41048, .right_class_mapping = 41048,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 41981,
}; };
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -3331,6 +3332,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 176, .range_length = 63475, .glyph_id_start = 113, .list_length = 654, .type = 3, .unicode_list = 6136, .glyph_id_ofs_list = 0 }, { .range_start = 176, .range_length = 63475, .glyph_id_start = 113, .list_length = 654, .type = 3, .unicode_list = 6136, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[66606] __SDRAM;
const etxLz4Font lv_font_noto_tw_13 = { const etxLz4Font lv_font_noto_tw_13 = {
.uncomp_size = 66342, .uncomp_size = 66342,
.comp_size = 53130, .comp_size = 53130,
@@ -3352,4 +3355,6 @@ const etxLz4Font lv_font_noto_tw_13 = {
.right_class_mapping = 65575, .right_class_mapping = 65575,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 66606,
}; };
File diff suppressed because it is too large Load Diff
+5
View File
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -2065,6 +2066,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 176, .range_length = 63475, .glyph_id_start = 113, .list_length = 654, .type = 3, .unicode_list = 6136, .glyph_id_ofs_list = 0 }, { .range_start = 176, .range_length = 63475, .glyph_id_start = 113, .list_length = 654, .type = 3, .unicode_list = 6136, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[40081] __SDRAM;
const etxLz4Font lv_font_noto_tw_9 = { const etxLz4Font lv_font_noto_tw_9 = {
.uncomp_size = 39817, .uncomp_size = 39817,
.comp_size = 32868, .comp_size = 32868,
@@ -2086,4 +2089,6 @@ const etxLz4Font lv_font_noto_tw_9 = {
.right_class_mapping = 39050, .right_class_mapping = 39050,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 40081,
}; };
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+5
View File
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -815,6 +816,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 8226, .range_length = 55425, .glyph_id_start = 306, .list_length = 62, .type = 3, .unicode_list = 2944, .glyph_id_ofs_list = 0 }, { .range_start = 8226, .range_length = 55425, .glyph_id_start = 306, .list_length = 62, .type = 3, .unicode_list = 2944, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[21439] __SDRAM;
const etxLz4Font lv_font_roboto_13 = { const etxLz4Font lv_font_roboto_13 = {
.uncomp_size = 21111, .uncomp_size = 21111,
.comp_size = 12847, .comp_size = 12847,
@@ -836,4 +839,6 @@ const etxLz4Font lv_font_roboto_13 = {
.right_class_mapping = 20743, .right_class_mapping = 20743,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 21439,
}; };
File diff suppressed because it is too large Load Diff
+5
View File
@@ -1,3 +1,4 @@
#include "definitions.h"
#include "lz4_fonts.h" #include "lz4_fonts.h"
static const uint8_t lz4FontData[] ={ static const uint8_t lz4FontData[] ={
@@ -562,6 +563,8 @@ static const etxFontCmap cmaps[] = {
{ .range_start = 8226, .range_length = 55425, .glyph_id_start = 306, .list_length = 62, .type = 3, .unicode_list = 2944, .glyph_id_ofs_list = 0 }, { .range_start = 8226, .range_length = 55425, .glyph_id_start = 306, .list_length = 62, .type = 3, .unicode_list = 2944, .glyph_id_ofs_list = 0 },
}; };
static uint8_t etxUncompBuf[14011] __SDRAM;
const etxLz4Font lv_font_roboto_9 = { const etxLz4Font lv_font_roboto_9 = {
.uncomp_size = 13683, .uncomp_size = 13683,
.comp_size = 8794, .comp_size = 8794,
@@ -583,4 +586,6 @@ const etxLz4Font lv_font_roboto_9 = {
.right_class_mapping = 13315, .right_class_mapping = 13315,
.cmaps = cmaps, .cmaps = cmaps,
.compressed = lz4FontData, .compressed = lz4FontData,
.lvglFontBuf = etxUncompBuf,
.lvglFontBufSize = 14011,
}; };
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+182 -165
View File
@@ -33,18 +33,17 @@
Designed to be used by the make_fonts.sh tool, not run standalone. Designed to be used by the make_fonts.sh tool, not run standalone.
Overview: Overview:
The font to be compressed is read from the structures in the lv_font.inc file. The font to be compressed is read from the structures in the lv_font.inc
Including and compiling with this files saves the effort of writing a parser file. Including and compiling with this files saves the effort of writing a
for the 'lvgl' font data. parser for the 'lvgl' font data. Data that can be compressed is collected
Data that can be compressed is collected into a byte array and then LZ4 compressed. into a byte array and then LZ4 compressed. The remaining data, and offsets
The remaining data, and offsets needed to rebuild the LVGL font structures are needed to rebuild the LVGL font structures are collected into custom
collected into custom structures (see lz4_fonts.h). structures (see lz4_fonts.h). Everything is then written back out to the
Everything is then written back out to the argv[1].c file to be compiled into argv[1].c file to be compiled into the EdgeTx firmware.
the EdgeTx firmware.
Note: Note:
This is dependant on the LVGL font structure formats. If the LVGL version is This is dependant on the LVGL font structure formats. If the LVGL
changed re-check that the font structure are still compatible. version is changed re-check that the font structure are still compatible.
*/ */
#include <stdio.h> #include <stdio.h>
@@ -52,10 +51,9 @@
#include "../../lv_conf.h" #include "../../lv_conf.h"
#define LV_CONF_SKIP 1 #define LV_CONF_SKIP 1
#include "lv_font.inc"
#include "lz4/lz4hc.h"
#include "../../gui/colorlcd/lz4_fonts.h" #include "../../gui/colorlcd/lz4_fonts.h"
#include "lv_font.inc"
#include "lz4/lz4hc.h"
// Need this to allow lvgl to compile. // Need this to allow lvgl to compile.
bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t* font, bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t* font,
@@ -63,189 +61,208 @@ bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t* font,
uint32_t unicode_letter, uint32_t unicode_letter,
uint32_t unicode_letter_next) uint32_t unicode_letter_next)
{ {
return true; return true;
} }
// Need this to allow lvgl to compile. // Need this to allow lvgl to compile.
const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t letter) const uint8_t* lv_font_get_bitmap_fmt_txt(const lv_font_t* font,
uint32_t letter)
{ {
return nullptr; return nullptr;
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int uncomp_size = 0; int uncomp_size = 0;
int comp_size = 0; int comp_size = 0;
// Pointers to base LVGL font strucures // Pointers to base LVGL font strucures
const lv_font_t* font = &lv_font; const lv_font_t* font = &lv_font;
lv_font_fmt_txt_dsc_t* dsc = (lv_font_fmt_txt_dsc_t*)font->dsc; lv_font_fmt_txt_dsc_t* dsc = (lv_font_fmt_txt_dsc_t*)font->dsc;
// Calculate size of data to compress // Calculate size of data to compress
uncomp_size = sizeof(glyph_bitmap) + sizeof(glyph_dsc); uncomp_size = sizeof(glyph_bitmap) + sizeof(glyph_dsc);
if (dsc->kern_classes) { if (dsc->kern_classes) {
uncomp_size += sizeof(kern_class_values) + sizeof(kern_left_class_mapping) + sizeof(kern_right_class_mapping); uncomp_size += sizeof(kern_class_values) + sizeof(kern_left_class_mapping) +
} sizeof(kern_right_class_mapping);
}
for (int i = 0; i < dsc->cmap_num; i += 1) {
if (dsc->cmaps[i].unicode_list)
uncomp_size += dsc->cmaps[i].list_length * sizeof(uint16_t);
if (dsc->cmaps[i].glyph_id_ofs_list)
uncomp_size += dsc->cmaps[i].list_length * sizeof(uint8_t);
}
// Create custom strucutre to hold font data
etxLz4Font etx_font;
memset(&etx_font, 0, sizeof(etxLz4Font));
// Copy font propeties
etx_font.line_height = font->line_height;
etx_font.base_line = font->base_line;
etx_font.subpx = font->subpx;
etx_font.underline_position = font->underline_position;
etx_font.underline_thickness = font->underline_thickness;
etx_font.kern_scale = dsc->kern_scale;
etx_font.cmap_num = dsc->cmap_num;
etx_font.bpp = dsc->bpp;
etx_font.kern_classes = dsc->kern_classes;
etx_font.bitmap_format = dsc->bitmap_format;
if (dsc->kern_classes) {
etx_font.left_class_cnt = kern_classes.left_class_cnt;
etx_font.right_class_cnt = kern_classes.right_class_cnt;
}
// Create custom cmap structure array
etxFontCmap* etx_cmaps = nullptr;
if (dsc->cmap_num > 0) {
etx_cmaps = (etxFontCmap*)malloc(dsc->cmap_num * sizeof(etxFontCmap));
memset(etx_cmaps, 0, dsc->cmap_num * sizeof(etxFontCmap));
// Copy properties
for (int i = 0; i < dsc->cmap_num; i += 1) { for (int i = 0; i < dsc->cmap_num; i += 1) {
if (dsc->cmaps[i].unicode_list) etx_cmaps[i].range_start = dsc->cmaps[i].range_start;
uncomp_size += dsc->cmaps[i].list_length * sizeof(uint16_t); etx_cmaps[i].range_length = dsc->cmaps[i].range_length;
if (dsc->cmaps[i].glyph_id_ofs_list) etx_cmaps[i].glyph_id_start = dsc->cmaps[i].glyph_id_start;
uncomp_size += dsc->cmaps[i].list_length * sizeof(uint8_t); etx_cmaps[i].list_length = dsc->cmaps[i].list_length;
etx_cmaps[i].type = dsc->cmaps[i].type;
} }
}
// Create custom strucutre to hold font data // Allocate data blob
etxLz4Font etx_font; uint8_t* data = (uint8_t*)malloc(uncomp_size);
memset(&etx_font, 0, sizeof(etxLz4Font)); // Pointer to next available space in data blob
uint8_t* next = data;
// Copy font propeties memset(data, 0, uncomp_size);
etx_font.line_height = font->line_height;
etx_font.base_line = font->base_line;
etx_font.subpx = font->subpx;
etx_font.underline_position = font->underline_position;
etx_font.underline_thickness = font->underline_thickness;
etx_font.kern_scale = dsc->kern_scale; // Copy compressable data and save offsets to each section
etx_font.cmap_num = dsc->cmap_num; // glyph_dsc is always first at offset 0 - no offset needed
etx_font.bpp = dsc->bpp; memcpy(next, glyph_dsc, sizeof(glyph_dsc));
etx_font.kern_classes = dsc->kern_classes;
etx_font.bitmap_format = dsc->bitmap_format;
if (dsc->kern_classes) { next += sizeof(glyph_dsc);
etx_font.left_class_cnt = kern_classes.left_class_cnt;
etx_font.right_class_cnt = kern_classes.right_class_cnt; // Copy cmaps array
for (int i = 0; i < dsc->cmap_num; i += 1) {
if (dsc->cmaps[i].unicode_list) {
memcpy(next, dsc->cmaps[i].unicode_list,
dsc->cmaps[i].list_length * sizeof(uint16_t));
etx_cmaps[i].unicode_list = next - data;
next += dsc->cmaps[i].list_length * sizeof(uint16_t);
} }
if (dsc->cmaps[i].glyph_id_ofs_list) {
memcpy(next, dsc->cmaps[i].glyph_id_ofs_list,
dsc->cmaps[i].list_length * sizeof(uint8_t));
etx_cmaps[i].glyph_id_ofs_list = next - data;
// Create custom cmap structure array next += dsc->cmaps[i].list_length * sizeof(uint8_t);
etxFontCmap* etx_cmaps = nullptr;
if (dsc->cmap_num > 0) {
etx_cmaps = (etxFontCmap*)malloc(dsc->cmap_num * sizeof(etxFontCmap));
memset(etx_cmaps, 0, dsc->cmap_num * sizeof(etxFontCmap));
// Copy properties
for (int i = 0; i < dsc->cmap_num; i += 1) {
etx_cmaps[i].range_start = dsc->cmaps[i].range_start;
etx_cmaps[i].range_length = dsc->cmaps[i].range_length;
etx_cmaps[i].glyph_id_start = dsc->cmaps[i].glyph_id_start;
etx_cmaps[i].list_length = dsc->cmaps[i].list_length;
etx_cmaps[i].type = dsc->cmaps[i].type;
}
} }
}
// Allocate data blob // Copy glyph_bitmap
uint8_t* data = (uint8_t*)malloc(uncomp_size); memcpy(next, glyph_bitmap, sizeof(glyph_bitmap));
// Pointer to next available space in data blob etx_font.glyph_bitmap = next - data;
uint8_t* next = data;
memset(data, 0, uncomp_size); next += sizeof(glyph_bitmap);
// Copy compressable data and save offsets to each section // Copy kern_classes (optional)
// glyph_dsc is always first at offset 0 - no offset needed if (dsc->kern_classes) {
memcpy(next, glyph_dsc, sizeof(glyph_dsc)); memcpy(next, kern_class_values, sizeof(kern_class_values));
etx_font.class_pair_values = next - data;
next += sizeof(glyph_dsc); next += sizeof(kern_class_values);
// Copy cmaps array memcpy(next, kern_left_class_mapping, sizeof(kern_left_class_mapping));
etx_font.left_class_mapping = next - data;
next += sizeof(kern_left_class_mapping);
memcpy(next, kern_right_class_mapping, sizeof(kern_right_class_mapping));
etx_font.right_class_mapping = next - data;
next += sizeof(kern_right_class_mapping);
}
// Allocate array and LZ4 compress data
uint8_t* lz4_data = (uint8_t*)malloc(uncomp_size);
comp_size = LZ4_compress_HC((const char*)data, (char*)lz4_data, uncomp_size,
uncomp_size, 12);
// Write data to file
int i;
char filename[100];
snprintf(filename, 100, "%s.c", argv[1]);
FILE* fp = fopen(filename, "w");
fprintf(fp, "#include \"definitions.h\"\n");
fprintf(fp, "#include \"lz4_fonts.h\"\n\n");
// Compressed data
fprintf(fp, "static const uint8_t lz4FontData[] ={\n");
for (i = 0; i < comp_size; i += 1) {
fprintf(fp, "0x%02x,", lz4_data[i]);
if ((i & 0x0F) == 0x0F) fprintf(fp, "\n");
}
if ((i & 0x0F) != 0) fprintf(fp, "\n");
fprintf(fp, "};\n\n");
// Cmaps
if (dsc->cmap_num > 0) {
fprintf(fp, "static const etxFontCmap cmaps[] = {\n");
for (int i = 0; i < dsc->cmap_num; i += 1) { for (int i = 0; i < dsc->cmap_num; i += 1) {
if (dsc->cmaps[i].unicode_list) { fprintf(fp,
memcpy(next, dsc->cmaps[i].unicode_list, dsc->cmaps[i].list_length * sizeof(uint16_t)); "{ .range_start = %d, .range_length = %d, .glyph_id_start = %d, "
etx_cmaps[i].unicode_list = next - data; ".list_length = %d, .type = %d, .unicode_list = %d, "
".glyph_id_ofs_list = %d },\n",
next += dsc->cmaps[i].list_length * sizeof(uint16_t); etx_cmaps[i].range_start, etx_cmaps[i].range_length,
} etx_cmaps[i].glyph_id_start, etx_cmaps[i].list_length,
if (dsc->cmaps[i].glyph_id_ofs_list) { etx_cmaps[i].type, etx_cmaps[i].unicode_list,
memcpy(next, dsc->cmaps[i].glyph_id_ofs_list, dsc->cmaps[i].list_length * sizeof(uint8_t)); etx_cmaps[i].glyph_id_ofs_list);
etx_cmaps[i].glyph_id_ofs_list = next - data;
next += dsc->cmaps[i].list_length * sizeof(uint8_t);
}
} }
// Copy glyph_bitmap
memcpy(next, glyph_bitmap, sizeof(glyph_bitmap));
etx_font.glyph_bitmap = next - data;
next += sizeof(glyph_bitmap);
// Copy kern_classes (optional)
if (dsc->kern_classes) {
memcpy(next, kern_class_values, sizeof(kern_class_values));
etx_font.class_pair_values = next - data;
next += sizeof(kern_class_values);
memcpy(next, kern_left_class_mapping, sizeof(kern_left_class_mapping));
etx_font.left_class_mapping = next - data;
next += sizeof(kern_left_class_mapping);
memcpy(next, kern_right_class_mapping, sizeof(kern_right_class_mapping));
etx_font.right_class_mapping = next - data;
next += sizeof(kern_right_class_mapping);
}
// Allocate array and LZ4 compress data
uint8_t* lz4_data = (uint8_t*)malloc(uncomp_size);
comp_size = LZ4_compress_HC((const char*)data, (char*)lz4_data, uncomp_size, uncomp_size, 12);
// Write data to file
int i;
char filename[100];
snprintf(filename, 100,"%s.c",argv[1]);
FILE* fp = fopen(filename,"w");
fprintf(fp, "#include \"lz4_fonts.h\"\n\n");
// Compressed data
fprintf(fp, "static const uint8_t lz4FontData[] ={\n");
for (i = 0; i < comp_size; i += 1) {
fprintf(fp,"0x%02x,",lz4_data[i]);
if ((i & 0x0F) == 0x0F)
fprintf(fp, "\n");
}
if ((i & 0x0F) != 0)
fprintf(fp, "\n");
fprintf(fp, "};\n\n"); fprintf(fp, "};\n\n");
}
// Cmaps // SDRAM buffer to decompress data into
if (dsc->cmap_num > 0) { int size = uncomp_size + sizeof(lv_font_t) +
fprintf(fp, "static const etxFontCmap cmaps[] = {\n"); sizeof(lv_font_fmt_txt_dsc_t) +
for (int i = 0; i < dsc->cmap_num; i += 1) { sizeof(lv_font_fmt_txt_glyph_cache_t) +
fprintf(fp,"{ .range_start = %d, .range_length = %d, .glyph_id_start = %d, .list_length = %d, .type = %d, .unicode_list = %d, .glyph_id_ofs_list = %d },\n", dsc->cmap_num * sizeof(lv_font_fmt_txt_cmap_t);
etx_cmaps[i].range_start, etx_cmaps[i].range_length, etx_cmaps[i].glyph_id_start, etx_cmaps[i].list_length, if (dsc->kern_classes) size += sizeof(lv_font_fmt_txt_kern_classes_t);
etx_cmaps[i].type, etx_cmaps[i].unicode_list, etx_cmaps[i].glyph_id_ofs_list fprintf(fp, "static uint8_t etxUncompBuf[%d] __SDRAM;\n\n", size);
);
}
fprintf(fp, "};\n\n");
}
// Custom font structure // Custom font structure
fprintf(fp,"const etxLz4Font %s = {\n", argv[1]); fprintf(fp, "const etxLz4Font %s = {\n", argv[1]);
fprintf(fp,".uncomp_size = %d,\n",uncomp_size); fprintf(fp, ".uncomp_size = %d,\n", uncomp_size);
fprintf(fp,".comp_size = %d,\n",comp_size); fprintf(fp, ".comp_size = %d,\n", comp_size);
fprintf(fp,".line_height = %d,\n",etx_font.line_height); fprintf(fp, ".line_height = %d,\n", etx_font.line_height);
fprintf(fp,".base_line = %d,\n",etx_font.base_line); fprintf(fp, ".base_line = %d,\n", etx_font.base_line);
fprintf(fp,".subpx = %d,\n",etx_font.subpx); fprintf(fp, ".subpx = %d,\n", etx_font.subpx);
fprintf(fp,".underline_position = %d,\n",etx_font.underline_position); fprintf(fp, ".underline_position = %d,\n", etx_font.underline_position);
fprintf(fp,".underline_thickness = %d,\n",etx_font.underline_thickness); fprintf(fp, ".underline_thickness = %d,\n", etx_font.underline_thickness);
fprintf(fp,".kern_scale = %d,\n",etx_font.kern_scale); fprintf(fp, ".kern_scale = %d,\n", etx_font.kern_scale);
fprintf(fp,".cmap_num = %d,\n",etx_font.cmap_num); fprintf(fp, ".cmap_num = %d,\n", etx_font.cmap_num);
fprintf(fp,".bpp = %d,\n",etx_font.bpp); fprintf(fp, ".bpp = %d,\n", etx_font.bpp);
fprintf(fp,".kern_classes = %d,\n",etx_font.kern_classes); fprintf(fp, ".kern_classes = %d,\n", etx_font.kern_classes);
fprintf(fp,".bitmap_format = %d,\n",etx_font.bitmap_format); fprintf(fp, ".bitmap_format = %d,\n", etx_font.bitmap_format);
fprintf(fp,".left_class_cnt = %d,\n",etx_font.left_class_cnt); fprintf(fp, ".left_class_cnt = %d,\n", etx_font.left_class_cnt);
fprintf(fp,".right_class_cnt = %d,\n",etx_font.right_class_cnt); fprintf(fp, ".right_class_cnt = %d,\n", etx_font.right_class_cnt);
fprintf(fp,".glyph_bitmap = %d,\n",etx_font.glyph_bitmap); fprintf(fp, ".glyph_bitmap = %d,\n", etx_font.glyph_bitmap);
fprintf(fp,".class_pair_values = %d,\n",etx_font.class_pair_values); fprintf(fp, ".class_pair_values = %d,\n", etx_font.class_pair_values);
fprintf(fp,".left_class_mapping = %d,\n",etx_font.left_class_mapping); fprintf(fp, ".left_class_mapping = %d,\n", etx_font.left_class_mapping);
fprintf(fp,".right_class_mapping = %d,\n",etx_font.right_class_mapping); fprintf(fp, ".right_class_mapping = %d,\n", etx_font.right_class_mapping);
fprintf(fp,".cmaps = cmaps,\n"); fprintf(fp, ".cmaps = cmaps,\n");
fprintf(fp,".compressed = lz4FontData,\n"); fprintf(fp, ".compressed = lz4FontData,\n");
fprintf(fp, "};\n"); fprintf(fp, ".lvglFontBuf = etxUncompBuf,\n");
fprintf(fp, ".lvglFontBufSize = %d,\n", size);
fprintf(fp, "};\n");
fclose(fp); fclose(fp);
printf("%s %d %d %d%%\n",argv[1],uncomp_size,comp_size,(comp_size * 100) / uncomp_size); printf("%s %d %d %d%%\n", argv[1], uncomp_size, comp_size,
(comp_size * 100) / uncomp_size);
} }
+4 -4
View File
@@ -116,10 +116,10 @@ function make_font_set() {
make_font_lz4 "${name}" "${ttf_normal}" 9 ${chars} --no-compress make_font_lz4 "${name}" "${ttf_normal}" 9 ${chars} --no-compress
make_font_lz4 "${name}" "${ttf_normal}" 13 ${chars} --no-compress make_font_lz4 "${name}" "${ttf_normal}" 13 ${chars} --no-compress
make_font "${name}" "${ttf_normal}" 16 ${chars} --no-compress make_font "${name}" "${ttf_normal}" 16 ${chars} --no-compress
make_font_lz4 "${name}_bold" "${ttf_bold}" 16 ${chars} make_font_lz4 "${name}_bold" "${ttf_bold}" 16 ${chars} --no-compress
make_font_w_extra_sym "${name}" "${ttf_normal}" 24 ${chars} make_font_w_extra_sym "${name}" "${ttf_normal}" 24 ${chars} --no-compress
make_font_no_sym "${name}_bold" "${ttf_bold}" 32 ${chars} make_font_no_sym "${name}_bold" "${ttf_bold}" 32 ${chars} --no-compress
make_font_no_sym "${name}_bold" "${ttf_bold}" 64 make_font_no_sym "${name}_bold" "${ttf_bold}" 64 "" --no-compress
} }
# Regular fonts # Regular fonts
+87 -91
View File
@@ -87,103 +87,99 @@ void decompressFont(int idx)
etxFont->cmap_num * sizeof(lv_font_fmt_txt_cmap_t); etxFont->cmap_num * sizeof(lv_font_fmt_txt_cmap_t);
if (etxFont->kern_classes) size += sizeof(lv_font_fmt_txt_kern_classes_t); if (etxFont->kern_classes) size += sizeof(lv_font_fmt_txt_kern_classes_t);
uint8_t* data = (uint8_t*)malloc(size); // Init SDRAM buffer
if (data) { uint8_t* data = etxFont->lvglFontBuf;
memset(data, 0, size); memset(data, 0, etxFont->lvglFontBufSize);
// Pointer to next free area in data block
uint8_t* next = data;
// 'Create' lv_font_t structure // Pointer to next free area in data block
lv_font_t* lvglFont = (lv_font_t*)next; uint8_t* next = data;
next += sizeof(lv_font_t);
// 'Create' lv_font_fmt_txt_dsc_t structure // 'Create' lv_font_t structure
lv_font_fmt_txt_dsc_t* lvglFontDsc = (lv_font_fmt_txt_dsc_t*)next; lv_font_t* lvglFont = (lv_font_t*)next;
next += sizeof(lv_font_fmt_txt_dsc_t); next += sizeof(lv_font_t);
// 'Create' lv_font_fmt_txt_glyph_cache_t structure // 'Create' lv_font_fmt_txt_dsc_t structure
lv_font_fmt_txt_glyph_cache_t* lvglCache = lv_font_fmt_txt_dsc_t* lvglFontDsc = (lv_font_fmt_txt_dsc_t*)next;
(lv_font_fmt_txt_glyph_cache_t*)next; next += sizeof(lv_font_fmt_txt_dsc_t);
next += sizeof(lv_font_fmt_txt_glyph_cache_t);
// 'Create' lv_font_fmt_txt_kern_classes_t structure (optional) // 'Create' lv_font_fmt_txt_glyph_cache_t structure
lv_font_fmt_txt_kern_classes_t* lvglKernClasses = nullptr; lv_font_fmt_txt_glyph_cache_t* lvglCache =
if (etxFont->kern_classes) { (lv_font_fmt_txt_glyph_cache_t*)next;
lvglKernClasses = (lv_font_fmt_txt_kern_classes_t*)next; next += sizeof(lv_font_fmt_txt_glyph_cache_t);
next += sizeof(lv_font_fmt_txt_kern_classes_t);
}
// 'Create' lv_font_fmt_txt_cmap_t structure array // 'Create' lv_font_fmt_txt_kern_classes_t structure (optional)
lv_font_fmt_txt_cmap_t* lvglCmaps = (lv_font_fmt_txt_cmap_t*)next; lv_font_fmt_txt_kern_classes_t* lvglKernClasses = nullptr;
next += sizeof(lv_font_fmt_txt_cmap_t) * etxFont->cmap_num; if (etxFont->kern_classes) {
lvglKernClasses = (lv_font_fmt_txt_kern_classes_t*)next;
// Decompress the compressed data into the remaining space next += sizeof(lv_font_fmt_txt_kern_classes_t);
// 'next' is now the start of the uncompressed data
LZ4_decompress_safe((const char*)etxFont->compressed, (char*)next,
etxFont->comp_size, etxFont->uncomp_size);
// Rebuild the lv_font_t structure
// Relocate pointers
lvglFont->get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt;
lvglFont->get_glyph_bitmap = lv_font_get_bitmap_fmt_txt;
lvglFont->dsc = lvglFontDsc;
// Fill in other properties
lvglFont->line_height = etxFont->line_height;
lvglFont->base_line = etxFont->base_line;
lvglFont->subpx = etxFont->subpx;
lvglFont->underline_position = etxFont->underline_position;
lvglFont->underline_thickness = etxFont->underline_thickness;
// Rebuild the lv_font_fmt_txt_dsc_t structure
// Relocate pointers
lvglFontDsc->glyph_bitmap = &next[etxFont->glyph_bitmap];
lvglFontDsc->glyph_dsc = (lv_font_fmt_txt_glyph_dsc_t*)&next[0];
lvglFontDsc->cmaps = lvglCmaps;
lvglFontDsc->kern_dsc = lvglKernClasses;
lvglFontDsc->kern_classes = etxFont->kern_classes;
lvglFontDsc->bitmap_format = etxFont->bitmap_format;
lvglFontDsc->cache = lvglCache;
// Fill in other properties
lvglFontDsc->kern_scale = etxFont->kern_scale;
lvglFontDsc->cmap_num = etxFont->cmap_num;
lvglFontDsc->bpp = etxFont->bpp;
// Rebuild the lv_font_fmt_txt_kern_classes_t structure
if (etxFont->kern_classes) {
// Relocate pointers
lvglKernClasses->class_pair_values =
(int8_t*)&next[etxFont->class_pair_values];
lvglKernClasses->left_class_mapping = &next[etxFont->left_class_mapping];
lvglKernClasses->right_class_mapping =
&next[etxFont->right_class_mapping];
// Fill in other properties
lvglKernClasses->left_class_cnt = etxFont->left_class_cnt;
lvglKernClasses->right_class_cnt = etxFont->right_class_cnt;
}
// Rebuild the lv_font_t lv_font_fmt_txt_cmap_t structure array
for (int i = 0; i < etxFont->cmap_num; i += 1) {
// Relocate pointers
if (etxFont->cmaps[i].unicode_list)
lvglCmaps[i].unicode_list =
(uint16_t*)&next[etxFont->cmaps[i].unicode_list];
if (etxFont->cmaps[i].glyph_id_ofs_list)
lvglCmaps[i].glyph_id_ofs_list =
&next[etxFont->cmaps[i].glyph_id_ofs_list];
// Fill in other properties
lvglCmaps[i].range_start = etxFont->cmaps[i].range_start;
lvglCmaps[i].range_length = etxFont->cmaps[i].range_length;
lvglCmaps[i].glyph_id_start = etxFont->cmaps[i].glyph_id_start;
lvglCmaps[i].list_length = etxFont->cmaps[i].list_length;
lvglCmaps[i].type = etxFont->cmaps[i].type;
}
// Save LVGL font to lookup array
lvglFontTable[idx] = lvglFont;
} else {
TRACE("No memory to decompress font %d", idx);
lvglFontTable[idx] = lvglFontTable[0];
} }
// 'Create' lv_font_fmt_txt_cmap_t structure array
lv_font_fmt_txt_cmap_t* lvglCmaps = (lv_font_fmt_txt_cmap_t*)next;
next += sizeof(lv_font_fmt_txt_cmap_t) * etxFont->cmap_num;
// Decompress the compressed data into the remaining space
// 'next' is now the start of the uncompressed data
LZ4_decompress_safe((const char*)etxFont->compressed, (char*)next,
etxFont->comp_size, etxFont->uncomp_size);
// Rebuild the lv_font_t structure
// Relocate pointers
lvglFont->get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt;
lvglFont->get_glyph_bitmap = lv_font_get_bitmap_fmt_txt;
lvglFont->dsc = lvglFontDsc;
// Fill in other properties
lvglFont->line_height = etxFont->line_height;
lvglFont->base_line = etxFont->base_line;
lvglFont->subpx = etxFont->subpx;
lvglFont->underline_position = etxFont->underline_position;
lvglFont->underline_thickness = etxFont->underline_thickness;
// Rebuild the lv_font_fmt_txt_dsc_t structure
// Relocate pointers
lvglFontDsc->glyph_bitmap = &next[etxFont->glyph_bitmap];
lvglFontDsc->glyph_dsc = (lv_font_fmt_txt_glyph_dsc_t*)&next[0];
lvglFontDsc->cmaps = lvglCmaps;
lvglFontDsc->kern_dsc = lvglKernClasses;
lvglFontDsc->kern_classes = etxFont->kern_classes;
lvglFontDsc->bitmap_format = etxFont->bitmap_format;
lvglFontDsc->cache = lvglCache;
// Fill in other properties
lvglFontDsc->kern_scale = etxFont->kern_scale;
lvglFontDsc->cmap_num = etxFont->cmap_num;
lvglFontDsc->bpp = etxFont->bpp;
// Rebuild the lv_font_fmt_txt_kern_classes_t structure
if (etxFont->kern_classes) {
// Relocate pointers
lvglKernClasses->class_pair_values =
(int8_t*)&next[etxFont->class_pair_values];
lvglKernClasses->left_class_mapping = &next[etxFont->left_class_mapping];
lvglKernClasses->right_class_mapping = &next[etxFont->right_class_mapping];
// Fill in other properties
lvglKernClasses->left_class_cnt = etxFont->left_class_cnt;
lvglKernClasses->right_class_cnt = etxFont->right_class_cnt;
}
// Rebuild the lv_font_t lv_font_fmt_txt_cmap_t structure array
for (int i = 0; i < etxFont->cmap_num; i += 1) {
// Relocate pointers
if (etxFont->cmaps[i].unicode_list)
lvglCmaps[i].unicode_list =
(uint16_t*)&next[etxFont->cmaps[i].unicode_list];
if (etxFont->cmaps[i].glyph_id_ofs_list)
lvglCmaps[i].glyph_id_ofs_list =
&next[etxFont->cmaps[i].glyph_id_ofs_list];
// Fill in other properties
lvglCmaps[i].range_start = etxFont->cmaps[i].range_start;
lvglCmaps[i].range_length = etxFont->cmaps[i].range_length;
lvglCmaps[i].glyph_id_start = etxFont->cmaps[i].glyph_id_start;
lvglCmaps[i].list_length = etxFont->cmaps[i].list_length;
lvglCmaps[i].type = etxFont->cmaps[i].type;
}
// Save LVGL font to lookup array
lvglFontTable[idx] = lvglFont;
} }
#endif // BOOT #endif // BOOT
+3 -1
View File
@@ -74,7 +74,9 @@ typedef struct {
uint32_t left_class_mapping; // lv_font_fmt_txt_kern_classes_t.left_class_mapping uint32_t left_class_mapping; // lv_font_fmt_txt_kern_classes_t.left_class_mapping
uint32_t right_class_mapping; // lv_font_fmt_txt_kern_classes_t.right_class_mapping uint32_t right_class_mapping; // lv_font_fmt_txt_kern_classes_t.right_class_mapping
// Pointers to cmaps and compressed data // Pointers to cmaps, compressed data and buffer for uncompressed data
const etxFontCmap* cmaps; const etxFontCmap* cmaps;
const uint8_t* compressed; const uint8_t* compressed;
uint8_t* lvglFontBuf;
uint32_t lvglFontBufSize;
} etxLz4Font; } etxLz4Font;