fbsplash: support configurable image position

For some setups (E.G. for supporting different screen resolutions),
positioning the image somewhere else than the top left corner may be
interesting.

Add support for IMG_LEFT/IMG_TOP settings to specify the image location,
similar to how it is done for the progress bar.

function                                             old     new   delta
fbsplash_main                                        994    1038     +44
static.param_names                                    57      74     +17
packed_usage                                       32631   32647     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 77/0)               Total: 77 bytes

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Peter Korsgaard 2018-03-29 13:35:01 +02:00 committed by Denys Vlasenko
parent 03fd7e06f8
commit a82fe671f5

View File

@ -54,7 +54,7 @@
//usage: "\n -d Framebuffer device (default /dev/fb0)" //usage: "\n -d Framebuffer device (default /dev/fb0)"
//usage: "\n -i Config file (var=value):" //usage: "\n -i Config file (var=value):"
//usage: "\n BAR_LEFT,BAR_TOP,BAR_WIDTH,BAR_HEIGHT" //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 -f Control pipe (else exit after drawing image)" //usage: "\n -f Control pipe (else exit after drawing image)"
//usage: "\n commands: 'NN' (% for progress bar) or 'exit'" //usage: "\n commands: 'NN' (% for progress bar) or 'exit'"
@ -73,7 +73,7 @@ struct globals {
FILE *logfile_fd; // log file FILE *logfile_fd; // log file
#endif #endif
unsigned char *addr; // pointer to framebuffer memory unsigned char *addr; // pointer to framebuffer memory
unsigned ns[7]; // n-parameters unsigned ns[9]; // n-parameters
const char *image_filename; const char *image_filename;
struct fb_var_screeninfo scr_var; struct fb_var_screeninfo scr_var;
struct fb_fix_screeninfo scr_fix; struct fb_fix_screeninfo scr_fix;
@ -95,6 +95,8 @@ struct globals {
#define nbar_colr ns[4] // progress bar color red component #define nbar_colr ns[4] // progress bar color red component
#define nbar_colg ns[5] // progress bar color green component #define nbar_colg ns[5] // progress bar color green component
#define nbar_colb ns[6] // progress bar color blue component #define nbar_colb ns[6] // progress bar color blue component
#define img_posx ns[7] // image horizontal position
#define img_posy ns[8] // image vertical position
#if DEBUG #if DEBUG
#define DEBUG_MESSAGE(strMessage, args...) \ #define DEBUG_MESSAGE(strMessage, args...) \
@ -426,10 +428,10 @@ static void fb_drawimage(void)
line_size = width*3; line_size = width*3;
pixline = xmalloc(line_size); pixline = xmalloc(line_size);
if (width > G.scr_var.xres) if ((width + G.img_posx) > G.scr_var.xres)
width = G.scr_var.xres; width = G.scr_var.xres - G.img_posx;
if (height > G.scr_var.yres) if ((height + G.img_posy) > G.scr_var.yres)
height = G.scr_var.yres; height = G.scr_var.yres - G.img_posy;
for (j = 0; j < height; j++) { for (j = 0; j < height; j++) {
unsigned char *pixel; unsigned char *pixel;
unsigned char *src; unsigned char *src;
@ -437,7 +439,7 @@ static void fb_drawimage(void)
if (fread(pixline, 1, line_size, theme_file) != line_size) if (fread(pixline, 1, line_size, theme_file) != line_size)
bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); bb_error_msg_and_die("bad PPM file '%s'", G.image_filename);
pixel = pixline; pixel = pixline;
src = G.addr + j * G.scr_fix.line_length; src = G.addr + (G.img_posy + j) * G.scr_fix.line_length + G.img_posx * G.bytes_per_pixel;
for (i = 0; i < width; i++) { for (i = 0; i < width; i++) {
unsigned thispix = fb_pixel_value(pixel[0], pixel[1], pixel[2]); unsigned thispix = fb_pixel_value(pixel[0], pixel[1], pixel[2]);
fb_write_pixel(src, thispix); fb_write_pixel(src, thispix);
@ -460,6 +462,7 @@ static void init(const char *cfg_filename)
"BAR_WIDTH\0" "BAR_HEIGHT\0" "BAR_WIDTH\0" "BAR_HEIGHT\0"
"BAR_LEFT\0" "BAR_TOP\0" "BAR_LEFT\0" "BAR_TOP\0"
"BAR_R\0" "BAR_G\0" "BAR_B\0" "BAR_R\0" "BAR_G\0" "BAR_B\0"
"IMG_LEFT\0" "IMG_TOP\0"
#if DEBUG #if DEBUG
"DEBUG\0" "DEBUG\0"
#endif #endif
@ -472,10 +475,10 @@ static void init(const char *cfg_filename)
int i = index_in_strings(param_names, token[0]); int i = index_in_strings(param_names, token[0]);
if (i < 0) if (i < 0)
bb_error_msg_and_die("syntax error: %s", token[0]); bb_error_msg_and_die("syntax error: %s", token[0]);
if (i >= 0 && i < 7) if (i >= 0 && i < 9)
G.ns[i] = val; G.ns[i] = val;
#if DEBUG #if DEBUG
if (i == 7) { if (i == 9) {
G.bdebug_messages = val; G.bdebug_messages = val;
if (G.bdebug_messages) if (G.bdebug_messages)
G.logfile_fd = xfopen_for_write("/tmp/fbsplash.log"); G.logfile_fd = xfopen_for_write("/tmp/fbsplash.log");