-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosd.c
230 lines (217 loc) · 6.92 KB
/
osd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <vdr/tools.h>
#include <vdr/osd.h>
#include <stdlib.h>
#include <ctype.h>
#include "osd.h"
#if VDRVERSNUM < 10307
void Frame(cOsdBase *Osd, int x1, int y1, int x2, int y2, eDvbColor Color) {
Osd->Fill(x1, y1, x2, y1 + 1, Color);
Osd->Fill(x1, y1, x1 + 1, y2, Color);
Osd->Fill(x1, y2 - 1, x2, y2, Color);
Osd->Fill(x2 - 1, y1, x2, y2, Color);
#else /* VDRVERSNUM < 10307 */
void Frame(cOsd *Osd, int x1, int y1, int x2, int y2, tColor Color) {
Osd->DrawRectangle(x1, y1, x2, y1 + 1, Color);
Osd->DrawRectangle(x1, y1, x1 + 1, y2, Color);
Osd->DrawRectangle(x1, y2 - 1, x2, y2, Color);
Osd->DrawRectangle(x2 - 1, y1, x2, y2, Color);
#endif /* VDRVERSNUM < 10307 */
}
#if VDRVERSNUM < 10307
void Frame(cBitmap *Bitmap, int x1, int y1, int x2, int y2, eDvbColor Color) {
Bitmap->Fill(x1, y1, x2, y1 + 1, Color);
Bitmap->Fill(x1, y1, x1 + 1, y2, Color);
Bitmap->Fill(x1, y2 - 1, x2, y2, Color);
Bitmap->Fill(x2 - 1, y1, x2, y2, Color);
#else /* VDRVERSNUM < 10307 */
void Frame(cBitmap *Bitmap, int x1, int y1, int x2, int y2, tColor Color) {
Bitmap->DrawRectangle(x1, y1, x2, y1 + 1, Color);
Bitmap->DrawRectangle(x1, y1, x1 + 1, y2, Color);
Bitmap->DrawRectangle(x1, y2 - 1, x2, y2, Color);
Bitmap->DrawRectangle(x2 - 1, y1, x2, y2, Color);
#endif /* VDRVERSNUM < 10307 */
}
#if VDRVERSNUM < 10307
bool LoadXpm(cBitmap *Bitmap, const char *FileName, eDvbColor NoneColor) {
#else /* VDRVERSNUM < 10307 */
bool LoadXpm(cBitmap *Bitmap, const char *FileName, tColor NoneColor) {
#endif /* VDRVERSNUM < 10307 */
// Note: Copied from ElchiAIO4d (not stolen, since i created original code)
bool bRet = false;
FILE *infile;
printf("bitmap: %s\n", FileName);
infile = fopen(FileName, "r");
if (infile) {
bool ok = true;
char buf[512];
char *ptr;
int state = 0;
int width, height, colors, colwidth, cnt = 0;
int temp;
uint pal[65536];
while (ok && fgets(buf, sizeof(buf), infile) != NULL) {
int len = strlen(buf);
ptr = buf;
if (ptr[len - 1] == '\n')
ptr[--len] = '\0';
if (state > 0 && strncmp(ptr, "/*", 2) == 0) {
continue;
}
switch (state) {
case 0:
if (strcmp(ptr, "/* XPM */") != 0) {
esyslog("ERROR: loading xpm %s failed: invalid header", FileName);
ok = false;
break;
}
++state;
break;
case 1:
++state;
break;
case 2:
sscanf(ptr, "\"%d %d %d %d\",", &width, &height, &colors, &colwidth);
if (colwidth > 2) {
esyslog("ERROR: wrong colorwidth in xpm %s", FileName);
ok = false;
break;
}
cnt = 0;
++state;
break;
case 3:
++ptr;
temp = 0;
for (int i = 0; i < colwidth; ++i) {
temp <<= 8;
temp += (int)*ptr;
++ptr;
}
++ptr;
if (strncmp(ptr, "c ", 2) != 0) {
esyslog("ERROR: wrong character in xpm %s", FileName);
ok = false;
break;
}
ptr += 2;
if (*ptr == '#') {
int col = strtoul(++ptr, NULL, 16);
#if VDRVERSNUM < 10307
pal[temp] = 0xff000000 | ((col & 0xff) << 16) | (col & 0xff00) | ((col & 0xff0000) >> 16);
#else /* VDRVERSNUM < 10307 */
pal[temp] = 0xff000000 | (col & 0xff) | (col & 0xff00) | (col & 0xff0000);
#endif /* VDRVERSNUM < 10307 */
}
else {
pal[temp] = NoneColor;
}
if (++cnt == colors) {
cnt = 0;
++state;
}
break;
case 4:
++ptr;
for (int p = 0; p < width; ++p) {
temp = 0;
for (int i = 0; i < colwidth; ++i) {
temp <<= 8;
temp += (int)*ptr;
++ptr;
}
#if VDRVERSNUM < 10307
Bitmap->SetPixel(p, cnt, (eDvbColor)pal[temp]);
#else /* VDRVERSNUM < 10307 */
Bitmap->DrawPixel(p, cnt, (tColor)pal[temp]);
#endif /* VDRVERSNUM < 10307 */
}
if (++cnt == height) {
++state;
bRet = true;
}
break;
default:
break;
}
}
fclose(infile);
}
return bRet;
}
#if VDRVERSNUM < 10307
char *WrapText(cBitmap *Bitmap, const char *Text, int Width, int *Height) {
#else /* VDRVERSNUM < 10307 */
char *WrapText(cBitmap *Bitmap, const char *Text, int Width, const cFont *Font, int *Height) {
#endif /* VDRVERSNUM < 10307 */
// Wraps the Text to make it fit into the area defined by the given Width
// (which is given in character cells).
// The actual number of lines resulting from this operation is returned in
// Height.
// The returned string is newly created on the heap and the caller
// is responsible for deleting it once it is no longer used.
// Wrapping is done by inserting the necessary number of newline
// characters into the string.
//
// Note: Stolen from vdr 1.2.6 :-)
int Lines = 1;
char *t = strdup(Text);
char *Blank = NULL;
char *Delim = NULL;
int w = 0;
while (*t && t[strlen(t) - 1] == '\n')
t[strlen(t) - 1] = 0; // skips trailing newlines
for (char *p = t; *p; ) {
if (*p == '|')
*p = '\n';
if (*p == '\n') {
Lines++;
w = 0;
Blank = Delim = NULL;
p++;
continue;
}
else if (isspace(*p))
Blank = p;
#if VDRVERSNUM < 10307
int cw = Bitmap->Width(*p);
#else /* VDRVERSNUM < 10307 */
int cw = Font->Width(*p);
#endif /* VDRVERSNUM < 10307 */
if (w + cw > Width) {
if (Blank) {
*Blank = '\n';
p = Blank;
continue;
}
else {
// Here's the ugly part, where we don't have any whitespace to
// punch in a newline, so we need to make room for it:
if (Delim)
p = Delim + 1; // let's fall back to the most recent delimiter
char *s = MALLOC(char, strlen(t) + 2); // The additional '\n' plus the terminating '\0'
int l = p - t;
strncpy(s, t, l);
s[l] = '\n';
strcpy(s + l + 1, p);
free(t);
t = s;
p = t + l;
continue;
}
}
else
w += cw;
if (strchr("-.,:;!?_", *p)) {
Delim = p;
Blank = NULL;
}
p++;
}
if (Height != NULL)
#if VDRVERSNUM < 10307
*Height = Lines * cOsd::LineHeight();
#else /* VDRVERSNUM < 10307 */
*Height = Lines * Font->Height();
#endif /* VDRVERSNUM < 10307 */
return t;
}