diff options
author | Jörg Hohensohn <hohensoh@rockbox.org> | 2004-08-26 21:15:07 +0000 |
---|---|---|
committer | Jörg Hohensohn <hohensoh@rockbox.org> | 2004-08-26 21:15:07 +0000 |
commit | 5d36aaf249f4f7baf752f3ecc5c252de05cd7166 (patch) | |
tree | bedfc311a9a72d07957627f4c4d829f586f83ca9 /firmware | |
parent | 033ba1669b1e4c7c29e0e4d4d3573a75b681abb5 (diff) | |
download | rockbox-5d36aaf249f4f7baf752f3ecc5c252de05cd7166.tar.gz rockbox-5d36aaf249f4f7baf752f3ecc5c252de05cd7166.zip |
New font format (already rotated) saves code, space and time. On the downside this new format is incompatible, so get the new fonts, too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5015 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/lcd-recorder.c | 4 | ||||
-rw-r--r-- | firmware/export/font.h | 9 | ||||
-rw-r--r-- | firmware/font.c | 146 |
3 files changed, 17 insertions, 142 deletions
diff --git a/firmware/drivers/lcd-recorder.c b/firmware/drivers/lcd-recorder.c index c9781e77ef..a791a79f4c 100644 --- a/firmware/drivers/lcd-recorder.c +++ b/firmware/drivers/lcd-recorder.c | |||
@@ -407,14 +407,14 @@ static void lcd_putsxyofs(int x, int y, int ofs, const unsigned char *str) | |||
407 | if (width > 0) | 407 | if (width > 0) |
408 | { | 408 | { |
409 | unsigned int i; | 409 | unsigned int i; |
410 | bitmap_t* bits = pf->bits + | 410 | unsigned char* bits = pf->bits + |
411 | (pf->offset ? pf->offset[ch] : (pf->height * ch)); | 411 | (pf->offset ? pf->offset[ch] : (pf->height * ch)); |
412 | 412 | ||
413 | if (ofs != 0) | 413 | if (ofs != 0) |
414 | { | 414 | { |
415 | for (i = 0; i < pf->height; i += 8) | 415 | for (i = 0; i < pf->height; i += 8) |
416 | { | 416 | { |
417 | lcd_bitmap (((unsigned char*) bits) + ofs, x, y + i, width, | 417 | lcd_bitmap (bits + ofs, x, y + i, width, |
418 | MIN(8, pf->height - i), true); | 418 | MIN(8, pf->height - i), true); |
419 | bits = (bitmap_t *)((int)bits + gwidth); | 419 | bits = (bitmap_t *)((int)bits + gwidth); |
420 | } | 420 | } |
diff --git a/firmware/export/font.h b/firmware/export/font.h index 14a683a5f2..fff7d05c0b 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h | |||
@@ -72,7 +72,7 @@ enum { | |||
72 | */ | 72 | */ |
73 | 73 | ||
74 | /* loadable font magic and version #*/ | 74 | /* loadable font magic and version #*/ |
75 | #define VERSION "RB11" | 75 | #define VERSION "RB12" |
76 | 76 | ||
77 | typedef unsigned short bitmap_t; /* bitmap image unit size*/ | 77 | typedef unsigned short bitmap_t; /* bitmap image unit size*/ |
78 | 78 | ||
@@ -88,15 +88,14 @@ typedef unsigned short bitmap_t; /* bitmap image unit size*/ | |||
88 | /* builtin C-based proportional/fixed font structure */ | 88 | /* builtin C-based proportional/fixed font structure */ |
89 | /* based on The Microwindows Project http://microwindows.org */ | 89 | /* based on The Microwindows Project http://microwindows.org */ |
90 | struct font { | 90 | struct font { |
91 | char * name; /* font name*/ | ||
92 | int maxwidth; /* max width in pixels*/ | 91 | int maxwidth; /* max width in pixels*/ |
93 | unsigned int height; /* height in pixels*/ | 92 | unsigned int height; /* height in pixels*/ |
94 | int ascent; /* ascent (baseline) height*/ | 93 | int ascent; /* ascent (baseline) height*/ |
95 | int firstchar; /* first character in bitmap*/ | 94 | int firstchar; /* first character in bitmap*/ |
96 | int size; /* font size in glyphs*/ | 95 | int size; /* font size in glyphs*/ |
97 | bitmap_t *bits; /* 16-bit right-padded bitmap data*/ | 96 | const unsigned char *bits; /* 8-bit column bitmap data*/ |
98 | unsigned long *offset; /* offsets into bitmap data*/ | 97 | const unsigned short *offset; /* offsets into bitmap data*/ |
99 | unsigned char *width; /* character widths or NULL if fixed*/ | 98 | const unsigned char *width; /* character widths or NULL if fixed*/ |
100 | int defaultchar; /* default char (not glyph index)*/ | 99 | int defaultchar; /* default char (not glyph index)*/ |
101 | long bits_size; /* # words of bitmap_t bits*/ | 100 | long bits_size; /* # words of bitmap_t bits*/ |
102 | }; | 101 | }; |
diff --git a/firmware/font.c b/firmware/font.c index 343dd0b278..9d46e0d4ce 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -53,15 +53,8 @@ static unsigned char *freeptr = mbuf; | |||
53 | static unsigned char *fileptr; | 53 | static unsigned char *fileptr; |
54 | static unsigned char *eofptr; | 54 | static unsigned char *eofptr; |
55 | 55 | ||
56 | static void rotate_font_bits(const struct font* pf); | ||
57 | static void rotleft(unsigned char *dst, | ||
58 | const bitmap_t *src, | ||
59 | unsigned int width, | ||
60 | unsigned int height); | ||
61 | |||
62 | void font_init(void) | 56 | void font_init(void) |
63 | { | 57 | { |
64 | rotate_font_bits(&sysfont); | ||
65 | memset(&font_ui, 0, sizeof(struct font)); | 58 | memset(&font_ui, 0, sizeof(struct font)); |
66 | } | 59 | } |
67 | 60 | ||
@@ -95,25 +88,6 @@ static int readstr(char *buf, int count) | |||
95 | return (fileptr <= eofptr)? count: 0; | 88 | return (fileptr <= eofptr)? count: 0; |
96 | } | 89 | } |
97 | 90 | ||
98 | /* read totlen bytes, return NUL terminated string*/ | ||
99 | /* may write 1 past buf[totlen]; removes blank pad*/ | ||
100 | static int readstrpad(char *buf, int totlen) | ||
101 | { | ||
102 | char *p = buf; | ||
103 | int n = totlen; | ||
104 | |||
105 | while (--n >= 0) | ||
106 | *p++ = *fileptr++; | ||
107 | if (fileptr > eofptr) | ||
108 | return 0; | ||
109 | |||
110 | p = &buf[totlen]; | ||
111 | *p-- = 0; | ||
112 | while (*p == ' ' && p >= buf) | ||
113 | *p-- = '\0'; | ||
114 | return totlen; | ||
115 | } | ||
116 | |||
117 | void font_reset(void) | 91 | void font_reset(void) |
118 | { | 92 | { |
119 | memset(&font_ui, 0, sizeof(struct font)); | 93 | memset(&font_ui, 0, sizeof(struct font)); |
@@ -127,7 +101,6 @@ struct font* font_load(const char *path) | |||
127 | unsigned long firstchar, defaultchar, size; | 101 | unsigned long firstchar, defaultchar, size; |
128 | unsigned long i, nbits, noffset, nwidth; | 102 | unsigned long i, nbits, noffset, nwidth; |
129 | char version[4+1]; | 103 | char version[4+1]; |
130 | char copyright[256+1]; | ||
131 | struct font* pf = &font_ui; | 104 | struct font* pf = &font_ui; |
132 | 105 | ||
133 | /* open and read entire font file*/ | 106 | /* open and read entire font file*/ |
@@ -163,15 +136,6 @@ struct font* font_load(const char *path) | |||
163 | if (strcmp(version, VERSION) != 0) | 136 | if (strcmp(version, VERSION) != 0) |
164 | return NULL; | 137 | return NULL; |
165 | 138 | ||
166 | /* internal font name*/ | ||
167 | pf->name = fileptr; | ||
168 | if (readstrpad(pf->name, 64) != 64) | ||
169 | return NULL; | ||
170 | |||
171 | /* copyright, not currently stored*/ | ||
172 | if (readstrpad(copyright, 256) != 256) | ||
173 | return NULL; | ||
174 | |||
175 | /* font info*/ | 139 | /* font info*/ |
176 | if (!readshort(&maxwidth)) | 140 | if (!readshort(&maxwidth)) |
177 | return NULL; | 141 | return NULL; |
@@ -198,7 +162,6 @@ struct font* font_load(const char *path) | |||
198 | /* # words of bitmap_t*/ | 162 | /* # words of bitmap_t*/ |
199 | if (!readlong(&nbits)) | 163 | if (!readlong(&nbits)) |
200 | return NULL; | 164 | return NULL; |
201 | pf->bits_size = nbits; | ||
202 | 165 | ||
203 | /* # longs of offset*/ | 166 | /* # longs of offset*/ |
204 | if (!readlong(&noffset)) | 167 | if (!readlong(&noffset)) |
@@ -209,18 +172,21 @@ struct font* font_load(const char *path) | |||
209 | return NULL; | 172 | return NULL; |
210 | 173 | ||
211 | /* variable font data*/ | 174 | /* variable font data*/ |
212 | pf->bits = (bitmap_t *)fileptr; | 175 | pf->bits = (unsigned char *)fileptr; |
213 | for (i=0; i<nbits; ++i) | 176 | fileptr += nbits*sizeof(unsigned char); |
214 | if (!readshort(&pf->bits[i])) | 177 | |
215 | return NULL; | 178 | /* pad to 16 bit boundary*/ |
216 | /* pad to longword boundary*/ | 179 | fileptr = (unsigned char *)(((int)fileptr + 1) & ~1); |
217 | fileptr = (unsigned char *)(((int)fileptr + 3) & ~3); | ||
218 | 180 | ||
219 | if (noffset) { | 181 | if (noffset) { |
220 | pf->offset = (unsigned long *)fileptr; | 182 | pf->offset = (unsigned short *)fileptr; |
221 | for (i=0; i<noffset; ++i) | 183 | for (i=0; i<noffset; ++i) |
222 | if (!readlong(&pf->offset[i])) | 184 | { |
185 | unsigned short offset; | ||
186 | if (!readshort(&offset)) | ||
223 | return NULL; | 187 | return NULL; |
188 | ((unsigned short*)(pf->offset))[i] = (unsigned short)offset; | ||
189 | } | ||
224 | } | 190 | } |
225 | else | 191 | else |
226 | pf->offset = NULL; | 192 | pf->offset = NULL; |
@@ -235,9 +201,6 @@ struct font* font_load(const char *path) | |||
235 | if (fileptr > eofptr) | 201 | if (fileptr > eofptr) |
236 | return NULL; | 202 | return NULL; |
237 | 203 | ||
238 | /* one-time rotate font bits to rockbox format*/ | ||
239 | rotate_font_bits(pf); | ||
240 | |||
241 | return pf; /* success!*/ | 204 | return pf; /* success!*/ |
242 | } | 205 | } |
243 | 206 | ||
@@ -262,93 +225,6 @@ struct font* font_get(int font) | |||
262 | } | 225 | } |
263 | } | 226 | } |
264 | 227 | ||
265 | /* convert font bitmap data inplace to rockbox format*/ | ||
266 | static void rotate_font_bits(const struct font* pf) | ||
267 | { | ||
268 | int i; | ||
269 | unsigned long defaultchar = pf->defaultchar - pf->firstchar; | ||
270 | bool did_defaultchar = false; | ||
271 | unsigned char buf[256]; | ||
272 | |||
273 | for (i=0; i<pf->size; ++i) { | ||
274 | bitmap_t *bits = pf->bits + | ||
275 | (pf->offset ? pf->offset[i] : (pf->height * i)); | ||
276 | int width = pf->width? pf->width[i]: pf->maxwidth; | ||
277 | int src_bytes = BITMAP_BYTES(width) * pf->height; | ||
278 | |||
279 | /* | ||
280 | * Due to the way the offset map works, | ||
281 | * non-mapped characters are mapped to the default | ||
282 | * character, and shouldn't be rotated twice. | ||
283 | */ | ||
284 | |||
285 | if (pf->offset && pf->offset[i] == defaultchar) { | ||
286 | if (did_defaultchar) | ||
287 | continue; | ||
288 | did_defaultchar = true; | ||
289 | } | ||
290 | |||
291 | /* rotate left for lcd_bitmap function input*/ | ||
292 | rotleft(buf, bits, width, pf->height); | ||
293 | |||
294 | /* copy back into original location*/ | ||
295 | memcpy(bits, buf, src_bytes); | ||
296 | } | ||
297 | } | ||
298 | |||
299 | /* | ||
300 | * Take an bitmap_t bitmap and convert to Rockbox format. | ||
301 | * Used for converting font glyphs for the time being. | ||
302 | * Can use for standard X11 and Win32 images as well. | ||
303 | * See format description in lcd-recorder.c | ||
304 | * | ||
305 | * Doing it this way keeps fonts in standard formats, | ||
306 | * as well as keeping Rockbox hw bitmap format. | ||
307 | */ | ||
308 | static void rotleft(unsigned char *dst, const bitmap_t *src, | ||
309 | unsigned int width, unsigned int height) | ||
310 | { | ||
311 | unsigned int i,j; | ||
312 | unsigned int src_words; /* # words of input image*/ | ||
313 | unsigned int dst_mask; /* bit mask for destination */ | ||
314 | bitmap_t src_mask; /* bit mask for source */ | ||
315 | |||
316 | /* calc words of input image*/ | ||
317 | src_words = BITMAP_WORDS(width) * height; | ||
318 | |||
319 | /* clear background*/ | ||
320 | memset(dst, 0, ((height + 7) / 8) * width); | ||
321 | |||
322 | dst_mask = 1; | ||
323 | |||
324 | for (i=0; i < src_words; i++) { | ||
325 | |||
326 | /* calc src input bit*/ | ||
327 | src_mask = 1 << (sizeof (bitmap_t) * 8 - 1); | ||
328 | |||
329 | /* for each input column...*/ | ||
330 | for(j=0; j < width; j++) { | ||
331 | |||
332 | /* if set in input, set in rotated output */ | ||
333 | if (src[i] & src_mask) | ||
334 | dst[j] |= dst_mask; | ||
335 | |||
336 | src_mask >>= 1; /* next input bit */ | ||
337 | if (src_mask == 0) /* input word done? */ | ||
338 | { | ||
339 | src_mask = 1 << (sizeof (bitmap_t) * 8 - 1); | ||
340 | i++; /* next input word */ | ||
341 | } | ||
342 | } | ||
343 | |||
344 | dst_mask <<= 1; /* next output bit (row) */ | ||
345 | if (dst_mask > (1 << 7)) /* output bit > 7? */ | ||
346 | { | ||
347 | dst_mask = 1; | ||
348 | dst += width; /* next output byte row */ | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | #endif /* HAVE_LCD_BITMAP */ | 228 | #endif /* HAVE_LCD_BITMAP */ |
353 | 229 | ||
354 | /* ----------------------------------------------------------------- | 230 | /* ----------------------------------------------------------------- |