mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 06:52:20 +00:00
[CHG] BMF function are a bit faster, character definition is taken inside an array
This commit is contained in:
parent
0432dd951c
commit
cde17f778f
3 changed files with 25 additions and 31 deletions
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
|||
|
||||
/**
|
||||
* Load a ByteMap font structure from a buffer.
|
||||
* File format version 1.1 is used, more information could be found at http://bmf.wz.cz/bmf-format.htm
|
||||
* @param my_bmf The ByteMap font buffer to load.
|
||||
* @return A GRRLIB_bytemapFont structure filled with BMF information.
|
||||
* @see GRRLIB_FreeBMF
|
||||
|
@ -34,7 +35,7 @@ THE SOFTWARE.
|
|||
GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
|
||||
GRRLIB_bytemapFont *fontArray = (struct GRRLIB_bytemapFont *)malloc(sizeof(GRRLIB_bytemapFont));
|
||||
u32 i, j = 1;
|
||||
u8 lineheight, usedcolors, highestcolor, nbPalette;
|
||||
u8 lineheight, usedcolors, highestcolor, nbPalette, c;
|
||||
short int sizeover, sizeunder, sizeinner, numcolpal;
|
||||
u16 nbPixels;
|
||||
|
||||
|
@ -58,19 +59,18 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) {
|
|||
memcpy(fontArray->name, &my_bmf[18 + numcolpal], j);
|
||||
j = 18 + numcolpal + j;
|
||||
fontArray->nbChar = (my_bmf[j] | my_bmf[j+1]<<8);
|
||||
fontArray->charDef = (GRRLIB_bytemapChar *)calloc(fontArray->nbChar, sizeof(GRRLIB_bytemapChar));
|
||||
j++;
|
||||
for (i=0; i < fontArray->nbChar; i++) {
|
||||
fontArray->charDef[i].character = my_bmf[++j];
|
||||
fontArray->charDef[i].width = my_bmf[++j];
|
||||
fontArray->charDef[i].height = my_bmf[++j];
|
||||
fontArray->charDef[i].relx = my_bmf[++j];
|
||||
fontArray->charDef[i].rely = my_bmf[++j];
|
||||
fontArray->charDef[i].kerning = my_bmf[++j];
|
||||
nbPixels = fontArray->charDef[i].width * fontArray->charDef[i].height;
|
||||
fontArray->charDef[i].data = (u8 *)malloc(nbPixels);
|
||||
if (nbPixels && fontArray->charDef[i].data) {
|
||||
memcpy(fontArray->charDef[i].data, &my_bmf[++j], nbPixels);
|
||||
c = my_bmf[++j];
|
||||
fontArray->charDef[c].width = my_bmf[++j];
|
||||
fontArray->charDef[c].height = my_bmf[++j];
|
||||
fontArray->charDef[c].relx = my_bmf[++j];
|
||||
fontArray->charDef[c].rely = my_bmf[++j];
|
||||
fontArray->charDef[c].kerning = my_bmf[++j];
|
||||
nbPixels = fontArray->charDef[c].width * fontArray->charDef[c].height;
|
||||
fontArray->charDef[c].data = (u8 *)malloc(nbPixels);
|
||||
if (nbPixels && fontArray->charDef[c].data) {
|
||||
memcpy(fontArray->charDef[c].data, &my_bmf[++j], nbPixels);
|
||||
j += (nbPixels - 1);
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,6 @@ void GRRLIB_FreeBMF (const GRRLIB_bytemapFont *bmf) {
|
|||
for (i=0; i<bmf->nbChar; i++) {
|
||||
free(bmf->charDef[i].data);
|
||||
}
|
||||
free(bmf->charDef);
|
||||
free(bmf->palette);
|
||||
free(bmf->name);
|
||||
}
|
||||
|
|
|
@ -69,11 +69,12 @@ void GRRLIB_Printf (const f32 xpos, const f32 ypos,
|
|||
void GRRLIB_PrintBMF (const f32 xpos, const f32 ypos,
|
||||
const GRRLIB_bytemapFont *bmf,
|
||||
const char *text, ...) {
|
||||
uint i, n, size;
|
||||
u16 j;
|
||||
uint i, size;
|
||||
u8 *pdata;
|
||||
u8 x, y;
|
||||
char tmp[1024];
|
||||
f32 xoff = xpos;
|
||||
const GRRLIB_bytemapChar *pchar;
|
||||
|
||||
va_list argp;
|
||||
va_start(argp, text);
|
||||
|
@ -81,22 +82,17 @@ void GRRLIB_PrintBMF (const f32 xpos, const f32 ypos,
|
|||
va_end(argp);
|
||||
|
||||
for (i=0; i<size; i++) {
|
||||
for (j=0; j<bmf->nbChar; j++) {
|
||||
if (tmp[i] == bmf->charDef[j].character) {
|
||||
n=0;
|
||||
for (y=0; y<bmf->charDef[j].height; y++) {
|
||||
for (x=0; x<bmf->charDef[j].width; x++) {
|
||||
if (bmf->charDef[j].data[n]) {
|
||||
GRRLIB_Plot(xoff + x + bmf->charDef[j].relx,
|
||||
ypos + y + bmf->charDef[j].rely,
|
||||
bmf->palette[bmf->charDef[j].data[n]]);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
pchar = &bmf->charDef[(u8)tmp[i]];
|
||||
pdata = pchar->data;
|
||||
for (y=0; y<pchar->height; y++) {
|
||||
for (x=0; x<pchar->width; x++) {
|
||||
if (*pdata++) {
|
||||
GRRLIB_Plot(xoff + x + pchar->relx,
|
||||
ypos + y + pchar->rely,
|
||||
bmf->palette[*pdata]);
|
||||
}
|
||||
xoff += bmf->charDef[j].kerning + bmf->tracking;
|
||||
break;
|
||||
}
|
||||
}
|
||||
xoff += pchar->kerning + bmf->tracking;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,6 @@ typedef struct GRRLIB_texImg {
|
|||
* Structure to hold the bytemap character information.
|
||||
*/
|
||||
typedef struct GRRLIB_bytemapChar {
|
||||
u8 character; /**< Character identity. */
|
||||
u8 width; /**< Character width. */
|
||||
u8 height; /**< Character height. */
|
||||
s8 relx; /**< Horizontal offset relative to cursor (-128 to 127). */
|
||||
|
@ -150,7 +149,7 @@ typedef struct GRRLIB_bytemapFont {
|
|||
u8 version; /**< Version. */
|
||||
s8 tracking; /**< Tracking (Add-space after each char) (-128 to 127). */
|
||||
|
||||
GRRLIB_bytemapChar *charDef; /**< Array of bitmap characters. */
|
||||
GRRLIB_bytemapChar charDef[256]; /**< Array of bitmap characters. */
|
||||
} GRRLIB_bytemapFont;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue