[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.4 - (view) (download)

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

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