[cvs] / xvidcore / src / image / font.c Repository:
ViewVC logotype

Annotation of /xvidcore/src/image/font.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (view) (download)

1 : edgomez 1.5 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Font rendering to frame buffer functions -
5 :     *
6 :     * Copyright(C) 2002-2003 Peter Ross <pross@xvid.org>
7 :     *
8 :     * This program is free software ; you can redistribute it and/or modify
9 :     * it under the terms of the GNU General Public License as published by
10 :     * the Free Software Foundation ; either version 2 of the License, or
11 :     * (at your option) any later version.
12 :     *
13 :     * This program is distributed in the hope that it will be useful,
14 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
15 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     * GNU General Public License for more details.
17 :     *
18 :     * You should have received a copy of the GNU General Public License
19 :     * along with this program ; if not, write to the Free Software
20 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 :     *
22 : suxen_drol 1.7 * $Id: font.c,v 1.6 2004/05/31 21:36:23 edgomez Exp $
23 : edgomez 1.5 *
24 :     ****************************************************************************/
25 : suxen_drol 1.1
26 : edgomez 1.4 #include <stdio.h>
27 :     #include <stdarg.h>
28 : suxen_drol 1.1
29 :     #include "image.h"
30 :     #include "font.h"
31 :    
32 :     #define FONT_WIDTH 4
33 :     #define FONT_HEIGHT 6
34 :    
35 :    
36 : edgomez 1.5 static const char ascii33[33][FONT_WIDTH*FONT_HEIGHT] = {
37 :    
38 :     /* ! */
39 :     {0,0,1,0,
40 :     0,0,1,0,
41 :     0,0,1,0,
42 :     0,0,1,0,
43 :     0,0,0,0,
44 :     0,0,1,0},
45 :    
46 :     /* " */
47 :     {0,1,0,1,
48 :     0,1,0,1,
49 :     0,0,0,0,
50 :     0,0,0,0,
51 :     0,0,0,0,
52 :     0,0,0,0},
53 :    
54 :     /* # */
55 :     {0,1,1,0,
56 :     1,1,1,1,
57 :     0,1,1,0,
58 :     0,1,1,0,
59 :     1,1,1,1,
60 :     0,1,1,0},
61 :    
62 :     /* $ */
63 :     {0,1,1,0,
64 :     1,0,1,1,
65 :     1,1,1,0,
66 :     0,1,1,1,
67 :     1,1,0,1,
68 :     0,1,1,0},
69 :    
70 :     /* % */
71 :     {1,1,0,1,
72 :     1,0,0,1,
73 :     0,0,1,0,
74 :     0,1,0,0,
75 :     1,0,0,1,
76 :     1,0,1,1},
77 :    
78 :     /* & */
79 :     {0,1,1,0,
80 :     1,0,0,0,
81 :     0,1,0,1,
82 :     1,0,1,0,
83 :     1,0,1,0,
84 :     0,1,0,1},
85 :    
86 :     /* ' */
87 :     {0,0,1,0,
88 :     0,0,1,0,
89 :     0,0,0,0,
90 :     0,0,0,0,
91 :     0,0,0,0,
92 :     0,0,0,0},
93 :    
94 :     /* ( */
95 :     {0,0,1,0,
96 :     0,1,0,0,
97 :     0,1,0,0,
98 :     0,1,0,0,
99 :     0,1,0,0,
100 :     0,0,1,0},
101 :    
102 :     /* ) */
103 :     {0,1,0,0,
104 :     0,0,1,0,
105 :     0,0,1,0,
106 :     0,0,1,0,
107 :     0,0,1,0,
108 :     0,1,0,0},
109 :    
110 :     /* * */
111 :     {0,0,0,0,
112 :     1,0,0,1,
113 :     0,1,1,0,
114 :     1,1,1,1,
115 :     0,1,1,0,
116 :     1,0,0,1},
117 :    
118 :     /* + */
119 :     {0,0,0,0,
120 :     0,0,1,0,
121 :     0,0,1,0,
122 :     0,1,1,1,
123 :     0,0,1,0,
124 :     0,0,1,0},
125 :    
126 :     /* , */
127 :     {0,0,0,0,
128 :     0,0,0,0,
129 :     0,0,0,0,
130 :     0,0,0,0,
131 :     0,1,1,0,
132 :     0,0,1,0},
133 :    
134 :     /* - */
135 :     {0,0,0,0,
136 :     0,0,0,0,
137 :     0,0,0,0,
138 :     1,1,1,1,
139 :     0,0,0,0,
140 :     0,0,0,0},
141 :    
142 :     /* . */
143 :     {0,0,0,0,
144 :     0,0,0,0,
145 :     0,0,0,0,
146 :     0,0,0,0,
147 :     0,1,1,0,
148 :     0,1,1,0},
149 :    
150 :     /* / */
151 :     {0,0,0,1,
152 :     0,0,0,1,
153 :     0,0,1,0,
154 :     0,1,0,0,
155 :     1,0,0,0,
156 :     1,0,0,0},
157 :    
158 :     /* 0 */
159 :     {0,1,1,0,
160 :     1,0,0,1,
161 :     1,0,1,1,
162 :     1,1,0,1,
163 :     1,0,0,1,
164 :     0,1,1,0},
165 :    
166 :     /* 1 */
167 :     {0,0,1,0,
168 :     0,0,1,0,
169 :     0,0,1,0,
170 :     0,0,1,0,
171 :     0,0,1,0,
172 :     0,0,1,0},
173 :    
174 :     /* 2 */
175 :     {0,1,1,0,
176 :     1,0,0,1,
177 :     0,0,1,0,
178 :     0,1,0,0,
179 :     1,0,0,0,
180 :     1,1,1,1},
181 :    
182 :     /* 3 */
183 :     {0,1,1,0,
184 :     1,0,0,1,
185 :     0,0,1,0,
186 :     0,0,0,1,
187 :     1,0,0,1,
188 :     0,1,1,0},
189 :    
190 :     /* 4 */
191 :     {0,0,1,0,
192 :     0,1,1,0,
193 :     1,0,1,0,
194 :     1,1,1,1,
195 :     0,0,1,0,
196 :     0,0,1,0},
197 :    
198 :     /* 5 */
199 :     {1,1,1,1,
200 :     1,0,0,0,
201 :     1,1,1,0,
202 :     0,0,0,1,
203 :     1,0,0,1,
204 :     0,1,1,0},
205 :    
206 :     /* 6 */
207 :     {0,1,1,1,
208 :     1,0,0,0,
209 :     1,1,1,0,
210 :     1,0,0,1,
211 :     1,0,0,1,
212 :     0,1,1,0},
213 :    
214 :     /* 7 */
215 :     {1,1,1,0,
216 :     0,0,0,1,
217 :     0,0,0,1,
218 :     0,0,1,0,
219 :     0,0,1,0,
220 :     0,0,1,0},
221 :    
222 :     /* 8 */
223 :     {0,1,1,0,
224 :     1,0,0,1,
225 :     0,1,1,0,
226 :     1,0,0,1,
227 :     1,0,0,1,
228 :     0,1,1,0},
229 :    
230 :     /* 9 */
231 :     {0,1,1,0,
232 :     1,0,0,1,
233 :     1,0,0,1,
234 :     0,1,1,1,
235 :     0,0,0,1,
236 :     1,1,1,0},
237 :    
238 :     /* : */
239 :     {0,0,0,0,
240 :     0,0,0,0,
241 :     0,0,1,0,
242 :     0,0,0,0,
243 :     0,0,1,0,
244 :     0,0,0,0},
245 :    
246 :     /* ; */
247 :     {0,0,0,0,
248 :     0,0,1,0,
249 :     0,0,0,0,
250 :     0,0,0,0,
251 :     0,1,1,0,
252 :     0,0,1,0},
253 :    
254 :     /* < */
255 :     {0,0,0,1,
256 :     0,0,1,0,
257 :     0,1,0,0,
258 :     0,1,0,0,
259 :     0,0,1,0,
260 :     0,0,0,1},
261 :    
262 :     /* = */
263 :     {0,0,0,0,
264 :     1,1,1,1,
265 :     0,0,0,0,
266 :     0,0,0,0,
267 :     1,1,1,1,
268 :     0,0,0,0},
269 :    
270 :     /* > */
271 :     {0,1,0,0,
272 :     0,0,1,0,
273 :     0,0,0,1,
274 :     0,0,0,1,
275 :     0,0,1,0,
276 :     0,1,0,0},
277 :    
278 :     /* ? */
279 :     {0,1,1,0,
280 :     1,0,0,1,
281 :     0,0,1,0,
282 :     0,0,1,0,
283 :     0,0,0,0,
284 :     0,0,1,0},
285 :    
286 :     /* @ */
287 :     {0,1,1,0,
288 :     1,0,0,1,
289 :     1,0,1,1,
290 :     1,0,1,1,
291 :     1,0,0,0,
292 :     0,1,1,0},
293 : suxen_drol 1.1
294 :     };
295 :    
296 :    
297 : edgomez 1.5 static const char ascii65[26][FONT_WIDTH*FONT_HEIGHT] = {
298 :     /* A */
299 :     {0,1,1,0,
300 :     1,0,0,1,
301 :     1,0,0,1,
302 :     1,1,1,1,
303 :     1,0,0,1,
304 :     1,0,0,1},
305 :    
306 :     /* B */
307 :     {1,1,1,0,
308 :     1,0,0,1,
309 :     1,1,1,0,
310 :     1,0,0,1,
311 :     1,0,0,1,
312 :     1,1,1,0},
313 :    
314 :     /* C */
315 :     {0,1,1,0,
316 :     1,0,0,1,
317 :     1,0,0,0,
318 :     1,0,0,0,
319 :     1,0,0,1,
320 :     0,1,1,0},
321 :    
322 :     /* D */
323 :     {1,1,0,0,
324 :     1,0,1,0,
325 :     1,0,0,1,
326 :     1,0,0,1,
327 :     1,0,1,0,
328 :     1,1,0,0},
329 :    
330 :     /* E */
331 :     {1,1,1,1,
332 :     1,0,0,0,
333 :     1,1,1,0,
334 :     1,0,0,0,
335 :     1,0,0,0,
336 :     1,1,1,1},
337 :    
338 :     /* F */
339 :     {1,1,1,1,
340 :     1,0,0,0,
341 :     1,1,1,0,
342 :     1,0,0,0,
343 :     1,0,0,0,
344 :     1,0,0,0},
345 :    
346 :     /* G */
347 :     {0,1,1,1,
348 :     1,0,0,0,
349 :     1,0,1,1,
350 :     1,0,0,1,
351 :     1,0,0,1,
352 :     0,1,1,0},
353 :    
354 :     /* H */
355 :     {1,0,0,1,
356 :     1,0,0,1,
357 :     1,1,1,1,
358 :     1,0,0,1,
359 :     1,0,0,1,
360 :     1,0,0,1},
361 :    
362 :     /* I */
363 :     {0,1,1,1,
364 :     0,0,1,0,
365 :     0,0,1,0,
366 :     0,0,1,0,
367 :     0,0,1,0,
368 :     0,1,1,1},
369 :    
370 :     /* J */
371 :     {0,1,1,1,
372 :     0,0,1,0,
373 :     0,0,1,0,
374 :     0,0,1,0,
375 :     1,0,1,0,
376 :     0,1,0,0},
377 :    
378 :     /* K */
379 :     {1,0,0,1,
380 :     1,0,0,1,
381 :     1,1,1,0,
382 :     1,0,0,1,
383 :     1,0,0,1,
384 :     1,0,0,1},
385 :    
386 :     /* L */
387 :     {1,0,0,0,
388 :     1,0,0,0,
389 :     1,0,0,0,
390 :     1,0,0,0,
391 :     1,0,0,0,
392 :     1,1,1,1},
393 :    
394 :     /* M */
395 :     {1,0,0,1,
396 :     1,1,1,1,
397 :     1,1,1,1,
398 :     1,0,0,1,
399 :     1,0,0,1,
400 :     1,0,0,1},
401 :    
402 :     /* N */
403 :     {1,0,0,1,
404 :     1,1,0,1,
405 :     1,1,0,1,
406 :     1,0,1,1,
407 :     1,0,1,1,
408 :     1,0,0,1},
409 :    
410 :     /* 0 */
411 :     {0,1,1,0,
412 :     1,0,0,1,
413 :     1,0,0,1,
414 :     1,0,0,1,
415 :     1,0,0,1,
416 :     0,1,1,0},
417 :    
418 :     /* P */
419 :     {1,1,1,0,
420 :     1,0,0,1,
421 :     1,1,1,0,
422 :     1,0,0,0,
423 :     1,0,0,0,
424 :     1,0,0,0},
425 :    
426 :     /* Q */
427 :     {0,1,1,0,
428 :     1,0,0,1,
429 :     1,0,0,1,
430 :     1,0,0,1,
431 :     1,0,1,0,
432 :     0,1,0,1},
433 :    
434 :    
435 :     /* R */
436 :     {1,1,1,0,
437 :     1,0,0,1,
438 :     1,1,1,0,
439 :     1,0,0,1,
440 :     1,0,0,1,
441 :     1,0,0,1},
442 :    
443 :     /* S */
444 :     {0,1,1,0,
445 :     1,0,0,1,
446 :     0,1,0,0,
447 :     0,0,1,0,
448 :     1,0,0,1,
449 :     0,1,1,0},
450 :    
451 :     /* T */
452 :     {0,1,1,1,
453 :     0,0,1,0,
454 :     0,0,1,0,
455 :     0,0,1,0,
456 :     0,0,1,0,
457 :     0,0,1,0},
458 :    
459 :     /* U */
460 :     {1,0,0,1,
461 :     1,0,0,1,
462 :     1,0,0,1,
463 :     1,0,0,1,
464 :     1,0,0,1,
465 :     1,1,1,1},
466 :    
467 :     /* V */
468 :     {1,0,0,1,
469 :     1,0,0,1,
470 :     1,0,0,1,
471 :     0,1,1,0,
472 :     0,1,1,0,
473 :     0,1,1,0},
474 :    
475 :     /* W */
476 :     {1,0,0,1,
477 :     1,0,0,1,
478 :     1,0,0,1,
479 :     1,1,1,1,
480 :     1,1,1,1,
481 :     1,0,0,1},
482 :    
483 :     /* X */
484 :     {1,0,0,1,
485 :     1,0,0,1,
486 :     0,1,1,0,
487 :     1,0,0,1,
488 :     1,0,0,1,
489 :     1,0,0,1},
490 :    
491 :     /* Y */
492 :     {1,0,0,1,
493 :     1,0,0,1,
494 :     0,1,0,0,
495 :     0,0,1,0,
496 :     0,1,0,0,
497 :     1,0,0,0},
498 :    
499 :     /* Z */
500 :     {1,1,1,1,
501 :     0,0,0,1,
502 :     0,0,1,0,
503 :     0,1,0,0,
504 :     1,0,0,0,
505 :     1,1,1,1},
506 : suxen_drol 1.1
507 :     };
508 :    
509 :    
510 :    
511 : edgomez 1.5 static const char ascii91[6][FONT_WIDTH*FONT_HEIGHT] = {
512 :     /* [ */
513 :     {0,1,1,0,
514 :     0,1,0,0,
515 :     0,1,0,0,
516 :     0,1,0,0,
517 :     0,1,0,0,
518 :     0,1,1,0},
519 :    
520 :     /* '\' */
521 :     {1,0,0,0,
522 :     1,0,0,0,
523 :     0,1,0,0,
524 :     0,0,1,0,
525 :     0,0,0,1,
526 :     0,0,0,1},
527 :    
528 :     /* ] */
529 :     {0,1,1,0,
530 :     0,0,1,0,
531 :     0,0,1,0,
532 :     0,0,1,0,
533 :     0,0,1,0,
534 :     0,1,1,0},
535 :    
536 :     /* ^ */
537 :     {0,1,0,1,
538 :     0,0,0,0,
539 :     0,0,0,0,
540 :     0,0,0,0,
541 :     0,0,0,0,
542 :     0,0,0,0},
543 :    
544 :     /* _ */
545 :     {0,0,0,0,
546 :     0,0,0,0,
547 :     0,0,0,0,
548 :     0,0,0,0,
549 :     0,0,0,0,
550 :     1,1,1,1},
551 :    
552 :     /* ` */
553 :     {0,1,0,0,
554 :     0,0,1,0,
555 :     0,0,0,0,
556 :     0,0,0,0,
557 :     0,0,0,0,
558 :     0,0,0,0}
559 : suxen_drol 1.1 };
560 :    
561 :    
562 :     #define FONT_ZOOM 4
563 :    
564 : suxen_drol 1.7 static void
565 :     draw_num(IMAGE * img, const int stride, const int height,
566 : suxen_drol 1.1 const char * font, const int x, const int y)
567 :     {
568 :     int i, j;
569 :    
570 :     for (j = 0; j < FONT_ZOOM * FONT_HEIGHT && y+j < height; j++)
571 :     for (i = 0; i < FONT_ZOOM * FONT_WIDTH && x+i < stride; i++)
572 :     if (font[(j/FONT_ZOOM)*FONT_WIDTH + (i/FONT_ZOOM)])
573 :     {
574 :     int offset = (y+j)*stride + (x+i);
575 :     int offset2 =((y+j)/2)*(stride/2) + ((x+i)/2);
576 :     img->y[offset] = 255;
577 :     img->u[offset2] = 127;
578 :     img->v[offset2] = 127;
579 :     }
580 :     }
581 :    
582 :    
583 :     #define FONT_BUF_SZ 1024
584 :    
585 : edgomez 1.5 void image_printf(IMAGE * img, int edged_width, int height,
586 : suxen_drol 1.1 int x, int y, char *fmt, ...)
587 :     {
588 :     va_list args;
589 :     char buf[FONT_BUF_SZ];
590 : edgomez 1.4 int i;
591 : suxen_drol 1.1
592 :     va_start(args, fmt);
593 :     vsprintf(buf, fmt, args);
594 : edgomez 1.6 va_end(args);
595 : suxen_drol 1.1
596 : edgomez 1.4 for (i = 0; i < buf[i]; i++) {
597 : suxen_drol 1.1 const char * font;
598 :    
599 :     if (buf[i] >= '!' && buf[i] <= '@')
600 :     font = ascii33[buf[i]-'!'];
601 :     else if (buf[i] >= 'A' && buf[i] <= 'Z')
602 :     font = ascii65[buf[i]-'A'];
603 :     else if (buf[i] >= '[' && buf[i] <= '`')
604 :     font = ascii91[buf[i]-'['];
605 :     else if (buf[i] >= 'a' && buf[i] <= 'z')
606 :     font = ascii65[buf[i]-'a'];
607 :     else
608 :     continue;
609 :    
610 :     draw_num(img, edged_width, height, font, x + i*FONT_ZOOM*(FONT_WIDTH+1), y);
611 :     }
612 :     }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4