diff --git a/App/font.c b/App/font.c index e1a3194e..d81f42f9 100644 --- a/App/font.c +++ b/App/font.c @@ -435,6 +435,8 @@ const uint8_t gFontSmallDigits[11][7] = {0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00} // '-' }; */ +#if 0 +// Uncompressed small-font references kept for byte-for-byte verification. const uint8_t gFontSmall[95-1][6] = { // {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // ' ' @@ -634,6 +636,90 @@ const uint8_t gFontSmall[95-1][6] = {0x0C, 0x06, 0x0C, 0x18, 0x0C, 0x00} }; #endif +#endif + +// Each glyph contains six columns of seven visible pixels: 42 packed bits. +const uint8_t gFontSmallPacked[FONT_SMALL_PACKED_SIZE] = +{ + 0x00, 0x80, 0x17, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x03, 0x00, 0x40, 0xF1, 0x51, 0x7C, + 0x14, 0x80, 0x29, 0xF9, 0x4F, 0xCA, 0x00, 0xE3, 0x09, 0x82, 0x20, 0x0E, 0xC3, 0x96, + 0xCD, 0xAA, 0x08, 0x0A, 0x00, 0x1C, 0x0E, 0x00, 0x00, 0x80, 0x23, 0x0A, 0x02, 0x00, + 0x80, 0xA0, 0x88, 0x03, 0x00, 0x00, 0x54, 0x1C, 0x8E, 0x0A, 0x80, 0x40, 0xF8, 0x10, + 0x08, 0x00, 0x00, 0x08, 0x06, 0x01, 0x00, 0x00, 0x04, 0x02, 0x81, 0x00, 0x00, 0x00, + 0x60, 0x30, 0x00, 0x00, 0x04, 0x41, 0x10, 0x04, 0x81, 0x2F, 0x18, 0x0C, 0x06, 0x7D, + 0x00, 0xA0, 0xF0, 0x0F, 0x04, 0x8A, 0xA3, 0xD1, 0x64, 0xD2, 0x28, 0x0A, 0x26, 0x93, + 0x49, 0x1B, 0x86, 0x22, 0x89, 0xFC, 0x21, 0xA7, 0x62, 0xB1, 0x58, 0xCC, 0xF9, 0x92, + 0xC9, 0x64, 0x52, 0x16, 0x08, 0xC4, 0x13, 0x85, 0x81, 0x2D, 0x99, 0x4C, 0x26, 0x6D, + 0xC6, 0x64, 0x32, 0x99, 0xF2, 0x00, 0x00, 0x6C, 0x36, 0x00, 0x00, 0x00, 0xB2, 0x59, + 0x00, 0x00, 0x82, 0x22, 0x0A, 0x02, 0x00, 0x14, 0x0A, 0x85, 0x42, 0x01, 0x00, 0x82, + 0x22, 0x0A, 0x02, 0x20, 0x08, 0x44, 0x13, 0x06, 0x00, 0x4C, 0xA9, 0x94, 0xF2, 0x00, + 0xFE, 0x44, 0x22, 0x91, 0xF0, 0xFF, 0x93, 0xC9, 0x64, 0xD2, 0xE6, 0x0B, 0x06, 0x83, + 0x41, 0xD1, 0x3F, 0x18, 0x0C, 0x06, 0x7D, 0xFF, 0x64, 0x32, 0x99, 0x0C, 0xFE, 0x13, + 0x89, 0x44, 0x22, 0xE0, 0x0B, 0x26, 0x93, 0x49, 0xDD, 0x1F, 0x81, 0x40, 0x20, 0xFE, + 0xC1, 0xE0, 0x3F, 0x18, 0x04, 0x80, 0x82, 0xC1, 0x5F, 0x20, 0xF0, 0x47, 0x30, 0x24, + 0x21, 0xE0, 0x1F, 0x08, 0x04, 0x02, 0x81, 0x7F, 0x01, 0x81, 0x20, 0xF8, 0xFF, 0x05, + 0x04, 0x04, 0xE4, 0xEF, 0x0B, 0x06, 0x83, 0x41, 0xDF, 0x3F, 0x91, 0x48, 0x24, 0x0C, + 0xBE, 0x60, 0x34, 0x1C, 0xF4, 0xFD, 0x13, 0x89, 0x4C, 0xCA, 0x68, 0x4A, 0x26, 0x93, + 0x49, 0x59, 0x20, 0xF0, 0x0F, 0x04, 0x00, 0x3F, 0x20, 0x10, 0x08, 0xFC, 0x1D, 0x70, + 0x40, 0x20, 0xEE, 0xF0, 0x03, 0xC2, 0x60, 0xC0, 0xDF, 0x98, 0x82, 0x40, 0x50, 0xC6, + 0x07, 0x04, 0x1C, 0x71, 0x00, 0x84, 0xA3, 0xC9, 0xE2, 0x30, 0x08, 0xF8, 0x07, 0x83, + 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0xC0, 0x00, 0x40, 0x30, 0xF8, 0x07, 0x10, 0x04, + 0x01, 0x01, 0x01, 0x00, 0x04, 0x02, 0x81, 0x40, 0x20, 0x60, 0x70, 0x30, 0x00, 0x00, + 0x20, 0x2A, 0x95, 0x8A, 0x07, 0xFC, 0x89, 0x44, 0x22, 0x0E, 0x80, 0x23, 0x12, 0x89, + 0x28, 0x00, 0x8E, 0x48, 0x24, 0xFE, 0x01, 0x38, 0x2A, 0x95, 0x8A, 0x04, 0xF0, 0x15, + 0x0A, 0x85, 0x00, 0x80, 0xA5, 0x52, 0xA9, 0x3C, 0xC0, 0x9F, 0x40, 0x20, 0xE0, 0x01, + 0x00, 0x80, 0x1E, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x1E, 0x00, 0x00, 0xF8, 0x43, 0x50, + 0x44, 0x00, 0x00, 0xF0, 0x03, 0x02, 0x00, 0x7C, 0x02, 0x9F, 0x80, 0x07, 0xF0, 0x09, + 0x04, 0x02, 0x1E, 0x80, 0x23, 0x12, 0x89, 0x38, 0x00, 0x9F, 0x42, 0xA1, 0x20, 0x00, + 0x08, 0x0A, 0x85, 0xC2, 0x07, 0xF2, 0x09, 0x04, 0x02, 0x02, 0x80, 0xA0, 0x52, 0xA9, + 0x20, 0xC0, 0x8F, 0x48, 0x24, 0x02, 0x01, 0x3C, 0x20, 0x10, 0xC8, 0x03, 0x30, 0x60, + 0x40, 0x18, 0x03, 0xC0, 0x03, 0xC2, 0x80, 0x3C, 0x00, 0x11, 0x05, 0x41, 0x11, 0x01, + 0x0C, 0x28, 0x14, 0xCA, 0x03, 0x10, 0xC9, 0x54, 0x26, 0x11, 0x80, 0xB0, 0x05, 0x01, + 0x00, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00, 0x40, 0xD0, 0x86, 0x00, 0x10, 0x04, + 0x04, 0x04, 0x01, 0x00, +}; + +#ifdef ENABLE_SMALL_BOLD +const uint8_t gFontSmallBoldPacked[FONT_SMALL_PACKED_SIZE] = +{ + 0x00, 0x80, 0xD7, 0x0B, 0x00, 0x18, 0x0C, 0x00, 0x83, 0x01, 0x40, 0xF1, 0x51, 0x7C, + 0x14, 0x80, 0x6B, 0xFD, 0x5F, 0xEB, 0x00, 0xE3, 0x19, 0x86, 0x61, 0x1E, 0xC3, 0x96, + 0xCD, 0xAA, 0x08, 0x0A, 0x00, 0x1C, 0x0E, 0x00, 0x00, 0x80, 0xE3, 0x1B, 0x07, 0x01, + 0x80, 0xE0, 0xD8, 0xC7, 0x01, 0x00, 0x54, 0x1C, 0x8E, 0x0A, 0x80, 0xC1, 0xF8, 0xFD, + 0x18, 0x0C, 0x00, 0x08, 0x06, 0x01, 0x00, 0x00, 0x0C, 0x06, 0x83, 0x01, 0x00, 0x00, + 0x60, 0x30, 0x00, 0x00, 0x86, 0x61, 0x18, 0x86, 0x81, 0xEF, 0x3F, 0x1E, 0xFF, 0x7D, + 0x64, 0xF3, 0xFF, 0x0F, 0x06, 0x8B, 0xE7, 0xFB, 0xFD, 0xDB, 0x3C, 0x1E, 0xAF, 0xD7, + 0x7F, 0x1B, 0x8E, 0x67, 0xFB, 0xFF, 0x61, 0xEF, 0xF7, 0x7A, 0xBD, 0x9F, 0xF9, 0xFE, + 0xEB, 0xF5, 0x5E, 0x36, 0x18, 0xCC, 0xF7, 0x8F, 0x83, 0xED, 0xBF, 0x5E, 0xFF, 0x6D, + 0x86, 0xF7, 0x7A, 0xFD, 0xF7, 0x01, 0x00, 0x6C, 0x36, 0x00, 0x00, 0x00, 0xB2, 0x59, + 0x00, 0x00, 0x82, 0x22, 0x0A, 0x02, 0x00, 0x36, 0x9B, 0xCD, 0x66, 0x03, 0x00, 0x82, + 0x22, 0x0A, 0x02, 0x60, 0x38, 0x4C, 0xB7, 0x1F, 0x07, 0x6C, 0xBF, 0xDE, 0xFF, 0x7D, + 0xFE, 0xFF, 0x66, 0xF3, 0xF7, 0xFF, 0xFF, 0xEB, 0xF5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x8E, 0xCF, 0x66, 0xFF, 0xFF, 0x3C, 0xBF, 0xD5, 0xEA, 0x65, 0xF8, 0xFF, + 0x9B, 0x8D, 0x00, 0xC0, 0xF0, 0x5A, 0xAD, 0x7E, 0xDE, 0xFF, 0xCF, 0x60, 0xF0, 0xF1, + 0x00, 0x80, 0x5E, 0x0F, 0x00, 0xC0, 0xC0, 0xE0, 0x7E, 0x0F, 0xF0, 0xFF, 0x63, 0x78, + 0x7E, 0x33, 0xE0, 0xF7, 0x07, 0x02, 0x00, 0x7C, 0x3E, 0x06, 0xC3, 0xE7, 0xF3, 0xF9, + 0x0C, 0x06, 0x1F, 0xCF, 0xF3, 0x9B, 0xCD, 0x7E, 0x9E, 0xDF, 0x6F, 0xB3, 0xF9, 0x38, + 0x1C, 0x9F, 0xCD, 0xEF, 0x07, 0xF3, 0xF9, 0x0C, 0x06, 0x06, 0xC0, 0xF4, 0x5A, 0xAD, + 0x76, 0xD0, 0xEF, 0xCF, 0x66, 0x83, 0x01, 0x3C, 0x3E, 0x18, 0xCC, 0xE7, 0x31, 0x78, + 0x70, 0x38, 0x8F, 0xC1, 0xE3, 0xC3, 0x60, 0x7C, 0x1E, 0x91, 0x8D, 0xC3, 0xB1, 0x89, + 0x06, 0x37, 0x1A, 0xED, 0xF7, 0x99, 0xED, 0x7E, 0xB7, 0x19, 0x80, 0xF0, 0xDD, 0x83, + 0x00, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x80, 0xE0, 0xDD, 0x87, 0x00, 0x30, 0x0C, + 0x0C, 0x0C, 0x03, 0x00, +}; +#endif //#ifdef ENABLE_SPECTRUM const uint8_t gFont3x5[][3] = diff --git a/App/font.h b/App/font.h index 0e339a97..af388cd3 100644 --- a/App/font.h +++ b/App/font.h @@ -23,9 +23,14 @@ void FONT_DrawBigGlyph(uint8_t glyph, uint8_t *top, uint8_t *bottom); extern const uint8_t gFontBigDigits[11][26 - 6]; extern const uint8_t gFont3x5[96][3]; -extern const uint8_t gFontSmall[95 - 1][6]; + +#define FONT_SMALL_WIDTH 6u +#define FONT_SMALL_GLYPH_COUNT (95u - 1u) +#define FONT_SMALL_PACKED_SIZE ((FONT_SMALL_GLYPH_COUNT * FONT_SMALL_WIDTH * 7u + 7u) / 8u) + +extern const uint8_t gFontSmallPacked[FONT_SMALL_PACKED_SIZE]; #ifdef ENABLE_SMALL_BOLD - extern const uint8_t gFontSmallBold[95 - 1][6]; + extern const uint8_t gFontSmallBoldPacked[FONT_SMALL_PACKED_SIZE]; #endif #endif diff --git a/App/ui/helper.c b/App/ui/helper.c index ef67f018..8931e956 100644 --- a/App/ui/helper.c +++ b/App/ui/helper.c @@ -48,15 +48,22 @@ void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uin } } -void UI_PrintStringBuffer(const char *pString, uint8_t * buffer, uint32_t char_width, const uint8_t *font) +void UI_PrintStringBuffer(const char *pString, uint8_t *buffer, const uint8_t *font) { const size_t Length = strlen(pString); - const unsigned int char_spacing = char_width + 1; + const unsigned int char_spacing = FONT_SMALL_WIDTH + 1u; for (size_t i = 0; i < Length; i++) { const unsigned int index = pString[i] - ' ' - 1; if (pString[i] > ' ' && pString[i] < 127) { const uint32_t offset = i * char_spacing + 1; - memcpy(buffer + offset, font + index * char_width, char_width); + uint16_t bit = index * FONT_SMALL_WIDTH * 7u; + + for (uint8_t column = 0; column < FONT_SMALL_WIDTH; column++) { + const uint16_t byte = bit >> 3; + const uint16_t packed = font[byte] | ((uint16_t)font[byte + 1u] << 8); + buffer[offset + column] = (packed >> (bit & 7u)) & 0x7Fu; + bit += 7u; + } } } } @@ -82,22 +89,22 @@ void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Lin } } -void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, uint8_t char_width, const uint8_t *font) +void UI_PrintStringSmall(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, const uint8_t *font) { const size_t Length = strlen(pString); - const unsigned int char_spacing = char_width + 1; + const unsigned int char_spacing = FONT_SMALL_WIDTH + 1u; if (End > Start) { Start += (((End - Start) - Length * char_spacing) + 1) / 2; } - UI_PrintStringBuffer(pString, gFrameBuffer[Line] + Start, char_width, font); + UI_PrintStringBuffer(pString, gFrameBuffer[Line] + Start, font); } void UI_PrintStringSmallNormal(const char *pString, uint8_t Start, uint8_t End, uint8_t Line) { - UI_PrintStringSmall(pString, Start, End, Line, ARRAY_SIZE(gFontSmall[0]), (const uint8_t *)gFontSmall); + UI_PrintStringSmall(pString, Start, End, Line, gFontSmallPacked); } void UI_PrintStringSmallNormalInverse(const char *pString, uint8_t Start, uint8_t End, uint8_t Line) @@ -132,31 +139,27 @@ void UI_PrintStringSmallNormalInverse(const char *pString, uint8_t Start, uint8_ void UI_PrintStringSmallBold(const char *pString, uint8_t Start, uint8_t End, uint8_t Line) { #ifdef ENABLE_SMALL_BOLD - const uint8_t *font = (uint8_t *)gFontSmallBold; - const uint8_t char_width = ARRAY_SIZE(gFontSmallBold[0]); + const uint8_t *font = gFontSmallBoldPacked; #else - const uint8_t *font = (uint8_t *)gFontSmall; - const uint8_t char_width = ARRAY_SIZE(gFontSmall[0]); + const uint8_t *font = gFontSmallPacked; #endif - UI_PrintStringSmall(pString, Start, End, Line, char_width, font); + UI_PrintStringSmall(pString, Start, End, Line, font); } void UI_PrintStringSmallBufferNormal(const char *pString, uint8_t * buffer) { - UI_PrintStringBuffer(pString, buffer, ARRAY_SIZE(gFontSmall[0]), (uint8_t *)gFontSmall); + UI_PrintStringBuffer(pString, buffer, gFontSmallPacked); } void UI_PrintStringSmallBufferBold(const char *pString, uint8_t * buffer) { #ifdef ENABLE_SMALL_BOLD - const uint8_t *font = (uint8_t *)gFontSmallBold; - const uint8_t char_width = ARRAY_SIZE(gFontSmallBold[0]); + const uint8_t *font = gFontSmallBoldPacked; #else - const uint8_t *font = (uint8_t *)gFontSmall; - const uint8_t char_width = ARRAY_SIZE(gFontSmall[0]); + const uint8_t *font = gFontSmallPacked; #endif - UI_PrintStringBuffer(pString, buffer, char_width, font); + UI_PrintStringBuffer(pString, buffer, font); } void UI_DisplayFrequency(const char *string, uint8_t X, uint8_t Y, bool center) diff --git a/App/ui/menu.c b/App/ui/menu.c index f4c9b35a..692d94b9 100644 --- a/App/ui/menu.c +++ b/App/ui/menu.c @@ -771,7 +771,7 @@ bool edit_is_uppercase = false; static void UI_MENU_DrawTopRightRoundedBadge(const char *text, const uint8_t line, const bool center_in_area, const uint8_t area_x1, const uint8_t area_x2) { const size_t length = strlen(text); - const size_t char_pitch = ARRAY_SIZE(gFontSmall[0]) + 1u; + const size_t char_pitch = FONT_SMALL_WIDTH + 1u; const size_t text_width = length * char_pitch; const size_t capsule_span = text_width + 1u; // matches UI_PrintStringSmallNormalInverse x_end computation uint8_t text_x; diff --git a/App/ui/welcome.c b/App/ui/welcome.c index ec2bfaf1..999a1a56 100644 --- a/App/ui/welcome.c +++ b/App/ui/welcome.c @@ -310,7 +310,7 @@ void UI_DisplayWelcome(void) UI_PrintString(WelcomeString1, 0, 127, 2, 10); #ifdef ENABLE_FEAT_F4HWN - const size_t version_width = strlen(DisplayVersion) * (ARRAY_SIZE(gFontSmall[0]) + 1u); + const size_t version_width = strlen(DisplayVersion) * (FONT_SMALL_WIDTH + 1u); const uint8_t version_x = version_width < LCD_WIDTH ? (uint8_t)((LCD_WIDTH - version_width + 1u) / 2u) : 0u;