Am 01.10.2016 um 13:26 schrieb Mattias Schlenker:

Hi everyone,

I maintain a few (commercial) live distributions and have to fulfil the need of a few customers for a nice graphical boot splash. Unfortunately busybox' fbsplash was too unflexible, so I added a bit more configurability:

  * Specify a background color which is used to flood the whole screen
    before drawing the image and the progress bar
  * Specify an x and y offset of the ppm image
  * Specify an x or y offset larger than the respective screen size to
    move the image to the right or bottom edge of the screen (or
    bottom right corner)

The attached patch just re-uses functions already in fbsplash.c and introduces five more config options, this should result in the same size of the busybox binary. Even if these config options are not set, the screen is blanked all black before painting the splash, which might be desired in most cases (and usually is done by using fullscreen images).

With the patch I am able to calculate the position of logo and progress bar by a script before invoking fbsplash and do not have to add a splash for each and every screen resolution. Initially I was thinking about adding more options: color of progess bar and the posibility to specify a gradient, but this might have enlarged the binary which is not desirable.

I just updated the patch: The calculation for cropping the image was wrong, the parameter name "IMAGE_WIDTH" proved too long on 32 bit systems and I added a "NOFILL=1" option. This option allows drawing an arbitary image to an arbitary position without completely wiping the framebuffer first. Take a look at the demo script (run with the path to your busybox binary) as first parameter: The scripts reads the framebuffer dimensions, creates two config files, paints an image on a plain background, progress bar and changing icon beneath the progress bar.

The demo script: http://distfiles.lesslinux.org/fbsplash_demo.tar.gz

The patch is attached.

Yours,
Mattias


--
Mattias Schlenker - Freier IT-Fachredakteur und -autor
                             redakt...@mattiasschlenker.de
Mattias Schlenker - IT-Consulting, Softwareentwicklung
                            consult...@mattiasschlenker.de

Address__ August-Bebel-Str. 74 - D-04275 LEIPZIG - GERMANY
Phone: +49 341 39290767              Fax: +49 341 30393578
Mobile: +49 163  6953657  Another mobile: +49 159 03160327
VATIN_________________________________________ DE240998538

Fork me!____________________ https://github.com/mschlenker
Website.__________________ http://www.mattiasschlenker.de/
My books!___________ http://www.arduino-hausautomation.de/

diff -ruN busybox-1.25.0/miscutils/fbsplash.c busybox-1.25.0.mod/miscutils/fbsplash.c
--- busybox-1.25.0/miscutils/fbsplash.c	2016-05-26 19:42:44.000000000 +0200
+++ busybox-1.25.0.mod/miscutils/fbsplash.c	2016-10-03 12:01:26.611456712 +0200
@@ -29,7 +29,8 @@
 //usage:     "\n	-d	Framebuffer device (default /dev/fb0)"
 //usage:     "\n	-i	Config file (var=value):"
 //usage:     "\n			BAR_LEFT,BAR_TOP,BAR_WIDTH,BAR_HEIGHT"
-//usage:     "\n			BAR_R,BAR_G,BAR_B"
+//usage:     "\n			BAR_R,BAR_G,BAR_B,IMG_LEFT,IMG_TOP"
+//usage:     "\n                        BG_R,BG_G,BG_B,NOFILL"
 //usage:     "\n	-f	Control pipe (else exit after drawing image)"
 //usage:     "\n			commands: 'NN' (% for progress bar) or 'exit'"
 
@@ -46,7 +47,7 @@
 	FILE *logfile_fd;	// log file
 #endif
 	unsigned char *addr;	// pointer to framebuffer memory
-	unsigned ns[7];		// n-parameters
+	unsigned ns[13];	// n-parameters
 	const char *image_filename;
 	struct fb_var_screeninfo scr_var;
 	struct fb_fix_screeninfo scr_fix;
@@ -68,6 +69,12 @@
 #define nbar_colr	ns[4]	// progress bar color red component
 #define nbar_colg	ns[5]	// progress bar color green component
 #define nbar_colb	ns[6]	// progress bar color blue component
+#define image_posx	ns[7]	// splash image horizontal position
+#define image_posy	ns[8]	// splash image verical position
+#define flood_colr	ns[9]	// background color red component
+#define flood_colg	ns[10]	// background color green component
+#define flood_colb	ns[11]	// background color blue component
+#define do_not_flood	ns[12]	// do not flood the whole screen with one color
 
 #if DEBUG
 #define DEBUG_MESSAGE(strMessage, args...) \
