Magellan Linux

Annotation of /trunk/busybox/patches/busybox-1.19.0-fbsplash-tykef-1.0.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1516 - (hide annotations) (download)
Mon Sep 5 17:48:40 2011 UTC (12 years, 8 months ago) by niro
File size: 47932 byte(s)
-rediffed against 1.19.0
1 niro 1516 diff -Naur busybox-1.19.0/miscutils/Config.src busybox-1.19.0-magellan/miscutils/Config.src
2     --- busybox-1.19.0/miscutils/Config.src 2011-08-11 02:23:58.000000000 +0200
3     +++ busybox-1.19.0-magellan/miscutils/Config.src 2011-09-05 21:00:28.000000000 +0200
4     @@ -276,7 +276,8 @@
5     select PLATFORM_LINUX
6     help
7     Shows splash image and progress bar on framebuffer device.
8     - Can be used during boot phase of an embedded device. ~2kb.
9     + Can be used during boot phase of an embedded device.
10     + Code size is 2..7kb depends on enabled features.
11     Usage:
12     - use kernel option 'vga=xxx' or otherwise enable fb device.
13     - put somewhere fbsplash.cfg file and an image in .ppm format.
14     @@ -292,6 +293,44 @@
15     "NN" (ASCII decimal number) - percentage to show on progress bar
16     "exit" - well you guessed it
17    
18     +config FEATURE_FBSPLASH_8BPP
19     + bool "support 8bit depth with color mapping"
20     + depends on FBSPLASH
21     + help
22     + support for low color framebuffer that's need color mapping ~350 b
23     +
24     +config FEATURE_FBSPLASH_SPRITES
25     + bool "Render icons and animations"
26     + default n
27     + depends on FBSPLASH
28     + help
29     + This option adds the ability to display icons on the
30     + image displayed by the fbsplash applet. ~1.5kb.
31     + - command for fifo:
32     + "load:x:y:filename" - load images from file
33     + each sprite is one square area when image is wider than higher
34     + before load new sprite set, old area is cleared.
35     + "sprite:n" - show one sprite - sprite 0 is background.
36     + "anime:n:m:t" - anime from sprite n up/down to sprite m
37     + time between sprites is in t * 100 msec.
38     +
39     +config FEATURE_FBSPLASH_TEXT
40     + bool "text rendering"
41     + default n
42     + depends on FBSPLASH
43     + help
44     + This option adds the ability to print text messages on the
45     + image displayed by the fbsplash applet. ~2kb.
46     + - command for fifo:
47     + "write:string to print" - print the string after the word "write:"
48     +
49     +config FEATURE_FBSPLASH_FONTLOAD
50     + bool "font loading"
51     + depends on FEATURE_FBSPLASH_TEXT
52     + help
53     + The font is loaded from a standard console font file.
54     + Supported are psf v1.x and psf v2.0 files including mapping ~1kb.
55     +
56     config FLASHCP
57     bool "flashcp"
58     default n # doesn't build on Ubuntu 8.04
59     diff -Naur busybox-1.19.0/miscutils/fbsplash.c busybox-1.19.0-magellan/miscutils/fbsplash.c
60     --- busybox-1.19.0/miscutils/fbsplash.c 2011-08-11 02:23:58.000000000 +0200
61     +++ busybox-1.19.0-magellan/miscutils/fbsplash.c 2011-09-05 21:00:45.000000000 +0200
62     @@ -1,6 +1,7 @@
63     /* vi: set sw=4 ts=4: */
64     /*
65     * Copyright (C) 2008 Michele Sanges <michele.sanges@gmail.com>
66     + * Copyright (C) 2009 Jiri Gabriel <george.gabriel@seznam.cz>
67     *
68     * Licensed under GPLv2 or later, see file LICENSE in this source tree.
69     *
70     @@ -10,19 +11,51 @@
71     * - run applet: $ setsid fbsplash [params] &
72     * -c: hide cursor
73     * -d /dev/fbN: framebuffer device (if not /dev/fb0)
74     - * -s path_to_image_file (can be "-" for stdin)
75     + * -s path_to_image_file - ppm or ppm.gz or ppm.bz2
76     * -i path_to_cfg_file
77     * -f path_to_fifo (can be "-" for stdin)
78     + * -m font map file - standard psf file (v1 and v2) can be with unumap
79     * - if you want to run it only in presence of a kernel parameter
80     * (for example fbsplash=on), use:
81     * grep -q "fbsplash=on" </proc/cmdline && setsid fbsplash [params]
82     * - commands for fifo:
83     * "NN" (ASCII decimal number) - percentage to show on progress bar.
84     - * "exit" (or just close fifo) - well you guessed it.
85     + * if number is smaller than zero progress bar is filled from left.
86     + * "write:string to print" - print the string after the word "write:"
87     + * "exit" - well you guessed it.
88     + */
89     +
90     +/*
91     + * enhancements:
92     + * - framebuffer can be in depth 8,15,16,24,32 PSEUDOCOLR,TRUECOLOR
93     + * not only 16
94     + * - image file cannot be stdin
95     + * - bugfix: if virtual size is bigger than visual resolution
96     + * - progress bar can be dscending for shutdown (-1..-100)
97     + * - progress bar is from background picture + color in cfg - only colorize.
98     + * - bouncing bar - command "bounce" and at start.
99     + * - smaller image is shown centered on screen cfg positions recalc on demand.
100     + * - without text rendering and sprites grow size is only 800b.
101     + * text rendering:
102     + * - font is standard psf console font
103     + * - if font not specified or not compiled in fontload function
104     + * font is used from kernel using KDFONTOP / GIO_FONTX / GIO_FONT
105     + * - colorize text render by \033[30m .. \033[37m,\033[1;30 .. \033[1;37m
106     + * sprites:
107     + * - animated sprites load by fifo command "load:x:y:filename".
108     + * File is ppm format may be gzipped/bzipped or raw.
109     + * Frame/Icon is always square. Width of each Frame is image height.
110     + * Frame number 0 is always created for save background.
111     + * Transparent color is in ppm file is stored as #FF00FF - purple.
112     + * Show frame by pipe command "sprite:n" where n is frame number.
113     + * Run animated sequence by "anime:n:m:t" where
114     + * n is first frame m is last frame, t is time between displaying
115     + * frames in 0.1sec. n can be bigger than m for reverse order in anime.
116     */
117    
118     //usage:#define fbsplash_trivial_usage
119     //usage: "-s IMGFILE [-c] [-d DEV] [-i INIFILE] [-f CMD]"
120     +//usage: IF_FEATURE_FBSPLASH_FONTLOAD("[-m FONTMAPFILE]")
121     //usage:#define fbsplash_full_usage "\n\n"
122     //usage: " -s Image"
123     //usage: "\n -c Hide cursor"
124     @@ -30,31 +63,155 @@
125     //usage: "\n -i Config file (var=value):"
126     //usage: "\n BAR_LEFT,BAR_TOP,BAR_WIDTH,BAR_HEIGHT"
127     //usage: "\n BAR_R,BAR_G,BAR_B"
128     +//usage: "\n TEXT_LEFT,TEXT_TOP,TEXT_R,TEXT_G,TEXT_B,TEXT_SIZE"
129     //usage: "\n -f Control pipe (else exit after drawing image)"
130     //usage: "\n commands: 'NN' (% for progress bar) or 'exit'"
131     +//usage: IF_FEATURE_FBSPLASH_FONTLOAD(
132     +//usage: "\n -m Font map file"
133     +//usage: "\n commands: 'NN' (% for progress bar), 'write:string to print' or 'exit'"
134     +//usage: )
135    
136     #include "libbb.h"
137     +#if BB_BIG_ENDIAN
138     +#warning "fbsplash work only on little endian architecures. Sorry"
139     +int fbsplash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
140     +int fbsplash_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) {
141     + bb_error_msg_and_die("fbsplash not work on big endian architectures.");
142     + return 1;
143     +}
144     +
145     +#else
146     #include <linux/fb.h>
147    
148     +#if ENABLE_FEATURE_FBSPLASH_TEXT
149     +#include <linux/kd.h>
150     +
151     +/* if you have fonts with sequences can turn this to 1 i not find any font with this feature
152     + ~510 bytes of code */
153     +#define ENABLE_FEATURE_FBSPLASH_PSFSEQS 0
154     +
155     +/* if you not use text colors and need optimize size - disable text colors
156     + ~250 bytes of code */
157     +#define ENABLE_FEATURE_FBSPLASH_TEXT_COLORS 1
158     +
159     +#if !defined(GIO_UNIMAP)
160     +struct unipair {
161     + unsigned short unicode;
162     + unsigned short fontpos;
163     +} __atribute__ ((packed));
164     +
165     +struct unimapdesc {
166     + unsigned short entry_ct;
167     + struct unipair *entries;
168     +} __atribute__ ((packed));
169     +#endif
170     +
171     +#if ENABLE_FEATURE_FBSPLASH_FONTLOAD
172     +
173     +enum { // uint16
174     + PSF1_MAGIC = 0x0436,
175     + PSF1_SEPARATOR = 0xFFFF,
176     + PSF1_STARTSEQ = 0xFFFE
177     +};
178     +
179     +enum { // uint32
180     + PSF2_MAGIC = 0x864ab572,
181     + PSF2_HAS_UNICODE_TABLE = 0x01, /* bits used in flags */
182     + PSF2_MAXVERSION = 0 /* max version recognized so far */
183     +};
184     +
185     +enum { // uint8
186     + PSF1_MODE512 = 0x01,
187     + PSF1_MODEHASTAB = 0x02,
188     + PSF1_MODEHASSEQ = 0x04,
189     + PSF1_MAXMODE = 0x05,
190     + PSF2_STARTSEQ = 0xFE,
191     + PSF2_SEPARATOR = 0xFF
192     +};
193     +
194     +struct psf1_header {
195     + uint16_t magic; /* Magic number */
196     + uint8_t mode; /* PSF font mode */
197     + uint8_t charsize; /* Character size */
198     +} __attribute__ ((packed));
199     +
200     +struct psf2_header {
201     + uint32_t magic;
202     + uint32_t version;
203     + uint32_t headersize; /* offset of bitmaps in file */
204     + uint32_t flags;
205     + uint32_t length; /* number of glyphs */
206     + uint32_t charsize; /* number of bytes for each character */
207     + uint32_t height, width; /* max dimensions of glyphs */
208     + /* charsize = height * ((width + 7) / 8) */
209     +} __attribute__ ((packed));
210     +
211     +#endif // FONTLOAD
212     +struct fbfont {
213     + uint8_t *mem1;
214     + uint8_t *glyphs;
215     + struct unimapdesc ud;
216     + int height;
217     + int width;
218     + int glyphcount;
219     + int charsize;
220     + int rowbytes;
221     +};
222     +
223     +#endif
224     +
225     /* If you want logging messages on /tmp/fbsplash.log... */
226     #define DEBUG 0
227    
228     +typedef uint32_t RGB;
229     +
230     +struct sprite {
231     + int w,h,bw; // width height in pixels, width in bytes
232     + uint8_t pixbuf[0];
233     +};
234     +
235     +struct ppmfile {
236     + int fd;
237     + int sizx,sizy;
238     + int bufhead,buftail;
239     + uint8_t buf[0]; // buf for entire pixels row
240     +};
241     +
242     struct globals {
243     #if DEBUG
244     bool bdebug_messages; // enable/disable logging
245     FILE *logfile_fd; // log file
246     #endif
247     - unsigned char *addr; // pointer to framebuffer memory
248     - unsigned ns[7]; // n-parameters
249     + unsigned char *addr; // pointer to visible framebuffer memory
250     + unsigned char *mapaddr; // pointer to framebuffer memory
251     +#if ENABLE_FEATURE_FBSPLASH_TEXT
252     + #define FBCFGVALS 13
253     +#else
254     + #define FBCFGVALS 7
255     +#endif
256     + unsigned ns[FBCFGVALS]; // n-parameters
257     const char *image_filename;
258     struct fb_var_screeninfo scr_var;
259     struct fb_fix_screeninfo scr_fix;
260     - unsigned bytes_per_pixel;
261     + int bytes_per_pixel,x0,y0; // offset for centering
262     + struct sprite *spb1,*spb2;
263     +#if ENABLE_FEATURE_FBSPLASH_TEXT
264     + struct fbfont *font;
265     + struct sprite *spt;
266     + uint8_t *unknown_glyph;
267     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
268     + uint8_t combglyph[4*32]; /* max width=32 max height=32 */
269     +#endif
270     +#endif
271     };
272     +
273     #define G (*ptr_to_globals)
274     #define INIT_G() do { \
275     SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
276     } while (0)
277     +#if ENABLE_FEATURE_FBSPLASH_TEXT
278     + #define GF (*(ptr_to_globals->font))
279     +#endif
280    
281     #define nbar_width ns[0] // progress bar width
282     #define nbar_height ns[1] // progress bar height
283     @@ -63,6 +220,75 @@
284     #define nbar_colr ns[4] // progress bar color red component
285     #define nbar_colg ns[5] // progress bar color green component
286     #define nbar_colb ns[6] // progress bar color blue component
287     +#define text_posx ns[7] // text horizontal position
288     +#define text_posy ns[8] // text vertical position
289     +#define text_colr ns[9] // text color red component
290     +#define text_colg ns[10] // text color green component
291     +#define text_colb ns[11] // text color blue component
292     +#define text_size ns[12] // text size (1 to 4)
293     +
294     +/**
295     + * A function to compute pixel value
296     + */
297     +static RGB FAST_FUNC makecol(uint16_t r, uint16_t g, uint16_t b) {
298     + if (r > 255) r = 255;
299     + if (g > 255) g = 255;
300     + if (b > 255) b = 255;
301     +#if ENABLE_FEATURE_FBSPLASH_8BPP
302     + if (G.bytes_per_pixel == 1) {
303     + // mymap is 6*8*5 = 240 values on offset 16
304     + // (r/42.6666) + (g/32) + (b/51.2)
305     + return 16 + (((r << 8) + r) / 13107) * 40 +
306     + (((g << 8) + g) / 9362) * 5 +
307     + (((b << 8) + b) / 16383);
308     + }
309     +#endif
310     + return ((r >> (8 - G.scr_var.red.length )) << G.scr_var.red.offset) |
311     + ((g >> (8 - G.scr_var.green.length)) << G.scr_var.green.offset) |
312     + ((b >> (8 - G.scr_var.blue.length )) << G.scr_var.blue.offset);
313     +}
314     +
315     +/*
316     + * A function to put the pixel row
317     + */
318     +static void fb_putpixrow(int x, int y, int w, uint8_t *rgb) {
319     + uint8_t *a;
320     + int realw;
321     + if (x < 0 || y < 0 || x > G.scr_var.xres || y > G.scr_var.yres) return;
322     + a = G.addr + G.scr_fix.line_length * y + G.bytes_per_pixel * x;
323     + realw = ((x + w) < G.scr_var.xres ? w : G.scr_var.xres - x) * G.bytes_per_pixel;
324     + memcpy(a,rgb,realw);
325     + return;
326     +}
327     +
328     +/*
329     + * A function to put the sprite to position or fill sprite from videoram
330     + */
331     +static void fb_sprite(int x, int y, int x0, int width, struct sprite *s, int direction) {
332     + uint8_t *a,*p;
333     + int realw,iy;
334     +
335     + if (x < 0 || y < 0 || x > G.scr_var.xres || y > G.scr_var.yres ||
336     + x0 >= s->w || x0 < 0 || width > (s->w - x0)) {
337     + return;
338     + }
339     + realw = ((x + width) < G.scr_var.xres ? width : (G.scr_var.xres - x)) * G.bytes_per_pixel;
340     + a = G.addr + G.scr_fix.line_length * y + G.bytes_per_pixel * x;
341     + p = &(s->pixbuf[x0 * G.bytes_per_pixel]);
342     + for (iy = 0; iy < s->h; iy++) {
343     + if ((iy + y) > G.scr_var.yres) break;
344     + if (direction == 1) {
345     + memcpy(p,a,realw);
346     + } else {
347     + memcpy(a,p,realw);
348     + }
349     + a += G.scr_fix.line_length;
350     + p += s->bw;
351     + }
352     + return;
353     +}
354     +#define fb_putsprite(x,y,s) fb_sprite(x,y,0,s->w,s,0)
355     +#define fb_getsprite(x,y,s) fb_sprite(x,y,0,s->w,s,1)
356    
357     #if DEBUG
358     #define DEBUG_MESSAGE(strMessage, args...) \
359     @@ -87,19 +313,60 @@
360     xioctl(fbfd, FBIOGET_VSCREENINFO, &G.scr_var);
361     xioctl(fbfd, FBIOGET_FSCREENINFO, &G.scr_fix);
362    
363     - if (G.scr_var.bits_per_pixel < 16 || G.scr_var.bits_per_pixel > 32)
364     - bb_error_msg_and_die("unsupported %u bpp", (int)G.scr_var.bits_per_pixel);
365     - G.bytes_per_pixel = (G.scr_var.bits_per_pixel + 7) >> 3;
366     +#if ENABLE_FEATURE_FBSPLASH_8BPP
367     + if ((G.scr_var.bits_per_pixel < 8) ||
368     + (G.scr_fix.type != FB_TYPE_PACKED_PIXELS)) {
369     + bb_error_msg_and_die("only 8,15,16,24 and 32 bpp is supported");
370     + }
371     +#else
372     + if ((G.scr_var.bits_per_pixel < 15) ||
373     + (G.scr_fix.type != FB_TYPE_PACKED_PIXELS)) {
374     + bb_error_msg_and_die("only 15,16,24 and 32 bpp is supported");
375     + }
376     +#endif
377     + switch (G.scr_fix.visual) {
378     +#if ENABLE_FEATURE_FBSPLASH_8BPP
379     + case FB_VISUAL_PSEUDOCOLOR: do {
380     + uint8_t *cmem;
381     + struct fb_cmap *cmap;
382     + int r,g,b,i;
383     + cmem = xzalloc(sizeof(struct fb_cmap) + sizeof(uint16_t) * 3 * 256);
384     + cmap = (struct fb_cmap *)cmem;
385     + cmap->len = 256;
386     + cmap->red = (uint16_t *)&(cmem[sizeof(struct fb_cmap)]);
387     + cmap->green = &(cmap->red[256]);
388     + cmap->blue = &(cmap->green[256]);
389     + xioctl(fbfd, FBIOGETCMAP, cmem); // read original palette
390     + // fill cmap with my 6x8x5 pallette
391     + for (r = 0,i = 16; r < 6; r++) {
392     + for (g = 0; g < 8; g++) {
393     + for (b = 0; b < 5; b++, i++) {
394     + cmap->red[i] = r * 13107;
395     + cmap->green[i] = g * 9362;
396     + cmap->blue[i] = b * 16383;
397     + }
398     + }
399     + }
400     + xioctl(fbfd, FBIOPUTCMAP, cmem);
401     + free(cmem);
402     + } while(0);
403     +#endif
404     + case FB_VISUAL_TRUECOLOR:
405     + break;
406     + default:
407     + bb_error_msg_and_die("only TrueColor modes is supported");
408     + }
409     +
410     + G.bytes_per_pixel = (G.scr_var.bits_per_pixel + 7) / 8;
411    
412     // map the device in memory
413     - G.addr = mmap(NULL,
414     - G.scr_var.xres * G.scr_var.yres * G.bytes_per_pixel,
415     + G.mapaddr = mmap(NULL,
416     + G.scr_var.yres_virtual * G.scr_fix.line_length ,
417     PROT_WRITE, MAP_SHARED, fbfd, 0);
418     - if (G.addr == MAP_FAILED)
419     + if (G.mapaddr == MAP_FAILED)
420     bb_perror_msg_and_die("mmap");
421     -
422     // point to the start of the visible screen
423     - G.addr += G.scr_var.yoffset * G.scr_fix.line_length + G.scr_var.xoffset * G.bytes_per_pixel;
424     + G.addr = G.mapaddr + G.scr_var.yoffset * G.scr_fix.line_length;
425     close(fbfd);
426     }
427    
428     @@ -140,142 +407,50 @@
429    
430    
431     /**
432     - * Draw hollow rectangle on framebuffer
433     - */
434     -static void fb_drawrectangle(void)
435     -{
436     - int cnt;
437     - unsigned thispix;
438     - unsigned char *ptr1, *ptr2;
439     - unsigned char nred = G.nbar_colr/2;
440     - unsigned char ngreen = G.nbar_colg/2;
441     - unsigned char nblue = G.nbar_colb/2;
442     -
443     - thispix = fb_pixel_value(nred, ngreen, nblue);
444     -
445     - // horizontal lines
446     - ptr1 = G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx) * G.bytes_per_pixel;
447     - ptr2 = G.addr + ((G.nbar_posy + G.nbar_height - 1) * G.scr_var.xres + G.nbar_posx) * G.bytes_per_pixel;
448     - cnt = G.nbar_width - 1;
449     - do {
450     - fb_write_pixel(ptr1, thispix);
451     - fb_write_pixel(ptr2, thispix);
452     - ptr1 += G.bytes_per_pixel;
453     - ptr2 += G.bytes_per_pixel;
454     - } while (--cnt >= 0);
455     -
456     - // vertical lines
457     - ptr1 = G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx) * G.bytes_per_pixel;
458     - ptr2 = G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx + G.nbar_width - 1) * G.bytes_per_pixel;
459     - cnt = G.nbar_height - 1;
460     - do {
461     - fb_write_pixel(ptr1, thispix);
462     - fb_write_pixel(ptr2, thispix);
463     - ptr1 += G.scr_var.xres * G.bytes_per_pixel;
464     - ptr2 += G.scr_var.xres * G.bytes_per_pixel;
465     - } while (--cnt >= 0);
466     -}
467     -
468     -
469     -/**
470     - * Draw filled rectangle on framebuffer
471     - * \param nx1pos,ny1pos upper left position
472     - * \param nx2pos,ny2pos down right position
473     - * \param nred,ngreen,nblue rgb color
474     - */
475     -static void fb_drawfullrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos,
476     - unsigned char nred, unsigned char ngreen, unsigned char nblue)
477     -{
478     - int cnt1, cnt2, nypos;
479     - unsigned thispix;
480     - unsigned char *ptr;
481     -
482     - thispix = fb_pixel_value(nred, ngreen, nblue);
483     -
484     - cnt1 = ny2pos - ny1pos;
485     - nypos = ny1pos;
486     - do {
487     - ptr = G.addr + (nypos * G.scr_var.xres + nx1pos) * G.bytes_per_pixel;
488     - cnt2 = nx2pos - nx1pos;
489     - do {
490     - fb_write_pixel(ptr, thispix);
491     - ptr += G.bytes_per_pixel;
492     - } while (--cnt2 >= 0);
493     -
494     - nypos++;
495     - } while (--cnt1 >= 0);
496     -}
497     -
498     -
499     -/**
500     * Draw a progress bar on framebuffer
501     - * \param percent percentage of loading
502     + * \param frompct percentage on which bar starting
503     + * \param topct percentage where bar end
504     */
505     -static void fb_drawprogressbar(unsigned percent)
506     +static void fb_drawnbar(int frompct, int topct)
507     {
508     - int i, left_x, top_y, width, height;
509     + int w0,w1,w2;
510    
511     - // outer box
512     - left_x = G.nbar_posx;
513     - top_y = G.nbar_posy;
514     - width = G.nbar_width - 1;
515     - height = G.nbar_height - 1;
516     - if ((height | width) < 0)
517     + if (G.spb1 == NULL || G.spb2 == NULL)
518     return;
519     - // NB: "width" of 1 actually makes rect with width of 2!
520     - fb_drawrectangle();
521     -
522     - // inner "empty" rectangle
523     - left_x++;
524     - top_y++;
525     - width -= 2;
526     - height -= 2;
527     - if ((height | width) < 0)
528     + if (frompct < 0 || frompct > 100 ||
529     + topct < 0 || topct > 100 ||
530     + frompct > topct) {
531     return;
532     - fb_drawfullrectangle(
533     - left_x, top_y,
534     - left_x + width, top_y + height,
535     - G.nbar_colr, G.nbar_colg, G.nbar_colb);
536     -
537     - if (percent > 0) {
538     - // actual progress bar
539     - width = width * percent / 100;
540     - i = height;
541     - if (height == 0)
542     - height++; // divide by 0 is bad
543     - while (i >= 0) {
544     - // draw one-line thick "rectangle"
545     - // top line will have gray lvl 200, bottom one 100
546     - unsigned gray_level = 100 + i*100/height;
547     - fb_drawfullrectangle(
548     - left_x, top_y, left_x + width, top_y,
549     - gray_level, gray_level, gray_level);
550     - top_y++;
551     - i--;
552     - }
553     }
554     +
555     + w0 = G.spb1->w * frompct / 100;
556     + w0 = (w0 > G.spb1->w ? G.spb1->w : w0);
557     + w2 = G.spb1->w * (100 - topct) / 100;
558     + w2 = ((w0 + w2) > G.spb1->w ? G.spb1->w - w0 : w2);
559     + w1 = G.spb1->w - w0 - w2;
560     + if (w0 > 0)
561     + fb_sprite(G.nbar_posx, G.nbar_posy, 0, w0, G.spb1, 0); // left "empty" area
562     + if (w1 > 0)
563     + fb_sprite(G.nbar_posx + w0, G.nbar_posy, w0, w1, G.spb2, 0); // filled area
564     + if (w2 > 0)
565     + fb_sprite(G.nbar_posx + w0 + w1, G.nbar_posy, w0 + w1, w2, G.spb1, 0); // right "empty" area
566     }
567    
568    
569     /**
570     - * Draw image from PPM file
571     + * Open PPM file - must be binary, color maxval 255
572     */
573     -static void fb_drawimage(void)
574     -{
575     - FILE *theme_file;
576     - char *read_ptr;
577     - unsigned char *pixline;
578     - unsigned i, j, width, height, line_size;
579     -
580     - if (LONE_DASH(G.image_filename)) {
581     - theme_file = stdin;
582     - } else {
583     - int fd = open_zipped(G.image_filename);
584     - if (fd < 0)
585     - bb_simple_perror_msg_and_die(G.image_filename);
586     - theme_file = xfdopen_for_read(fd);
587     - }
588     -
589     +static struct ppmfile *ppm_open(const char *filename) {
590     + int i,k,l,val;
591     + struct ppmfile *p;
592     + uint8_t *s;
593     + char *e;
594     +
595     + i = open_zipped(filename);
596     + if (i == -1) return NULL;
597     + p = (struct ppmfile *) xmalloc(sizeof(struct ppmfile) + 600);
598     + // initial buf 600 bytes header cannot be larger
599     + p->fd = i;
600     /* Parse ppm header:
601     * - Magic: two characters "P6".
602     * - Whitespace (blanks, TABs, CRs, LFs).
603     @@ -289,53 +464,721 @@
604     * - A raster of Width * Height pixels in triplets of rgb
605     * in pure binary by 1 or 2 bytes. (we support only 1 byte)
606     */
607     -#define concat_buf bb_common_bufsiz1
608     - read_ptr = concat_buf;
609     - while (1) {
610     - int w, h, max_color_val;
611     - int rem = concat_buf + sizeof(concat_buf) - read_ptr;
612     - if (rem < 2
613     - || fgets(read_ptr, rem, theme_file) == NULL
614     - ) {
615     - bb_error_msg_and_die("bad PPM file '%s'", G.image_filename);
616     - }
617     - read_ptr = strchrnul(read_ptr, '#');
618     - *read_ptr = '\0'; /* ignore #comments */
619     - if (sscanf(concat_buf, "P6 %u %u %u", &w, &h, &max_color_val) == 3
620     - && max_color_val <= 255
621     - ) {
622     - width = w; /* w is on stack, width may be in register */
623     - height = h;
624     - break;
625     + l=read(p->fd,&(p->buf[0]),600);
626     + if ((l < 0) || (p->buf[0] != 'P') || (p->buf[1] != '6')) {
627     + goto ppmopen_end;
628     + }
629     + for (s = &(p->buf[2]), i = 0, k = 0; s < &(p->buf[l]) && (k < 3); ) {
630     + switch (i) {
631     + case 0:
632     + if (*s <= ' ') {
633     + s++; // skip whitespaces
634     + } else {
635     + i++; // next state
636     + }
637     + break;
638     + case 1: // num or rmks
639     + if (*s == '#') {
640     + i = 2;
641     + } else {
642     + val=bb_strtoi((char *)s,&e,10);
643     + if (s == (uint8_t *)e) goto ppmopen_end; // no number - error
644     + s=(uint8_t *)e;
645     + i=0; // skip whitespaces
646     + switch (++k) {
647     + case 1: p->sizx = val; break;
648     + case 2: p->sizy = val; break;
649     + case 3:
650     + if (val > 255)
651     + goto ppmopen_end; // only 1 byte per color
652     + s++;
653     + p->bufhead = s - &(p->buf[0]);
654     + p->buftail = l;
655     + break;
656     + }
657     + }
658     + break;
659     + case 2: // skip to eol
660     + if (*s == 10) i=0;
661     + s++;
662     + break;
663     + }
664     + }
665     + if (p->sizx < 1 || p->sizy < 1) goto ppmopen_end;
666     + if (p->sizx > 200) {
667     + // buf is only 600 bytes = 200 pix prealocated - need more.
668     + p = xrealloc(p,sizeof(struct ppmfile) + 3 * p->sizx);
669     + }
670     + return p;
671     +
672     +ppmopen_end:
673     + close(p->fd);
674     + free(p);
675     + return NULL;
676     +}
677     +
678     +/**
679     + * Read pixelline from ppm to internal buffer and return pointer
680     + */
681     +static uint8_t *ppm_readline(struct ppmfile *p) {
682     + int i;
683     + if (p==NULL) return NULL;
684     + if (p->bufhead < p->buftail) {
685     + // pack buffer
686     + for (i = 0; p->bufhead < p->buftail; i++) {
687     + p->buf[i]=p->buf[p->bufhead++];
688     }
689     + p->buftail = i;
690     + } else {
691     + p->buftail = 0;
692     }
693     + while (p->buftail < (p->sizx * 3)) {
694     + i=read(p->fd, &(p->buf[p->buftail]), (p->sizx * 3) - p->buftail);
695     + if (i < 0) return NULL;
696     + p->buftail += i;
697     + }
698     + p->bufhead = p->sizx * 3;
699     + return &(p->buf[0]);
700     +}
701    
702     - line_size = width*3;
703     - pixline = xmalloc(line_size);
704     +/**
705     + * Close ppmfile
706     + */
707     +static void ppm_close(struct ppmfile *p) {
708     + if (p == NULL) return;
709     + close(p->fd);
710     + free(p);
711     +}
712     +
713     +/**
714     + * Draws a PPM image.
715     + */
716     +static void fb_drawimage(void)
717     +{
718     + struct ppmfile *ppm;
719     + unsigned char *pixel;
720     + unsigned char *rgbline,*rgbpix,*sprpix;
721     + RGB thispix;
722     + unsigned i, j, width, height;
723     +
724     + ppm = ppm_open(G.image_filename);
725     + if (ppm == NULL)
726     + bb_error_msg_and_die("PPM file %s cannot be opened",G.image_filename);
727     + width = ppm->sizx;
728     + height = ppm->sizy;
729     + if (width > G.scr_var.xres || height > G.scr_var.yres)
730     + bb_error_msg_and_die("PPM %dx%d does not match screen %dx%d",
731     + width, height, G.scr_var.xres, G.scr_var.yres);
732     + if (width > G.scr_var.xres)
733     + width = G.scr_var.xres;
734     + if (height > G.scr_var.yres)
735     + height = G.scr_var.yres;
736     +
737     + G.x0 = (width == G.scr_var.xres ? 0 : (G.scr_var.xres - width) / 2);
738     + G.y0 = (height == G.scr_var.yres ? 0 : (G.scr_var.yres - height) / 2);
739     + rgbline = xmalloc((width * G.bytes_per_pixel) + sizeof(RGB));
740    
741     - if (width > G.scr_var.xres)
742     - width = G.scr_var.xres;
743     - if (height > G.scr_var.yres)
744     - height = G.scr_var.yres;
745     for (j = 0; j < height; j++) {
746     - unsigned char *pixel;
747     - unsigned char *src;
748     + pixel = ppm_readline(ppm);
749     + rgbpix = rgbline;
750     + if (pixel == NULL)
751     + bb_error_msg_and_die("bad PPM file '%s' line %d", G.image_filename,j);
752     + if (G.spb2 != NULL && j >= G.nbar_posy && j < (G.nbar_posy + G.spb2->h)) {
753     + sprpix = &(G.spb2->pixbuf[(j - G.nbar_posy) * G.spb2->bw]);
754     + } else {
755     + sprpix = NULL;
756     + }
757    
758     - if (fread(pixline, 1, line_size, theme_file) != line_size)
759     - bb_error_msg_and_die("bad PPM file '%s'", G.image_filename);
760     - pixel = pixline;
761     - src = G.addr + j * G.scr_fix.line_length;
762     for (i = 0; i < width; i++) {
763     - unsigned thispix = fb_pixel_value(pixel[0], pixel[1], pixel[2]);
764     - fb_write_pixel(src, thispix);
765     - src += G.bytes_per_pixel;
766     + thispix = makecol(pixel[0],pixel[1],pixel[2]);
767     + *((RGB*)rgbpix) = thispix;
768     + if ((sprpix != NULL) && (i >= G.nbar_posx)) {
769     + if (G.nbar_colr >= 256) { // Multiple not add
770     + thispix = makecol((G.nbar_colr & 255) * pixel[0], (G.nbar_colg & 255) * pixel[1], (G.nbar_colb & 255) * pixel[2]);
771     + } else {
772     + thispix = makecol(G.nbar_colr + pixel[0], G.nbar_colg + pixel[1], G.nbar_colb + pixel[2]);
773     + }
774     + memcpy(sprpix,&thispix,G.bytes_per_pixel);
775     + if (i >= (G.nbar_posx + G.spb2->w - 1)) {
776     + sprpix = NULL;
777     + } else {
778     + sprpix += G.bytes_per_pixel;
779     + }
780     + }
781     pixel += 3;
782     + rgbpix += G.bytes_per_pixel;
783     }
784     + fb_putpixrow(G.x0,j + G.y0,width,rgbline);
785     }
786     - free(pixline);
787     - fclose(theme_file);
788     + free(rgbline);
789     + ppm_close(ppm);
790     + // recalc cfg if centered image
791     + G.nbar_posx += G.x0;
792     + G.nbar_posy += G.y0;
793     +#if ENABLE_FEATURE_FBSPLASH_TEXT
794     + G.text_posx += G.x0;
795     + G.text_posy += G.y0;
796     +#endif
797     +}
798     +
799     +#if ENABLE_FEATURE_FBSPLASH_SPRITES
800     +/**
801     + * Read rectangle sprites from ppm file
802     + * \return pointer to array of sprites
803     + * \return number of sprites loaded
804     + */
805     +static struct sprite *fb_loadsprites(char *filename, int sx, int sy) {
806     + struct ppmfile *ppm;
807     + uint8_t *pixel, *rgbpix;
808     + struct sprite *s=NULL;
809     + int y,i;
810     + RGB thispix;
811     +
812     + if ((ppm = ppm_open(filename)) == NULL) goto readsprites_out;
813     + s = fb_newsprite(ppm->sizx + ppm->sizy, ppm->sizy, -1, -1);
814     + fb_sprite(sx + G.x0, sy + G.y0, 0, s->h, s, 1); // load square 0 - background
815     + rgbpix = &(s->pixbuf[0]);
816     + for (y = 0; y < ppm->sizy; y++) {
817     + // skip square 0
818     + rgbpix += s->h * G.bytes_per_pixel;
819     + // read from file
820     + pixel = ppm_readline(ppm);
821     + for (i = 0; (pixel != NULL) && (i < ppm->sizx); i++) {
822     + if (pixel[0]==0xFF && pixel[1]==0 && pixel[2]==0xFF) {
823     + // transparent color => get pixel from square 0
824     + memcpy(&thispix,
825     + &(s->pixbuf[y * s->bw + (i % s->h) * G.bytes_per_pixel]),
826     + G.bytes_per_pixel);
827     + } else {
828     + thispix = makecol(pixel[0],pixel[1],pixel[2]);
829     + }
830     + memcpy(rgbpix,&thispix,G.bytes_per_pixel);
831     + pixel += 3;
832     + rgbpix += G.bytes_per_pixel;
833     + }
834     + }
835     + ppm_close(ppm);
836     + return s;
837     +readsprites_out:
838     + if (s != NULL) free(s);
839     + return NULL;
840     }
841    
842     +#define fb_putanim(x,y,n,s) fb_sprite(x + G.x0,y + G.y0,s->h * n,s->h,s,0)
843     +#endif
844     +
845     +#if ENABLE_FEATURE_FBSPLASH_TEXT
846     +
847     +/*
848     + * A function to put the pixel
849     + */
850     +static void fb_putpixel(int x, int y, RGB rgb) {
851     + uint8_t *a;
852     + if (x < 0 || y < 0 || x > G.scr_var.xres || y > G.scr_var.yres) return;
853     + a=G.addr + G.scr_fix.line_length * y + G.bytes_per_pixel * x;
854     + memcpy(a,&rgb,G.bytes_per_pixel);
855     +
856     + return;
857     +}
858     +
859     +/**
860     + * UTF-8 - get one charcter and advance to next
861     + * ??? this function may be in libbb ???
862     + * \return UCS4 value
863     + */
864     +static uint32_t ucs4value(uint8_t **s) {
865     + uint8_t *c;
866     + uint32_t ucs,w;
867     + int count;
868     +
869     + if (s==NULL || *s==NULL || **s==0) return 0;
870     + c = *s;
871     + ucs = *c++;
872     + if (ucs >= 0xC0) { /* 0x80..0xBF is error in utf8 but i use as-is */
873     + for (w = ucs & 0x7F, count = 0;(w & 0x40) == 0x40; count++) {
874     + w <<= 1;
875     + }
876     + ucs=ucs & (0x7E >> count);
877     + for(; count > 0; count--) {
878     + if ((*c & 0xC0) != 0x80) { /* error in utf8 */
879     + ucs=0;
880     + break;
881     + }
882     + ucs = (ucs << 6) + (*c++ & 0x3F);
883     + }
884     + }
885     + *s=c;
886     + return ucs;
887     +}
888     +
889     +/**
890     + * Find in GF.ud.entries desired UTF-8 char and advance to next char
891     + * can combine glyphs in own memory
892     + * \param s pointer to utf8 char pointer
893     + * \return pinter to glyph
894     + */
895     +static uint8_t *getglyph(uint8_t **s) {
896     + uint32_t ucs;
897     + uint8_t *c,*g;
898     + int utflen,i;
899     +
900     + if (s == NULL || *s == NULL || **s == 0)
901     + return G.unknown_glyph; /* end of string - no advance */
902     + c = *s;
903     + ucs = ucs4value(&c);
904     + utflen = c - *s;
905     + g = G.unknown_glyph;
906     + if (GF.ud.entries == NULL) {
907     + if (ucs < GF.glyphcount) {
908     + g = GF.glyphs + GF.charsize * ucs;
909     + }
910     + } else if (ucs <= 0xFFFF) { // only ucs2
911     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
912     + int j,compose;
913     + memset(G.combglyph,0,sizeof(G.combglyph));
914     + for (i = 0, compose=0; i < GF.ud.entry_ct; i++) {
915     + if (GF.ud.entries[i].unicode == ucs) {
916     + g=GF.glyphs +
917     + GF.ud.entries[i].fontpos * GF.charsize;
918     + for (j = 0; j < GF.charsize; j++) {
919     + G.combglyph[j] |= g[j];
920     + }
921     + compose++;
922     + }
923     + }
924     + if (compose > 1) { // found more than one
925     + g = &(G.combglyph[0]);
926     + }
927     +#else
928     + // no sequences - first found win
929     + for (i = 0; i < GF.ud.entry_ct ; i++) {
930     + if (GF.ud.entries[i].unicode == ucs) {
931     + g = GF.glyphs + GF.ud.entries[i].fontpos * GF.charsize;
932     + break;
933     + }
934     + }
935     +#endif
936     + }
937     + *s=c;
938     + return g;
939     +}
940     +
941     +/**
942     + * Draws a single character on framebuffer.
943     + * \param nXPos horizontal position from which draw the character.
944     + * \param nYPos vertical position from which draw the character.
945     + * \param nCharSize character scale factor [1..4].
946     + * \param pointer to *nChar character to draw - auto advance by utf8.
947     + * \param RGB color
948     + */
949     +static void fb_drawchar(int nXPos, int nYPos, int nCharSize,
950     + uint8_t **nChar, RGB thispix)
951     +{
952     + int x,y,px;
953     + uint8_t *glyph;
954     +
955     + if (G.font==NULL || GF.height==0 || GF.glyphs==NULL) return;
956     + if (G.unknown_glyph == NULL) {
957     + uint8_t *unknown;
958     + const uint8_t unconst[]="?";
959     + unknown=(uint8_t *)unconst;
960     + G.unknown_glyph = getglyph(&unknown);
961     + }
962     +
963     + glyph=getglyph(nChar);
964     + if (glyph==NULL) return;
965     + glyph-=GF.rowbytes;
966     + for (y = 0; y < (GF.height * nCharSize); y++) {
967     + if ((y % nCharSize) == 0) glyph+=GF.rowbytes;
968     + for (x = 0,px = -1; x < (GF.width * nCharSize); x++) {
969     + if ((x % nCharSize) == 0) px++;
970     + if ((glyph[px / 8] & (0x80 >> (px % 8))) != 0) {
971     + fb_putpixel(nXPos + x, nYPos + y,thispix);
972     + }
973     + }
974     + }
975     +}
976     +
977     +
978     +/**
979     + * Draws a string on framebuffer.
980     + * \param *strString pointer to the string.
981     + */
982     +static void fb_drawstring(char *strString)
983     +{
984     + RGB thispix;
985     + int nCharSize;
986     + int x;
987     + uint8_t *c;
988     +
989     + // size check
990     + nCharSize = G.text_size;
991     + if (nCharSize < 1)
992     + nCharSize = 1;
993     + else if (nCharSize > 4)
994     + nCharSize = 4;
995     +
996     + if (G.font==NULL || GF.height==0 || GF.glyphs==NULL) return;
997     +
998     + // redraws the portion of image interested to the old write operation
999     + fb_putsprite(G.text_posx, G.text_posy, G.spt);
1000     +
1001     + // new write operation
1002     + thispix=makecol(G.text_colr,G.text_colg,G.text_colb);
1003     + for (x = G.text_posx, c = (uint8_t *)strString; *c != 0;) {
1004     +#if ENABLE_FEATURE_FBSPLASH_TEXT_COLORS
1005     + if (*c==0x1b && c[1]=='[') {
1006     + long newcol=0,first;
1007     + char *e;
1008     + e=(char *)&(c[1]);
1009     + do {
1010     + first=newcol;
1011     + ++e;
1012     + newcol = strtol(e,&e,10);
1013     + } while (*e == ';');
1014     + if (*e == 'm' && ((newcol == 0) || (newcol >= 30 && newcol <= 37))) {
1015     + if (newcol >= 30 && newcol <= 37) {
1016     + if (newcol == 0 && first == 1) {
1017     + thispix=makecol(0x33,0x33,0x33);
1018     + } else {
1019     + newcol -= 30;
1020     + first = (first == 1 ? 0xFF : 0xCC);
1021     + thispix=makecol((newcol & 1) ? first : 0,
1022     + (newcol & 2) ? first : 0,
1023     + (newcol & 4) ? first : 0);
1024     + }
1025     + } else {
1026     + thispix=makecol(G.text_colr,G.text_colg,G.text_colb);
1027     + }
1028     + c=(uint8_t *)(++e);
1029     + continue;
1030     + }
1031     + }
1032     +#endif
1033     + fb_drawchar(x, G.text_posy, nCharSize, &c, thispix);
1034     + x += GF.width * nCharSize;
1035     + if (x >= G.scr_var.xres) break; // too long string
1036     + }
1037     +}
1038     +
1039     +/**
1040     + * Free readed font structure with all allocated memory
1041     + */
1042     +static void fb_freefont(void) {
1043     + if (G.font != NULL) {
1044     + if (GF.mem1 != NULL) free(GF.mem1);
1045     + if (GF.ud.entries != NULL) free(GF.ud.entries);
1046     + free(G.font);
1047     + G.font=NULL;
1048     + }
1049     +}
1050     +
1051     +/**
1052     + * Read font and mapping from console using ioctl GIO_FONT and GIO_UNIMAP
1053     + */
1054     +static void fb_readvgafont(void) {
1055     + int fd,i;
1056     +#if (defined(KDFONTOP) && defined(KD_FONT_OP_GET)) || defined(GIO_FONTX)
1057     +#if defined(KDFONTOP) && defined(KD_FONT_OP_GET)
1058     + struct console_font_op fo;
1059     + fd = open(CURRENT_TTY,O_NONBLOCK);
1060     + if (fd == -1) return;
1061     +
1062     + fo.data = NULL;
1063     + fo.charcount = 0;
1064     + fo.height = 32; fo.width = 32; // max usable font size
1065     + fo.flags = 0;
1066     + fo.op = KD_FONT_OP_GET;
1067     + if (ioctl(fd, KDFONTOP, &fo) == 0) {
1068     + i = (fo.width + 7) / 8;
1069     + fo.data = xmalloc(fo.charcount * 32 * i);
1070     + if (ioctl(fd, KDFONTOP, &fo) == -1) {
1071     + free(fo.data);
1072     + goto fb_vgafontout;
1073     + }
1074     + }
1075     + if (G.font != NULL) fb_freefont();
1076     + G.font = (struct fbfont *) xzalloc(sizeof(struct fbfont));
1077     + GF.height = fo.height;
1078     + GF.glyphcount = fo.charcount;
1079     + GF.width = fo.width;
1080     + GF.rowbytes = (fo.width + 7) / 8;
1081     + GF.charsize = GF.height * GF.rowbytes;
1082     + GF.mem1 = (uint8_t *) xmalloc(GF.height * GF.glyphcount * GF.rowbytes);
1083     + GF.glyphs = GF.mem1;
1084     + for (i = 0; i < GF.glyphcount; i++) {
1085     + memcpy(&(GF.glyphs[i * GF.height * GF.rowbytes]),
1086     + &(fo.data[i * 32 * GF.rowbytes]),
1087     + GF.height * GF.rowbytes);
1088     + }
1089     + if (fo.data) free(fo.data);
1090     +#else // KDFONTOP / GIO_FONTX
1091     + struct consolefontdesc cfd;
1092     + int j;
1093     + fd = open(CURRENT_TTY,O_NONBLOCK);
1094     + if (fd == -1) return;
1095     +
1096     + cfd.chardata = NULL;
1097     + cfd.charcount = 0;
1098     + cfd.charheight = 0;
1099     + if (ioctl(fd, GIO_FONTX, &cfd) == 0) {
1100     + cfd.chardata = xmalloc(cfd.charcount * 32);
1101     + if (ioctl(fd, GIO_FONTX, &cfd) == -1) {
1102     + free(cfd.chardata);
1103     + goto fb_vgafontout;
1104     + }
1105     + } else {
1106     + cfd.charcount=256;
1107     + cfd.chardata = xmalloc(256 * 32);
1108     + if (ioctl(fd, GIO_FONT, cfd.chardata) != 0) {
1109     + free(cfd.chardata);
1110     + goto fb_vgafontout;
1111     + }
1112     + // compute real height
1113     + cfd.charheight=0;
1114     + for (j = 31; (j > 0) && (cfd.charheight == 0); j--) {
1115     + for (i = 0; (i < 256) && (cfd.charheight == 0); i++) {
1116     + if (cfd.chardata[i*32+j] != 0)
1117     + cfd.charheight=j;
1118     + }
1119     + }
1120     + }
1121     + if (cfd.charheight != 0) {
1122     + if (G.font != NULL) fb_freefont();
1123     + G.font = (struct fbfont *) xzalloc(sizeof(struct fbfont));
1124     + GF.charsize = cfd.charheight;
1125     + GF.height = GF.charsize;
1126     + GF.glyphcount = cfd.charcount;
1127     + GF.width = 8;
1128     + GF.rowbytes = 1;
1129     + GF.mem1 = (uint8_t *) xmalloc(GF.height * GF.glyphcount);
1130     + GF.glyphs = GF.mem1;
1131     + // pack font
1132     + for (i = 0; i < GF.glyphcount; i++) {
1133     + memcpy(&(GF.glyphs[i * GF.height]),
1134     + &(cfd.chardata[i * 32]),
1135     + GF.height);
1136     + }
1137     + }
1138     + free(cfd.chardata);
1139     +#endif // FONTOP / FONTX
1140     +#if defined(GIO_UNIMAP)
1141     + GF.ud.entry_ct = 0;
1142     + ioctl(fd, GIO_UNIMAP, &(GF.ud));
1143     + if (errno != ENOMEM) {
1144     + goto fb_vgafontout;
1145     + }
1146     + if (GF.ud.entry_ct > 0) {
1147     + GF.ud.entries = xmalloc(GF.ud.entry_ct * sizeof(struct unipair));
1148     + if (ioctl(fd, GIO_UNIMAP, &(GF.ud)) == -1) {
1149     + // error no unimap
1150     + free(GF.ud.entries);
1151     + GF.ud.entry_ct = 0;
1152     + }
1153     + }
1154     +#endif // GIO_UNIMAP
1155     +fb_vgafontout:
1156     + close(fd);
1157     +#endif // GIO_FONTX or KDFONTOP available
1158     + return;
1159     +}
1160     +
1161     +#if ENABLE_FEATURE_FBSPLASH_FONTLOAD
1162     +
1163     +static uint16_t nextuni(int ver, uint8_t *map, int *pos) {
1164     + uint16_t rv;
1165     + int i;
1166     + i=*pos;
1167     + if (ver==1) {
1168     + rv = map[i + 1];
1169     + rv = (rv << 8) + map[i];
1170     + i += 2;
1171     + } else { // ver 2
1172     + if (map[i] == 0xFF) rv = 0xFFFF;
1173     + else if (map[i] == 0xFE) rv = 0xFFFE;
1174     + else if (map[i] < 0xC0) rv = map[i];
1175     + else if (map[i] < 0xE0) {
1176     + rv = map[i] & 0x1F;
1177     + if ((map[i + 1] & 0xC0) == 0x80)
1178     + rv = (rv << 6) + (map[++i] & 0x3F);
1179     + } else if (map[i] < 0xF0) {
1180     + rv = map[i] & 0x0F;
1181     + if ((map[i + 1] & 0xC0) == 0x80)
1182     + rv = (rv << 6) + (map[++i] & 0x3F);
1183     + if ((map[i + 1] & 0xC0) == 0x80)
1184     + rv = (rv << 6) + (map[++i] & 0x3F);
1185     + } else rv = map[i];
1186     + i++;
1187     + }
1188     + *pos=i;
1189     + return rv;
1190     +}
1191     +
1192     +/**
1193     + * Convert unimap from psf v1 and psf v2 to unimapdesc
1194     + */
1195     +static void convertmap(int ver, uint8_t *map, int mapsize, struct unimapdesc *ud) {
1196     + int i,j,k,glyph,glycodes;
1197     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
1198     + int l, seqlen=0, *seq=NULL;
1199     +#endif
1200     + uint16_t e;
1201     + ud->entry_ct=0;
1202     + for (i = 0, glycodes=0; i < mapsize; ) {
1203     + e = nextuni(ver, map, &i);
1204     + if (e == PSF1_STARTSEQ) {
1205     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
1206     + seqlen++;
1207     +#endif
1208     + e = nextuni(ver, map, &i);
1209     + while ((e != PSF1_SEPARATOR) && (i < mapsize)) {
1210     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
1211     + ud->entry_ct += glycodes;
1212     +#endif
1213     + e = nextuni(ver, map, &i);
1214     + }
1215     + glycodes=0;
1216     + } else if (e == PSF1_SEPARATOR) {
1217     + ud->entry_ct += glycodes;
1218     + glycodes=0;
1219     + } else {
1220     + glycodes++;
1221     + }
1222     + }
1223     + ud->entries = (struct unipair *)
1224     + xmalloc(sizeof(struct unimapdesc) * ud->entry_ct);
1225     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
1226     + if (seqlen > 0) {
1227     + seq = xzalloc(sizeof(int) * (seqlen + 1));
1228     + }
1229     +#endif
1230     + for (i = 0, glyph = 0, j = 0, k = 0; i < mapsize; ) {
1231     + e = nextuni(ver, map, &i);
1232     + if (e == PSF1_STARTSEQ) {
1233     + e = nextuni(ver, map, &i);
1234     + k++; // this is seqence - position saved
1235     + // remove sequence - this is not glyph
1236     + while (ud->entries[j-1].fontpos == glyph && j > 0) {
1237     + j--;
1238     + }
1239     + // skip chars in seq
1240     + while ((e != PSF1_SEPARATOR) && (i < mapsize)) {
1241     + e = nextuni(ver, map, &i);
1242     + }
1243     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
1244     + if (k < seqlen) seq[k] = i;
1245     +#endif
1246     + } else if (e == PSF1_SEPARATOR) {
1247     + glyph++;
1248     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
1249     + // next may be sequence
1250     + if (k < seqlen) seq[k] = i;
1251     +#endif
1252     + } else if (j < ud->entry_ct) {
1253     + ud->entries[j].unicode=e;
1254     + ud->entries[j++].fontpos=glyph;
1255     + }
1256     + }
1257     +#if ENABLE_FEATURE_FBSPLASH_PSFSEQS
1258     + i = 0;
1259     + while (i < seqlen) {
1260     + k = seq[i];
1261     + do {
1262     + e = nextuni(ver, map, &k);
1263     + } while (e != PSF1_STARTSEQ && e != PSF1_SEPARATOR && k < mapsize);
1264     + if (e == PSF1_STARTSEQ) {
1265     + e = nextuni(ver, map, &k);
1266     + while ((e != PSF1_SEPARATOR) && (k < mapsize)) {
1267     + // find glyph in table
1268     + glyph = 0;
1269     + while ((glyph < j) && (ud->entries[glyph].unicode != e)) {
1270     + glyph++;
1271     + }
1272     + // write glyph to table for all chars
1273     + if (glyph < j) { // found
1274     + l = seq[i]; // code pointer
1275     + e = nextuni(ver, map, &l);
1276     + while(e != PSF1_STARTSEQ && l < mapsize) {
1277     + ud->entries[j].unicode=e;
1278     + ud->entries[j++].fontpos=ud->entries[glyph].fontpos;
1279     + e = nextuni(ver, map, &l);
1280     + }
1281     + }
1282     + e = nextuni(ver, map, &k);
1283     + }
1284     + }
1285     + i++;
1286     + }
1287     + if (seqlen > 0) {
1288     + // remove unfound glyphs if any
1289     + ud->entry_ct = j;
1290     + free(seq);
1291     + }
1292     +#endif
1293     +}
1294     +
1295     +/**
1296     + * Read PSF v1 and PSF v2 fonts to own font structure
1297     + */
1298     +static void fb_readpsf(const char *filename) {
1299     + unsigned int len;
1300     + int maplen;
1301     + uint8_t *buf;
1302     + struct psf1_header *psf1;
1303     + struct psf2_header *psf2;
1304     +
1305     + if (G.font != NULL) fb_freefont();
1306     + len = 48*1024; // can't be larger
1307     + buf = xmalloc_open_zipped_read_close(filename, &len);
1308     + if (buf == NULL) {
1309     + bb_simple_perror_msg_and_die(filename);
1310     + }
1311     + if (len < 1024) {
1312     + goto badfmt;
1313     + }
1314     + G.font = (struct fbfont *) xzalloc(sizeof(struct fbfont));
1315     + GF.mem1 = buf;
1316     + psf1 = (struct psf1_header *)buf;
1317     + psf2 = (struct psf2_header *)buf;
1318     + if ((psf1->magic == PSF1_MAGIC) && (psf1->mode <= PSF1_MAXMODE)) {
1319     + GF.glyphs = &(buf[sizeof(struct psf1_header)]);
1320     + GF.charsize = psf1->charsize;
1321     + GF.height = GF.charsize;
1322     + GF.glyphcount = ((psf1->mode & PSF1_MODE512) ? 512 : 256);
1323     + GF.width = 8;
1324     + maplen = len - sizeof(struct psf1_header) -
1325     + (GF.charsize * GF.glyphcount);
1326     + if ((maplen > 0) && ((psf1->mode & PSF1_MODEHASTAB) != 0)) {
1327     + convertmap(1,&(buf[len - maplen]),maplen,&(GF.ud));
1328     + } else {
1329     + if (maplen < 0) goto badfmt;
1330     + }
1331     + } else if ((psf2->magic == PSF2_MAGIC) &&
1332     + (psf2->version <= PSF2_MAXVERSION)) {
1333     + GF.glyphs=&(buf[psf2->headersize]);
1334     + GF.height = psf2->height;
1335     + GF.width = psf2->width;
1336     + GF.glyphcount = psf2->length;
1337     + GF.charsize = psf2->charsize;
1338     + maplen = len - psf2->headersize -
1339     + (GF.charsize * GF.glyphcount);
1340     + if ((maplen > 0) && ((psf2->flags & PSF2_HAS_UNICODE_TABLE) != 0)) {
1341     + convertmap(2,&(buf[len - maplen]),maplen,&(GF.ud));
1342     + } else {
1343     + if (maplen < 0) goto badfmt;
1344     + }
1345     + } else {
1346     + goto badfmt;
1347     + }
1348     + GF.rowbytes = GF.charsize / GF.height;
1349     +
1350     + return;
1351     +badfmt:
1352     + if (G.font) fb_freefont();
1353     + bb_error_msg_and_die("Cannot read file %s - unrecognized format\n",filename);
1354     +}
1355     +#endif // FONTLOAD
1356     +#endif // TEXT
1357    
1358     /**
1359     * Parse configuration file
1360     @@ -347,6 +1190,9 @@
1361     "BAR_WIDTH\0" "BAR_HEIGHT\0"
1362     "BAR_LEFT\0" "BAR_TOP\0"
1363     "BAR_R\0" "BAR_G\0" "BAR_B\0"
1364     +#if ENABLE_FEATURE_FBSPLASH_TEXT
1365     + "TEXT_LEFT\0" "TEXT_TOP\0" "TEXT_R\0" "TEXT_G\0" "TEXT_B\0" "TEXT_SIZE\0"
1366     +#endif
1367     #if DEBUG
1368     "DEBUG\0"
1369     #endif
1370     @@ -354,15 +1200,15 @@
1371     char *token[2];
1372     parser_t *parser = config_open2(cfg_filename, xfopen_stdin);
1373     while (config_read(parser, token, 2, 2, "#=",
1374     - (PARSE_NORMAL | PARSE_MIN_DIE) & ~(PARSE_TRIM | PARSE_COLLAPSE))) {
1375     + (PARSE_NORMAL | PARSE_MIN_DIE) & ~(PARSE_TRIM | PARSE_COLLAPSE))) {
1376     unsigned val = xatoi_positive(token[1]);
1377     int i = index_in_strings(param_names, token[0]);
1378     if (i < 0)
1379     bb_error_msg_and_die("syntax error: %s", token[0]);
1380     - if (i >= 0 && i < 7)
1381     + if (i >= 0 && i < FBCFGVALS)
1382     G.ns[i] = val;
1383     #if DEBUG
1384     - if (i == 7) {
1385     + if (i == FBCFGVALS) {
1386     G.bdebug_messages = val;
1387     if (G.bdebug_messages)
1388     G.logfile_fd = xfopen_for_write("/tmp/fbsplash.log");
1389     @@ -376,11 +1222,24 @@
1390     int fbsplash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1391     int fbsplash_main(int argc UNUSED_PARAM, char **argv)
1392     {
1393     +#if ENABLE_FEATURE_FBSPLASH_FONTLOAD
1394     + const char *fontmap_filename = NULL;
1395     +#endif
1396     const char *fb_device, *cfg_filename, *fifo_filename;
1397     - FILE *fp = fp; // for compiler
1398     - char *num_buf;
1399     - unsigned num;
1400     + char num_buf[512];
1401     + int num;
1402     bool bCursorOff;
1403     + struct timeval tim;
1404     + fd_set rdfds;
1405     + FILE *fp=fp;
1406     + int bounce_x=0;
1407     +#if ENABLE_FEATURE_FBSPLASH_SPRITES
1408     + int anim_x,anim_y, /* position of sprite or animation */
1409     + anim_n,anim_m, /* min sprite, max sprite for animation */
1410     + anim_p=0, /* actual sprite */
1411     + anim_t=0,anim_now=0; /* time between steps */
1412     + struct sprite *spa=NULL;
1413     +#endif
1414    
1415     INIT_G();
1416    
1417     @@ -388,9 +1247,19 @@
1418     fb_device = "/dev/fb0";
1419     cfg_filename = NULL;
1420     fifo_filename = NULL;
1421     +
1422     +#if ENABLE_FEATURE_FBSPLASH_FONTLOAD
1423     + bCursorOff = 1 & getopt32(argv, "cs:d:i:f:m:",
1424     + &G.image_filename, &fb_device, &cfg_filename, &fifo_filename, &fontmap_filename);
1425     +
1426     + if (fontmap_filename) fb_readpsf(fontmap_filename);
1427     +#else
1428     bCursorOff = 1 & getopt32(argv, "cs:d:i:f:",
1429     &G.image_filename, &fb_device, &cfg_filename, &fifo_filename);
1430     -
1431     +#endif
1432     +#if ENABLE_FEATURE_FBSPLASH_TEXT
1433     + if (G.font==NULL) fb_readvgafont();
1434     +#endif
1435     // parse configuration file
1436     if (cfg_filename)
1437     init(cfg_filename);
1438     @@ -406,8 +1275,20 @@
1439     full_write(STDOUT_FILENO, "\033[?25l", 6);
1440     }
1441    
1442     + if (fifo_filename != NULL) {
1443     + G.spb2 = fb_newsprite(G.nbar_width, G.nbar_height, -1, -1);
1444     + }
1445     +
1446     fb_drawimage();
1447    
1448     + G.spb1 = fb_newsprite(G.nbar_width, G.nbar_height, G.nbar_posx, G.nbar_posy);
1449     +#if ENABLE_FEATURE_FBSPLASH_TEXT
1450     + if (G.font != NULL)
1451     + G.spt = fb_newsprite(G.scr_var.xres - G.text_posx,
1452     + GF.height * G.text_size,
1453     + G.text_posx, G.text_posy);
1454     +#endif
1455     +
1456     if (!fifo_filename)
1457     return EXIT_SUCCESS;
1458    
1459     @@ -424,31 +1305,137 @@
1460     // when last writer closes input end.
1461     // The simplest way is to open fifo for writing too
1462     // and become an additional writer :)
1463     - open(fifo_filename, O_WRONLY); // errors are ignored
1464     + open(fifo_filename, O_WRONLY | O_NDELAY); // errors are ignored
1465     }
1466    
1467     - fb_drawprogressbar(0);
1468     // Block on read, waiting for some input.
1469     // Use of <stdio.h> style I/O allows to correctly
1470     // handle a case when we have many buffered lines
1471     // already in the pipe
1472     - while ((num_buf = xmalloc_fgetline(fp)) != NULL) {
1473     - if (strncmp(num_buf, "exit", 4) == 0) {
1474     - DEBUG_MESSAGE("exit");
1475     - break;
1476     - }
1477     - num = atoi(num_buf);
1478     - if (isdigit(num_buf[0]) && (num <= 100)) {
1479     + // select and fgets work just in time only in nobuf mode
1480     + setvbuf(fp, NULL, _IONBF, 0);
1481     + tim.tv_sec = 0;
1482     + tim.tv_usec = 100000;
1483     + while (1) {
1484     + FD_ZERO(&rdfds);
1485     + FD_SET(fileno(fp),&rdfds);
1486     + if ((num=select(fileno(fp) + 1,&rdfds,NULL,NULL,&tim))==-1)
1487     + break; // select error
1488     + if (num != 0 && fgets(num_buf,sizeof(num_buf) - 1,fp) != NULL) {
1489     + num_buf[sizeof(num_buf) - 1]=0;
1490     + num=strlen(num_buf) - 1;
1491     + if (num >= 0 && num_buf[num]==10) num_buf[num]=0;
1492     + if (strncmp(num_buf, "exit", 4) == 0) {
1493     + DEBUG_MESSAGE("exit");
1494     + break;
1495     + } else if (strncmp(num_buf, "bounce", 6) == 0) {
1496     + bounce_x = 0;
1497     +#if ENABLE_FEATURE_FBSPLASH_TEXT
1498     + } else if (strncmp(num_buf, "write:", 6) == 0) {
1499     + if (G.font!=NULL) fb_drawstring(num_buf + 6);
1500     + DEBUG_MESSAGE(num_buf);
1501     +#endif
1502     +#if ENABLE_FEATURE_FBSPLASH_SPRITES
1503     + } else if (strncmp(num_buf, "load:", 5) == 0) {
1504     + if (spa) {
1505     + fb_putanim(anim_x,anim_y,0,spa); // hide old
1506     + free(spa);
1507     + spa=NULL;
1508     + }
1509     + if (sscanf(&(num_buf[5]),"%d:%d:",
1510     + &anim_x,&anim_y) == 2) {
1511     + // skip x:y
1512     + for (num=5;num_buf[num] != ':';) num++;
1513     + for (num++;num_buf[num] != ':';) num++;
1514     + spa=fb_loadsprites(&(num_buf[num + 1]),anim_x,anim_y);
1515     + anim_t = anim_now = 0; // stop animation
1516     + }
1517     + } else if (strncmp(num_buf, "sprite:", 7) == 0) {
1518     + if (spa != NULL) {
1519     + // "sprite:n"
1520     + anim_t = anim_now = 0; // stop animation
1521     + anim_p = atoi(&(num_buf[7]));
1522     + if (anim_p >= 0) {
1523     + fb_putanim(anim_x,anim_y,anim_p,spa);
1524     + }
1525     + }
1526     + } else if (strncmp(num_buf, "anime:", 6) == 0) {
1527     + if (spa != NULL) {
1528     + // "anime:n:m:t"
1529     + if ((sscanf(&(num_buf[6]),"%d:%d:%d",
1530     + &anim_n,&anim_m,&anim_t) == 3) &&
1531     + (anim_n >= 0) && (anim_m >= 0)) {
1532     + anim_p = anim_n; // first frame
1533     + fb_putanim(anim_x,anim_y,anim_p,spa);
1534     + anim_now = anim_t; // next sprite after time t
1535     + } else {
1536     + anim_now = anim_t = 0; // stop animation
1537     + }
1538     + }
1539     +#endif
1540     + } else {
1541     + num = atoi(num_buf);
1542     + if ((isdigit(num_buf[0]) || (num_buf[0]=='-')) &&
1543     + (num >= -100 && num <= 100)) {
1544     #if DEBUG
1545     - DEBUG_MESSAGE(itoa(num));
1546     + char strVal[10];
1547     + sprintf(strVal, "%d", num);
1548     + DEBUG_MESSAGE(strVal);
1549     +#endif
1550     + if (num < 0) {
1551     + fb_drawnbar(-1 * num,100);
1552     + } else {
1553     + fb_drawnbar(0,num);
1554     + }
1555     + bounce_x = -1; // stop bounce
1556     + }
1557     + }
1558     + } else {
1559     + if (fp == stdin && feof(fp)) break; // stdin closed END
1560     + }
1561     + if (tim.tv_usec == 0) { // timeout - anime
1562     + tim.tv_usec = 100000;
1563     + if (bounce_x >= 0) {
1564     + bounce_x += 5;
1565     + if (bounce_x > 160) bounce_x = 0;
1566     + if (bounce_x > 80)
1567     + fb_drawnbar(160 - bounce_x,180 - bounce_x);
1568     + else
1569     + fb_drawnbar(bounce_x, bounce_x + 20);
1570     + }
1571     +#if ENABLE_FEATURE_FBSPLASH_SPRITES
1572     + if (spa != NULL && anim_t != 0) {
1573     + --anim_now;
1574     + if (anim_now <= 0) {
1575     + anim_now = anim_t; // wait
1576     + if (anim_n < anim_m) {
1577     + anim_p++;
1578     + if (anim_p > anim_m) anim_p = anim_n;
1579     + } else {
1580     + anim_p--;
1581     + if (anim_p < anim_m) anim_p = anim_n;
1582     + }
1583     + fb_putanim(anim_x,anim_y,anim_p,spa);
1584     + }
1585     + }
1586     #endif
1587     - fb_drawprogressbar(num);
1588     }
1589     - free(num_buf);
1590     }
1591     -
1592     + if (G.spb1 != NULL) free(G.spb1);
1593     + G.spb1 = NULL;
1594     + if (G.spb2 != NULL) free(G.spb2);
1595     + G.spb2 = NULL;
1596     +#if ENABLE_FEATURE_FBSPLASH_TEXT
1597     + if (G.font != NULL) fb_freefont();
1598     + if (G.spt != NULL) free(G.spt);
1599     + G.spt = NULL;
1600     +#endif
1601     +#if ENABLE_FEATURE_FBSPLASH_SPRITES
1602     + if (spa != NULL) free(spa);
1603     +#endif
1604     if (bCursorOff) // restore cursor
1605     full_write(STDOUT_FILENO, "\033[?25h", 6);
1606    
1607     return EXIT_SUCCESS;
1608     }
1609     +#endif
1610     diff -Naur busybox-1.19.0/miscutils/fbsplash.cfg busybox-1.19.0-magellan/miscutils/fbsplash.cfg
1611     --- busybox-1.19.0/miscutils/fbsplash.cfg 2011-08-11 02:23:58.000000000 +0200
1612     +++ busybox-1.19.0-magellan/miscutils/fbsplash.cfg 2011-09-05 21:00:28.000000000 +0200
1613     @@ -7,3 +7,13 @@
1614     BAR_R=80
1615     BAR_G=80
1616     BAR_B=130
1617     +# the below settings are active only if you enable the option FBSPLASH_TEXT_RENDERING
1618     +# text position
1619     +#TEXT_LEFT=100
1620     +#TEXT_TOP=350
1621     +## text color
1622     +#TEXT_R=80
1623     +#TEXT_G=80
1624     +#TEXT_B=130
1625     +## text size (1 to 4)
1626     +#TEXT_SIZE=2