1 : /*
2 : * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 : *
4 : * Use of this source code is governed by a BSD-style license
5 : * that can be found in the LICENSE file in the root of the source
6 : * tree. An additional intellectual property rights grant can be found
7 : * in the file PATENTS. All contributing project authors may
8 : * be found in the AUTHORS file in the root of the source tree.
9 : */
10 :
11 : #include <stdlib.h>
12 :
13 :
14 0 : void vp8_blit_text(const char *msg, unsigned char *address, const int pitch)
15 : {
16 : int letter_bitmap;
17 0 : unsigned char *output_pos = address;
18 : int colpos;
19 0 : const int font[] =
20 : {
21 : 0x0, 0x5C00, 0x8020, 0xAFABEA, 0xD7EC0, 0x1111111, 0x1855740, 0x18000,
22 : 0x45C0, 0x74400, 0x51140, 0x23880, 0xC4000, 0x21080, 0x80000, 0x111110,
23 : 0xE9D72E, 0x87E40, 0x12AD732, 0xAAD62A, 0x4F94C4, 0x4D6B7, 0x456AA,
24 : 0x3E8423, 0xAAD6AA, 0xAAD6A2, 0x2800, 0x2A00, 0x8A880, 0x52940, 0x22A20,
25 : 0x15422, 0x6AD62E, 0x1E4A53E, 0xAAD6BF, 0x8C62E, 0xE8C63F, 0x118D6BF,
26 : 0x1094BF, 0xCAC62E, 0x1F2109F, 0x118FE31, 0xF8C628, 0x8A89F, 0x108421F,
27 : 0x1F1105F, 0x1F4105F, 0xE8C62E, 0x2294BF, 0x164C62E, 0x12694BF, 0x8AD6A2,
28 : 0x10FC21, 0x1F8421F, 0x744107, 0xF8220F, 0x1151151, 0x117041, 0x119D731,
29 : 0x47E0, 0x1041041, 0xFC400, 0x10440, 0x1084210, 0x820
30 : };
31 0 : colpos = 0;
32 :
33 0 : while (msg[colpos] != 0)
34 : {
35 0 : char letter = msg[colpos];
36 : int fontcol, fontrow;
37 :
38 0 : if (letter <= 'Z' && letter >= ' ')
39 0 : letter_bitmap = font[letter-' '];
40 0 : else if (letter <= 'z' && letter >= 'a')
41 0 : letter_bitmap = font[letter-'a'+'A' - ' '];
42 : else
43 0 : letter_bitmap = font[0];
44 :
45 0 : for (fontcol = 6; fontcol >= 0 ; fontcol--)
46 0 : for (fontrow = 0; fontrow < 5; fontrow++)
47 0 : output_pos[fontrow *pitch + fontcol] =
48 0 : ((letter_bitmap >> (fontcol * 5)) & (1 << fontrow) ? 255 : 0);
49 :
50 0 : output_pos += 7;
51 0 : colpos++;
52 : }
53 0 : }
54 :
55 0 : static void plot (const int x, const int y, unsigned char *image, const int pitch)
56 : {
57 0 : image [x+y*pitch] ^= 255;
58 0 : }
59 :
60 : /* Bresenham line algorithm */
61 0 : void vp8_blit_line(int x0, int x1, int y0, int y1, unsigned char *image, const int pitch)
62 : {
63 0 : int steep = abs(y1 - y0) > abs(x1 - x0);
64 : int deltax, deltay;
65 : int error, ystep, y, x;
66 :
67 0 : if (steep)
68 : {
69 : int t;
70 0 : t = x0;
71 0 : x0 = y0;
72 0 : y0 = t;
73 :
74 0 : t = x1;
75 0 : x1 = y1;
76 0 : y1 = t;
77 : }
78 :
79 0 : if (x0 > x1)
80 : {
81 : int t;
82 0 : t = x0;
83 0 : x0 = x1;
84 0 : x1 = t;
85 :
86 0 : t = y0;
87 0 : y0 = y1;
88 0 : y1 = t;
89 : }
90 :
91 0 : deltax = x1 - x0;
92 0 : deltay = abs(y1 - y0);
93 0 : error = deltax / 2;
94 :
95 0 : y = y0;
96 :
97 0 : if (y0 < y1)
98 0 : ystep = 1;
99 : else
100 0 : ystep = -1;
101 :
102 0 : if (steep)
103 : {
104 0 : for (x = x0; x <= x1; x++)
105 : {
106 0 : plot(y,x, image, pitch);
107 :
108 0 : error = error - deltay;
109 0 : if (error < 0)
110 : {
111 0 : y = y + ystep;
112 0 : error = error + deltax;
113 : }
114 : }
115 : }
116 : else
117 : {
118 0 : for (x = x0; x <= x1; x++)
119 : {
120 0 : plot(x,y, image, pitch);
121 :
122 0 : error = error - deltay;
123 0 : if (error < 0)
124 : {
125 0 : y = y + ystep;
126 0 : error = error + deltax;
127 : }
128 : }
129 : }
130 0 : }
|