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

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

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