use RLE compressed fonts on Horus

This commit is contained in:
Raphael Coeffic
2018-07-06 08:59:34 +02:00
parent caaba0ab3f
commit 96afa57d84
10 changed files with 106 additions and 14 deletions
+41 -4
View File
@@ -19,6 +19,7 @@
*/
#include "opentx.h"
#include "rle.h"
#if !defined(BOOT)
const uint16_t font_tinsize_specs[] = {
@@ -82,17 +83,18 @@ const pm_uchar font_stdsizebold[] = {
#if !defined(BOOT)
const uint16_t * const fontspecsTable[16] = {
font_stdsize_specs, font_tinsize_specs, font_smlsize_specs, font_midsize_specs, font_dblsize_specs, font_xxlsize_specs, font_stdsize_specs, font_stdsize_specs,
font_stdsize_specs, font_tinsize_specs, font_smlsize_specs, font_midsize_specs, font_dblsize_specs, font_xxlsize_specs, font_stdsize_specs, font_stdsize_specs,
font_stdsizebold_specs, font_tinsize_specs, font_smlsize_specs, font_midsize_specs, font_dblsize_specs, font_xxlsize_specs, font_stdsize_specs, font_stdsize_specs
};
const uint8_t * const fontsTable[16] = {
font_stdsize, font_tinsize, font_smlsize, font_midsize, font_dblsize, font_xxlsize, font_stdsize, font_stdsize,
const uint8_t * fontsTable[16] = {
font_stdsize, font_tinsize, font_smlsize, font_midsize, font_dblsize, font_xxlsize, font_stdsize, font_stdsize,
font_stdsizebold, font_tinsize, font_smlsize, font_midsize, font_dblsize, font_xxlsize, font_stdsize, font_stdsize
};
#else
const uint16_t * const fontspecsTable[1] = { font_stdsize_specs };
const uint8_t * const fontsTable[1] = { font_stdsize };
const uint8_t * fontsTable[1] = { font_stdsize };
#endif
BitmapBuffer * fontCache[2] = { NULL, NULL };
@@ -117,3 +119,38 @@ void loadFontCache()
fontCache[0] = createFontCache(fontsTable[0], TEXT_COLOR, TEXT_BGCOLOR);
fontCache[1] = createFontCache(fontsTable[0], TEXT_INVERTED_COLOR, TEXT_INVERTED_BGCOLOR);
}
static uint8_t* decompressFont(const uint8_t* font)
{
uint16_t width = *((uint16_t *)font);
uint16_t height = *(((uint16_t *)font)+1);
size_t font_size = width * height;
uint8_t* dec_buf = (uint8_t*)malloc(font_size + 4);
// copy width / height
memcpy(dec_buf,font,4);
rle_decode_8bit(dec_buf+4, font_size, font+4);
return dec_buf;
}
void loadFonts()
{
static bool fonts_loaded = false;
if (fonts_loaded) return;
#if !defined(BOOT)
int i=0;
for (; i<9; i++)
fontsTable[i] = decompressFont(fontsTable[i]);
for (; i<16; i++)
fontsTable[i] = fontsTable[i-9];
#else
fontsTable[0] = decompressFont(fontsTable[0]);
#endif
fonts_loaded = true;
}
+38
View File
@@ -0,0 +1,38 @@
#include "rle.h"
#include "debug.h"
#include <string.h>
int rle_decode_8bit(unsigned char* dest, unsigned int dest_size, const unsigned char* src)
{
//unsigned char count = 0;
unsigned char prev_byte = 0;
bool prev_byte_valid = false;
const unsigned char* dest_end = dest + dest_size;
unsigned char* d = dest;
while(d < dest_end) {
*d++ = *src;
if (prev_byte_valid && (*src == prev_byte)) {
src++;
if (d + *src > dest + dest_size) {
TRACE("rle_decode_8bit: destination overflow!\n");
return -1;
}
memset(d, prev_byte, *src);
d += *src++;
prev_byte_valid = false;
}
else {
prev_byte = *src++;
prev_byte_valid = true;
}
}
return d - dest;
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef _rle_h_
#define _rle_h_
int rle_decode_8bit(unsigned char* dest, unsigned int dest_size, const unsigned char* src);
#endif