Simon Wood wrote:
>
> For ELKSibo I have had to include a font bit map (as I have to draw each
> character to the LCD), this only has a few of the 255 ASCII codes and is the
> form:
> ASCII Value, data, data, data, etc,
>
> The renderer compares the first byte with it's desired character and moves
> to the next character should they not match.
>
> I would like to sequence the data so that the most common characters are
> near the start of the list and therefore speed up the display driver
> (believe me every little bit helps).
>
> Does anyone have letter probability table I could use??? (or any idea how to
> generate one)
>
> Simon Wood
>
How about something like this? The code should be small and fast,
and the data would be bigger only by the number of holes between
MIN_FONT_CHAR and MAX_FONT_CHAR.
#define MIN_FONT_CHAR 0x20 /* ? */
#define MAX_FONT_CHAR 0x7e /* ? */
#define N_CHAR (MAX_FONT_CHAR - MIN_FONT_CHAR + 1)
#define UNPRINTABLE N_CHAR
#define BYTES_PER_GLYPH 8 /* ? */
static unsigned char lookup_index[N_CHAR] = {
0, 1, UNPRINTABLE, 2, UNPRINTABLE, /* ... */
};
static unsigned char font_data[N_CHAR + 1][BYTES_PER_GLYPH] = {
{0,0,0,0,0,0,0,0}, /* data for MIN_FONT_CHAR */
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
/* ... */
{0,0,0,0,0,0,0,0}, /* data for MAX_FONT_CHAR */
{0,0,0,0,0,0,0,0} /* data for UNPRINTABLE char */
};
unsigned char *get_font_data(unsigned char c) {
if (c < MIN_FONT_CHAR || c > MAX_FONT_CHAR) {
return font_data[UNPRINTABLE];
}
return font_data[lookup_index[c - MIN_FONT_CHAR]];
}