@@ -340,6 +347,14 @@
 			G.nbar_colr, G.nbar_colg, G.nbar_colb);
 }
 
+/**
+ * Flood the background with one color
+ */
+static void fb_colorfill(void)
+{
+	fb_drawfullrectangle(0, 0, G.scr_var.xres - 1, G.scr_var.yres - 1, 
+		G.flood_colr, G.flood_colg, G.flood_colb);
+}
 
 /**
  * Draw image from PPM file
@@ -398,11 +413,24 @@
 
 	line_size = width*3;
 	pixline = xmalloc(line_size);
-
+	
 	if (width > G.scr_var.xres)
 		width = G.scr_var.xres;
 	if (height > G.scr_var.yres)
 		height = G.scr_var.yres;
+	
+	/* specify a image position outside the visible area to position the splash
+	at the edge of the screen */
+	if (G.image_posx >= G.scr_var.xres)
+		G.image_posx = G.scr_var.xres - width;
+	if (G.image_posy >= G.scr_var.yres)
+		G.image_posy = G.scr_var.yres - height;
+	/* crop the image if upper left corner is within visible area */
+	if (G.image_posx + height > G.scr_var.xres)
+		width = width - ( G.image_posx + width - G.scr_var.xres );
+	if (G.image_posy + height > G.scr_var.yres)
+		height = height - ( G.image_posy + height - G.scr_var.yres );
+	
 	for (j = 0; j < height; j++) {
 		unsigned char *pixel;
 		unsigned char *src;
@@ -413,7 +441,8 @@
 		src = G.addr + j * G.scr_fix.line_length;
 		for (i = 0; i < width; i++) {
 			unsigned thispix = fb_pixel_value(pixel[0], pixel[1], pixel[2]);
-			fb_write_pixel(src, thispix);
+			fb_write_pixel(G.image_posy *  G.scr_fix.line_length + 
+				G.image_posx * G.bytes_per_pixel + src, thispix);
 			src += G.bytes_per_pixel;
 			pixel += 3;
 		}
@@ -433,6 +462,9 @@
 		"BAR_WIDTH\0" "BAR_HEIGHT\0"
 		"BAR_LEFT\0" "BAR_TOP\0"
 		"BAR_R\0" "BAR_G\0" "BAR_B\0"
+		"IMG_LEFT\0" "IMG_TOP\0"
+		"BG_R\0" "BG_G\0" "BG_B\0"
+		"NOFILL\0"
 #if DEBUG
 		"DEBUG\0"
 #endif
@@ -445,10 +477,10 @@
 		int i = index_in_strings(param_names, token[0]);
 		if (i < 0)
 			bb_error_msg_and_die("syntax error: %s", token[0]);
-		if (i >= 0 && i < 7)
+		if (i >= 0 && i < 13)
 			G.ns[i] = val;
 #if DEBUG
-		if (i == 7) {
+		if (i == 13) {
 			G.bdebug_messages = val;
 			if (G.bdebug_messages)
 				G.logfile_fd = xfopen_for_write("/tmp/fbsplash.log");
@@ -492,6 +524,9 @@
 		full_write(STDOUT_FILENO, "\033[?25l", 6);
 	}
 
+	if (G.do_not_flood < 1)
+		fb_colorfill(); 
+	
 	fb_drawimage();
 
 	if (!fifo_filename)
diff -ruN busybox-1.25.0/miscutils/fbsplash.cfg busybox-1.25.0.mod/miscutils/fbsplash.cfg
--- busybox-1.25.0/miscutils/fbsplash.cfg	2015-07-13 04:18:47.000000000 +0200
+++ busybox-1.25.0.mod/miscutils/fbsplash.cfg	2016-10-03 11:58:12.055738247 +0200
@@ -1,9 +1,18 @@
 # progress bar position
 BAR_LEFT=170
-BAR_TOP=300
+BAR_TOP=400
 BAR_WIDTH=300
 BAR_HEIGHT=20
 # progress bar color
 BAR_R=80
 BAR_G=80
 BAR_B=130
+# image position
+IMAGE_LEFT=100
+IMAGE_TOP=100
+# background
+BG_R=80
+BG_G=130
+BG_B=80
+# set greater than 0 to suppress filling the whole screen with one color
+NOFILL=0
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to