summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-09-13 06:37:49 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-09-13 06:37:49 +0000
commit0a1c22128f6bca490c1b39a07ac30419f83b41ce (patch)
treeb5611256f866088452bd059e7f48f63e2d9e3621 /firmware
parent48c23501e9d8b98e4d4de785ce4599696e3848b0 (diff)
downloadrockbox-0a1c22128f6bca490c1b39a07ac30419f83b41ce.tar.gz
rockbox-0a1c22128f6bca490c1b39a07ac30419f83b41ce.zip
Greg Haerr's font patch 3:
Rotates the font bitmaps only once at font_init() time, with some source cleanup to rockbox standards. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2284 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/font.c116
-rw-r--r--firmware/font.h2
2 files changed, 77 insertions, 41 deletions
diff --git a/firmware/font.c b/firmware/font.c
index 5bde2ff1bc..5237f7d2aa 100644
--- a/firmware/font.c
+++ b/firmware/font.c
@@ -49,6 +49,10 @@ struct corefont sysfonts[MAXFONTS] = {
49 { NULL, NULL }, /* no FONT_MP3*/ 49 { NULL, NULL }, /* no FONT_MP3*/
50}; 50};
51 51
52static void rotate_font_bits(PMWCFONT pf);
53static void rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width,
54 unsigned int height);
55
52void 56void
53font_init(void) 57font_init(void)
54{ 58{
@@ -62,6 +66,10 @@ font_init(void)
62 DEBUGF("Font load failed: %s\n", cfp->diskname); 66 DEBUGF("Font load failed: %s\n", cfp->diskname);
63#endif 67#endif
64 } 68 }
69
70 /* one-time rotate font bits to rockbox format*/
71 if (cfp->pf && cfp->pf->height)
72 rotate_font_bits(cfp->pf);
65 } 73 }
66} 74}
67 75
@@ -107,7 +115,6 @@ lcd_getstringsize(unsigned char *str, int font, int *w, int *h)
107 int width = 0; 115 int width = 0;
108 116
109 while((ch = *str++)) { 117 while((ch = *str++)) {
110
111 /* check input range*/ 118 /* check input range*/
112 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size) 119 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
113 ch = pf->defaultchar; 120 ch = pf->defaultchar;
@@ -123,6 +130,70 @@ lcd_getstringsize(unsigned char *str, int font, int *w, int *h)
123} 130}
124 131
125/* 132/*
133 * Put a string at specified bit position
134 */
135//FIXME rename font_putsxy?
136void
137lcd_putsxy(int x, int y, unsigned char *str, int font)
138{
139 int ch;
140 PMWCFONT pf = getfont(font);
141
142 while (((ch = *str++) != '\0')) {
143 MWIMAGEBITS *bits;
144 int width;
145
146 /* check input range*/
147 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
148 ch = pf->defaultchar;
149 ch -= pf->firstchar;
150
151 /* get proportional width and glyph bits*/
152 width = pf->width? pf->width[ch]: pf->maxwidth;
153 if(x + width > LCD_WIDTH)
154 break;
155 bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch));
156
157 lcd_bitmap((unsigned char *)bits, x, y, width, pf->height, true);
158 x += width;
159 }
160}
161
162/* convert font bitmap data inplace to rockbox format*/
163static void
164rotate_font_bits(PMWCFONT pf)
165{
166 int i;
167 int defaultchar = pf->defaultchar - pf->firstchar;
168 int did_defaultchar = 0;
169 unsigned char buf[256];
170
171 for (i=0; i<pf->size; ++i) {
172 MWIMAGEBITS *bits = pf->bits +
173 (pf->offset? pf->offset[i]: (pf->height * i));
174 int width = pf->width? pf->width[i]: pf->maxwidth;
175 int src_bytes = MWIMAGE_BYTES(width) * pf->height;
176
177 /*
178 * Due to the way the offset map works,
179 * non-mapped characters are mapped to the default
180 * character, and shouldn't be rotated twice.
181 */
182 if (i == defaultchar) {
183 if (did_defaultchar)
184 continue;
185 did_defaultchar = 1;
186 }
187
188 /* rotate left for lcd_bitmap function input*/
189 rotleft(buf, bits, width, pf->height);
190
191 /* copy back into original location*/
192 memcpy(bits, buf, src_bytes);
193 }
194}
195
196/*
126 * Take an MWIMAGEBITS bitmap and convert to Rockbox format. 197 * Take an MWIMAGEBITS bitmap and convert to Rockbox format.
127 * Used for converting font glyphs for the time being. 198 * Used for converting font glyphs for the time being.
128 * Can use for standard X11 and Win32 images as well. 199 * Can use for standard X11 and Win32 images as well.
@@ -147,7 +218,7 @@ rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width,
147 src_words = MWIMAGE_WORDS(width) * height; 218 src_words = MWIMAGE_WORDS(width) * height;
148 219
149 /* clear background*/ 220 /* clear background*/
150 memset(dst, 0, dst_linelen*height); 221 memset(dst, 0, dst_linelen*width);
151 222
152 for (i=0; i < src_words; i++) { 223 for (i=0; i < src_words; i++) {
153 MWIMAGEBITS srcmap; /* current src input bit*/ 224 MWIMAGEBITS srcmap; /* current src input bit*/
@@ -178,45 +249,9 @@ rotleft(unsigned char *dst, MWIMAGEBITS *src, unsigned int width,
178 /* input column j becomes output row*/ 249 /* input column j becomes output row*/
179 dst[j*dst_linelen + dst_col] |= dstmap; 250 dst[j*dst_linelen + dst_col] |= dstmap;
180 } 251 }
181 //printf((bit & src[i])? "*": "."); 252 /*debugf((bit & src[i])? "*": ".");*/
182 } 253 }
183 //printf("\n"); 254 /*debugf("\n");*/
184 }
185}
186
187/*
188 * Put a string at specified bit position
189 */
190//FIXME rename font_putsxy?
191void
192lcd_putsxy(int x, int y, unsigned char *str, int font)
193{
194 int ch;
195 unsigned char *src;
196 PMWCFONT pf = getfont(font);
197
198 while (((ch = *str++) != '\0')) {
199 MWIMAGEBITS *bits;
200 int width;
201 unsigned char outbuf[256];
202
203 /* check input range*/
204 if (ch < pf->firstchar || ch >= pf->firstchar+pf->size)
205 ch = pf->defaultchar;
206 ch -= pf->firstchar;
207
208 /* get proportional width and glyph bits*/
209 width = pf->width? pf->width[ch]: pf->maxwidth;
210 if(x + width > LCD_WIDTH)
211 break;
212 bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch));
213
214 /* rotate left for lcd_bitmap function input*/
215 rotleft(outbuf, bits, width, pf->height);
216 src = outbuf;
217
218 lcd_bitmap (src, x, y, width, pf->height, true);
219 x += width;
220 } 255 }
221} 256}
222#endif /* HAVE_LCD_BITMAP */ 257#endif /* HAVE_LCD_BITMAP */
@@ -224,5 +259,6 @@ lcd_putsxy(int x, int y, unsigned char *str, int font)
224/* ----------------------------------------------------------------- 259/* -----------------------------------------------------------------
225 * local variables: 260 * local variables:
226 * eval: (load-file "rockbox-mode.el") 261 * eval: (load-file "rockbox-mode.el")
262 * vim: et sw=4 ts=4 sts=4 tw=78
227 * end: 263 * end:
228 */ 264 */
diff --git a/firmware/font.h b/firmware/font.h
index 13d60e560b..8535ab216b 100644
--- a/firmware/font.h
+++ b/firmware/font.h
@@ -70,7 +70,7 @@
70 70
71/* MWIMAGEBITS helper macros*/ 71/* MWIMAGEBITS helper macros*/
72#define MWIMAGE_WORDS(x) (((x)+15)/16) /* image size in words*/ 72#define MWIMAGE_WORDS(x) (((x)+15)/16) /* image size in words*/
73#define MWIMAGE_BYTES(x) (((x)+7)/8) /* image size in bytes*/ 73#define MWIMAGE_BYTES(x) (MWIMAGE_WORDS(x)*sizeof(MWIMAGEBITS))
74#define MWIMAGE_BITSPERIMAGE (sizeof(MWIMAGEBITS) * 8) 74#define MWIMAGE_BITSPERIMAGE (sizeof(MWIMAGEBITS) * 8)
75#define MWIMAGE_BITVALUE(n) ((MWIMAGEBITS) (((MWIMAGEBITS) 1) << (n))) 75#define MWIMAGE_BITVALUE(n) ((MWIMAGEBITS) (((MWIMAGEBITS) 1) << (n)))
76#define MWIMAGE_FIRSTBIT (MWIMAGE_BITVALUE(MWIMAGE_BITSPERIMAGE - 1)) 76#define MWIMAGE_FIRSTBIT (MWIMAGE_BITVALUE(MWIMAGE_BITSPERIMAGE - 1))