fbsplash: reinstate drawing of over/undersized images; shrink

Based on the patch by Nuno Lucas <ntlucas@gmail.com>

function                                             old     new   delta
fbsplash_main                                        938     864     -74

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2010-03-14 23:59:54 +01:00
parent 7cfec4b3e0
commit 814da220a5

View File

@ -121,7 +121,7 @@ static void fb_drawrectangle(void)
// vertical lines // vertical lines
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);
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);
cnt = G.nbar_height - 1 /* HUH?! G.nbar_posy + G.nbar_height - 1 - G.nbar_posy*/; cnt = G.nbar_height - 1;
do { do {
*ptr1 = thispix; ptr1 += G.scr_var.xres; *ptr1 = thispix; ptr1 += G.scr_var.xres;
*ptr2 = thispix; ptr2 += G.scr_var.xres; *ptr2 = thispix; ptr2 += G.scr_var.xres;
@ -216,70 +216,69 @@ static void fb_drawprogressbar(unsigned percent)
*/ */
static void fb_drawimage(void) static void fb_drawimage(void)
{ {
char *head, *ptr;
FILE *theme_file; FILE *theme_file;
char *read_ptr;
unsigned char *pixline; unsigned char *pixline;
unsigned i, j, width, height, line_size; unsigned i, j, width, height, line_size;
if (LONE_DASH(G.image_filename)) if (LONE_DASH(G.image_filename)) {
theme_file = stdin; theme_file = stdin;
else { } else {
int fd = open_zipped(G.image_filename); int fd = open_zipped(G.image_filename);
if (fd < 0) if (fd < 0)
bb_simple_perror_msg_and_die(G.image_filename); bb_simple_perror_msg_and_die(G.image_filename);
theme_file = xfdopen_for_read(fd); theme_file = xfdopen_for_read(fd);
} }
head = xmalloc(256);
/* parse ppm header /* Parse ppm header:
* - A ppm images magic number is the two characters "P6". * - Magic: two characters "P6".
* - Whitespace (blanks, TABs, CRs, LFs). * - Whitespace (blanks, TABs, CRs, LFs).
* - A width, formatted as ASCII characters in decimal. * - A width, formatted as ASCII characters in decimal.
* - Whitespace. * - Whitespace.
* - A height, again in ASCII decimal. * - A height, ASCII decimal.
* - Whitespace. * - Whitespace.
* - The maximum color value (Maxval), again in ASCII decimal. Must be * - The maximum color value, ASCII decimal, in 0..65535
* less than 65536.
* - Newline or other single whitespace character. * - Newline or other single whitespace character.
* (we support newline only)
* - A raster of Width * Height pixels in triplets of rgb * - A raster of Width * Height pixels in triplets of rgb
* in pure binary by 1 (or not implemented 2) bytes. * in pure binary by 1 or 2 bytes. (we support only 1 byte)
*/ */
#define concat_buf bb_common_bufsiz1
read_ptr = concat_buf;
while (1) { while (1) {
if (fgets(head, 256, theme_file) == NULL int w, h, max_color_val;
/* do not overrun the buffer */ int rem = concat_buf + sizeof(concat_buf) - read_ptr;
|| strlen(bb_common_bufsiz1) >= sizeof(bb_common_bufsiz1) - 256) if (rem < 2
|| fgets(read_ptr, rem, theme_file) == NULL
) {
bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); bb_error_msg_and_die("bad PPM file '%s'", G.image_filename);
}
ptr = memchr(skip_whitespace(head), '#', 256); read_ptr = strchrnul(read_ptr, '#');
if (ptr != NULL) *read_ptr = '\0'; /* ignore #comments */
*ptr = 0; /* ignore comments */ if (sscanf(concat_buf, "P6 %u %u %u", &w, &h, &max_color_val) == 3
strcat(bb_common_bufsiz1, head); && max_color_val <= 255
// width, height, max_color_val ) {
if (sscanf(bb_common_bufsiz1, "P6 %u %u %u", &width, &height, &i) == 3 width = w; /* w is on stack, width may be in register */
&& i <= 255) height = h;
break; break;
/* If we do not find a signature throughout the whole file then }
we will diagnose this via EOF on read in the head of the loop. */
} }
if (ENABLE_FEATURE_CLEAN_UP)
free(head);
if (width != G.scr_var.xres || height != G.scr_var.yres)
bb_error_msg_and_die("PPM %dx%d does not match screen %dx%d",
width, height, G.scr_var.xres, G.scr_var.yres);
line_size = width*3; line_size = width*3;
pixline = xmalloc(line_size);
if (width > G.scr_var.xres) if (width > G.scr_var.xres)
width = G.scr_var.xres; width = G.scr_var.xres;
if (height > G.scr_var.yres) if (height > G.scr_var.yres)
height = G.scr_var.yres; height = G.scr_var.yres;
pixline = xmalloc(line_size);
for (j = 0; j < height; j++) { for (j = 0; j < height; j++) {
unsigned char *pixel = pixline; unsigned char *pixel;
DATA *src = (DATA *)(G.addr + j * G.scr_fix.line_length); DATA *src;
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;
src = (DATA *)(G.addr + j * G.scr_fix.line_length);
for (i = 0; i < width; i++) { for (i = 0; i < width; i++) {
unsigned thispix; unsigned thispix;
thispix = (((unsigned)pixel[0] << 8) & 0xf800) thispix = (((unsigned)pixel[0] << 8) & 0xf800)
@ -289,7 +288,6 @@ static void fb_drawimage(void)
pixel += 3; pixel += 3;
} }
} }
if (ENABLE_FEATURE_CLEAN_UP)
free(pixline); free(pixline);
fclose(theme_file); fclose(theme_file);
} }