1 |
/* vi: set sw=4 ts=4: */ |
/* vi: set sw=4 ts=4: */ |
2 |
/* |
/* |
3 |
* Copyright (C) 2008 Michele Sanges <michele.sanges@otomelara.it>, |
* Copyright (C) 2008 Michele Sanges <michele.sanges@gmail.com> |
|
* <michele.sanges@gmail.it> |
|
4 |
* |
* |
5 |
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
6 |
* |
* |
84 |
// map the device in memory |
// map the device in memory |
85 |
G.addr = mmap(NULL, |
G.addr = mmap(NULL, |
86 |
G.scr_var.xres * G.scr_var.yres |
G.scr_var.xres * G.scr_var.yres |
87 |
* BYTES_PER_PIXEL /*(G.scr_var.bits_per_pixel / 8)*/ , |
* BYTES_PER_PIXEL /*(G.scr_var.bits_per_pixel / 8)*/, |
88 |
PROT_WRITE, MAP_SHARED, fbfd, 0); |
PROT_WRITE, MAP_SHARED, fbfd, 0); |
89 |
if (G.addr == MAP_FAILED) |
if (G.addr == MAP_FAILED) |
90 |
bb_perror_msg_and_die("can't mmap %s", strfb_device); |
bb_perror_msg_and_die("mmap"); |
91 |
close(fbfd); |
close(fbfd); |
92 |
} |
} |
93 |
|
|
121 |
// vertical lines |
// vertical lines |
122 |
ptr1 = (DATA*)(G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx) * BYTES_PER_PIXEL); |
ptr1 = (DATA*)(G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx) * BYTES_PER_PIXEL); |
123 |
ptr2 = (DATA*)(G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx + G.nbar_width - 1) * BYTES_PER_PIXEL); |
ptr2 = (DATA*)(G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx + G.nbar_width - 1) * BYTES_PER_PIXEL); |
124 |
cnt = G.nbar_posy + G.nbar_height - 1 - G.nbar_posy; |
cnt = G.nbar_height - 1; |
125 |
do { |
do { |
126 |
*ptr1 = thispix; ptr1 += G.scr_var.xres; |
*ptr1 = thispix; ptr1 += G.scr_var.xres; |
127 |
*ptr2 = thispix; ptr2 += G.scr_var.xres; |
*ptr2 = thispix; ptr2 += G.scr_var.xres; |
216 |
*/ |
*/ |
217 |
static void fb_drawimage(void) |
static void fb_drawimage(void) |
218 |
{ |
{ |
|
char head[256]; |
|
|
char s[80]; |
|
219 |
FILE *theme_file; |
FILE *theme_file; |
220 |
|
char *read_ptr; |
221 |
unsigned char *pixline; |
unsigned char *pixline; |
222 |
unsigned i, j, width, height, line_size; |
unsigned i, j, width, height, line_size; |
223 |
|
|
224 |
memset(head, 0, sizeof(head)); |
if (LONE_DASH(G.image_filename)) { |
225 |
theme_file = xfopen_stdin(G.image_filename); |
theme_file = stdin; |
226 |
|
} else { |
227 |
|
int fd = open_zipped(G.image_filename); |
228 |
|
if (fd < 0) |
229 |
|
bb_simple_perror_msg_and_die(G.image_filename); |
230 |
|
theme_file = xfdopen_for_read(fd); |
231 |
|
} |
232 |
|
|
233 |
// parse ppm header |
/* Parse ppm header: |
234 |
|
* - Magic: two characters "P6". |
235 |
|
* - Whitespace (blanks, TABs, CRs, LFs). |
236 |
|
* - A width, formatted as ASCII characters in decimal. |
237 |
|
* - Whitespace. |
238 |
|
* - A height, ASCII decimal. |
239 |
|
* - Whitespace. |
240 |
|
* - The maximum color value, ASCII decimal, in 0..65535 |
241 |
|
* - Newline or other single whitespace character. |
242 |
|
* (we support newline only) |
243 |
|
* - A raster of Width * Height pixels in triplets of rgb |
244 |
|
* in pure binary by 1 or 2 bytes. (we support only 1 byte) |
245 |
|
*/ |
246 |
|
#define concat_buf bb_common_bufsiz1 |
247 |
|
read_ptr = concat_buf; |
248 |
while (1) { |
while (1) { |
249 |
if (fgets(s, sizeof(s), theme_file) == NULL) |
int w, h, max_color_val; |
250 |
bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
int rem = concat_buf + sizeof(concat_buf) - read_ptr; |
251 |
|
if (rem < 2 |
252 |
if (s[0] == '#') |
|| fgets(read_ptr, rem, theme_file) == NULL |
253 |
continue; |
) { |
|
|
|
|
if (strlen(head) + strlen(s) >= sizeof(head)) |
|
254 |
bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
255 |
|
} |
256 |
strcat(head, s); |
read_ptr = strchrnul(read_ptr, '#'); |
257 |
if (head[0] != 'P' || head[1] != '6') |
*read_ptr = '\0'; /* ignore #comments */ |
258 |
bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
if (sscanf(concat_buf, "P6 %u %u %u", &w, &h, &max_color_val) == 3 |
259 |
|
&& max_color_val <= 255 |
260 |
// width, height, max_color_val |
) { |
261 |
if (sscanf(head, "P6 %u %u %u", &width, &height, &i) == 3) |
width = w; /* w is on stack, width may be in register */ |
262 |
|
height = h; |
263 |
break; |
break; |
264 |
// TODO: i must be <= 255! |
} |
265 |
} |
} |
266 |
|
|
267 |
line_size = width*3; |
line_size = width*3; |
268 |
|
pixline = xmalloc(line_size); |
269 |
|
|
270 |
if (width > G.scr_var.xres) |
if (width > G.scr_var.xres) |
271 |
width = G.scr_var.xres; |
width = G.scr_var.xres; |
272 |
if (height > G.scr_var.yres) |
if (height > G.scr_var.yres) |
273 |
height = G.scr_var.yres; |
height = G.scr_var.yres; |
|
|
|
|
pixline = xmalloc(line_size); |
|
274 |
for (j = 0; j < height; j++) { |
for (j = 0; j < height; j++) { |
275 |
unsigned char *pixel = pixline; |
unsigned char *pixel; |
276 |
DATA *src = (DATA *)(G.addr + j * G.scr_fix.line_length); |
DATA *src; |
277 |
|
|
278 |
if (fread(pixline, 1, line_size, theme_file) != line_size) |
if (fread(pixline, 1, line_size, theme_file) != line_size) |
279 |
bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
280 |
|
pixel = pixline; |
281 |
|
src = (DATA *)(G.addr + j * G.scr_fix.line_length); |
282 |
for (i = 0; i < width; i++) { |
for (i = 0; i < width; i++) { |
283 |
unsigned thispix; |
unsigned thispix; |
284 |
thispix = (((unsigned)pixel[0] << 8) & 0xf800) |
thispix = (((unsigned)pixel[0] << 8) & 0xf800) |
299 |
*/ |
*/ |
300 |
static void init(const char *cfg_filename) |
static void init(const char *cfg_filename) |
301 |
{ |
{ |
302 |
static const char const param_names[] ALIGN1 = |
static const char param_names[] ALIGN1 = |
303 |
"BAR_WIDTH\0" "BAR_HEIGHT\0" |
"BAR_WIDTH\0" "BAR_HEIGHT\0" |
304 |
"BAR_LEFT\0" "BAR_TOP\0" |
"BAR_LEFT\0" "BAR_TOP\0" |
305 |
"BAR_R\0" "BAR_G\0" "BAR_B\0" |
"BAR_R\0" "BAR_G\0" "BAR_B\0" |
310 |
char *token[2]; |
char *token[2]; |
311 |
parser_t *parser = config_open2(cfg_filename, xfopen_stdin); |
parser_t *parser = config_open2(cfg_filename, xfopen_stdin); |
312 |
while (config_read(parser, token, 2, 2, "#=", |
while (config_read(parser, token, 2, 2, "#=", |
313 |
(PARSE_NORMAL | PARSE_MIN_DIE) & ~(PARSE_TRIM | PARSE_COLLAPSE))) { |
(PARSE_NORMAL | PARSE_MIN_DIE) & ~(PARSE_TRIM | PARSE_COLLAPSE))) { |
314 |
unsigned val = xatoi_u(token[1]); |
unsigned val = xatoi_u(token[1]); |
315 |
int i = index_in_strings(param_names, token[0]); |
int i = index_in_strings(param_names, token[0]); |
316 |
if (i < 0) |
if (i < 0) |
317 |
bb_error_msg_and_die("syntax error: '%s'", token[0]); |
bb_error_msg_and_die("syntax error: %s", token[0]); |
318 |
if (i >= 0 && i < 7) |
if (i >= 0 && i < 7) |
319 |
G.ns[i] = val; |
G.ns[i] = val; |
320 |
#if DEBUG |
#if DEBUG |
396 |
num = atoi(num_buf); |
num = atoi(num_buf); |
397 |
if (isdigit(num_buf[0]) && (num <= 100)) { |
if (isdigit(num_buf[0]) && (num <= 100)) { |
398 |
#if DEBUG |
#if DEBUG |
399 |
char strVal[10]; |
DEBUG_MESSAGE(itoa(num)); |
|
sprintf(strVal, "%d", num); |
|
|
DEBUG_MESSAGE(strVal); |
|
400 |
#endif |
#endif |
401 |
fb_drawprogressbar(num); |
fb_drawprogressbar(num); |
402 |
} |
} |