Commit 1a3cb4ad649607aa8bf1df33a4ce7f5b9e0a5e59
Committed by
Wolfgang Denk
1 parent
feb12a1f6d
Exists in
master
and in
54 other branches
easylogo: add lzma support
Compressing the logos with lzma rather than gzip saves ~9kb with the Blackfin 24bit images and ~3kb with the 16bit images. Add a new -l option to easylogo so people can pick lzma as their decompression routine. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Showing 1 changed file with 56 additions and 29 deletions Side-by-side Diff
tools/easylogo/easylogo.c
... | ... | @@ -305,7 +305,13 @@ |
305 | 305 | return 0; |
306 | 306 | } |
307 | 307 | |
308 | -int use_gzip = 0; | |
308 | +enum comp_t { | |
309 | + COMP_NONE, | |
310 | + COMP_GZIP, | |
311 | + COMP_LZMA, | |
312 | +}; | |
313 | +static enum comp_t compression = COMP_NONE; | |
314 | +static bool bss_storage = false; | |
309 | 315 | |
310 | 316 | int image_save_header (image_t * image, char *filename, char *varname) |
311 | 317 | { |
312 | 318 | |
313 | 319 | |
314 | 320 | |
315 | 321 | |
316 | 322 | |
317 | 323 | |
318 | 324 | |
319 | 325 | |
320 | 326 | |
321 | 327 | |
322 | 328 | |
323 | 329 | |
... | ... | @@ -329,58 +335,74 @@ |
329 | 335 | fprintf (file, " *\t\t'x'\t\tis the horizontal position\n"); |
330 | 336 | fprintf (file, " *\t\t'y'\t\tis the vertical position\n */\n\n"); |
331 | 337 | |
332 | - /* gzip compress */ | |
333 | - if (use_gzip & 0x1) { | |
338 | + /* image compress */ | |
339 | + if (compression != COMP_NONE) { | |
334 | 340 | const char *errstr = NULL; |
335 | 341 | unsigned char *compressed; |
342 | + const char *comp_name; | |
336 | 343 | struct stat st; |
337 | - FILE *gz; | |
338 | - char *gzfilename = xmalloc(strlen (filename) + 20); | |
339 | - char *gzcmd = xmalloc(strlen (filename) + 20); | |
344 | + FILE *compfp; | |
345 | + size_t filename_len = strlen(filename); | |
346 | + char *compfilename = xmalloc(filename_len + 20); | |
347 | + char *compcmd = xmalloc(filename_len + 50); | |
340 | 348 | |
341 | - sprintf (gzfilename, "%s.gz", filename); | |
342 | - sprintf (gzcmd, "gzip > %s", gzfilename); | |
343 | - gz = popen (gzcmd, "w"); | |
344 | - if (!gz) { | |
349 | + sprintf(compfilename, "%s.bin", filename); | |
350 | + switch (compression) { | |
351 | + case COMP_GZIP: | |
352 | + strcpy(compcmd, "gzip"); | |
353 | + comp_name = "GZIP"; | |
354 | + break; | |
355 | + case COMP_LZMA: | |
356 | + strcpy(compcmd, "lzma"); | |
357 | + comp_name = "LZMA"; | |
358 | + break; | |
359 | + default: | |
360 | + errstr = "\nerror: unknown compression method"; | |
361 | + goto done; | |
362 | + } | |
363 | + strcat(compcmd, " > "); | |
364 | + strcat(compcmd, compfilename); | |
365 | + compfp = popen(compcmd, "w"); | |
366 | + if (!compfp) { | |
345 | 367 | errstr = "\nerror: popen() failed"; |
346 | 368 | goto done; |
347 | 369 | } |
348 | - if (fwrite (image->data, image->size, 1, gz) != 1) { | |
370 | + if (fwrite(image->data, image->size, 1, compfp) != 1) { | |
349 | 371 | errstr = "\nerror: writing data to gzip failed"; |
350 | 372 | goto done; |
351 | 373 | } |
352 | - if (pclose (gz)) { | |
374 | + if (pclose(compfp)) { | |
353 | 375 | errstr = "\nerror: gzip process failed"; |
354 | 376 | goto done; |
355 | 377 | } |
356 | 378 | |
357 | - gz = fopen (gzfilename, "r"); | |
358 | - if (!gz) { | |
379 | + compfp = fopen(compfilename, "r"); | |
380 | + if (!compfp) { | |
359 | 381 | errstr = "\nerror: open() on gzip data failed"; |
360 | 382 | goto done; |
361 | 383 | } |
362 | - if (stat (gzfilename, &st)) { | |
384 | + if (stat(compfilename, &st)) { | |
363 | 385 | errstr = "\nerror: stat() on gzip file failed"; |
364 | 386 | goto done; |
365 | 387 | } |
366 | - compressed = xmalloc (st.st_size); | |
367 | - if (fread (compressed, st.st_size, 1, gz) != 1) { | |
388 | + compressed = xmalloc(st.st_size); | |
389 | + if (fread(compressed, st.st_size, 1, compfp) != 1) { | |
368 | 390 | errstr = "\nerror: reading gzip data failed"; |
369 | 391 | goto done; |
370 | 392 | } |
371 | - fclose (gz); | |
393 | + fclose(compfp); | |
372 | 394 | |
373 | - unlink (gzfilename); | |
395 | + unlink(compfilename); | |
374 | 396 | |
375 | 397 | dataptr = compressed; |
376 | 398 | count = st.st_size; |
377 | - fprintf (file, "#define EASYLOGO_ENABLE_GZIP %i\n\n", count); | |
378 | - if (use_gzip & 0x2) | |
399 | + fprintf(file, "#define EASYLOGO_ENABLE_%s %i\n\n", comp_name, count); | |
400 | + if (bss_storage) | |
379 | 401 | fprintf (file, "static unsigned char EASYLOGO_DECOMP_BUFFER[%i];\n\n", image->size); |
380 | 402 | |
381 | 403 | done: |
382 | - free (gzfilename); | |
383 | - free (gzcmd); | |
404 | + free(compfilename); | |
405 | + free(compcmd); | |
384 | 406 | |
385 | 407 | if (errstr) { |
386 | 408 | perror (errstr); |
... | ... | @@ -466,6 +488,7 @@ |
466 | 488 | " -r Output RGB888 instead of YUYV\n" |
467 | 489 | " -s Output RGB565 instead of YUYV\n" |
468 | 490 | " -g Compress with gzip\n" |
491 | + " -l Compress with lzma\n" | |
469 | 492 | " -b Preallocate space in bss for decompressing image\n" |
470 | 493 | " -h Help output\n" |
471 | 494 | "\n" |
... | ... | @@ -486,7 +509,7 @@ |
486 | 509 | |
487 | 510 | image_t rgb888_logo, rgb565_logo, yuyv_logo; |
488 | 511 | |
489 | - while ((c = getopt(argc, argv, "hrsgb")) > 0) { | |
512 | + while ((c = getopt(argc, argv, "hrsglb")) > 0) { | |
490 | 513 | switch (c) { |
491 | 514 | case 'h': |
492 | 515 | usage (0); |
493 | 516 | |
494 | 517 | |
... | ... | @@ -500,12 +523,16 @@ |
500 | 523 | puts("Using 16-bit RGB565 Output Fromat"); |
501 | 524 | break; |
502 | 525 | case 'g': |
503 | - use_gzip |= 0x1; | |
504 | - puts ("Compressing with gzip"); | |
526 | + compression = COMP_GZIP; | |
527 | + puts("Compressing with gzip"); | |
505 | 528 | break; |
529 | + case 'l': | |
530 | + compression = COMP_LZMA; | |
531 | + puts("Compressing with lzma"); | |
532 | + break; | |
506 | 533 | case 'b': |
507 | - use_gzip |= 0x2; | |
508 | - puts ("Preallocating bss space for decompressing image"); | |
534 | + bss_storage = true; | |
535 | + puts("Preallocating bss space for decompressing image"); | |
509 | 536 | break; |
510 | 537 | default: |
511 | 538 | usage (1); |