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

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

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