diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bmp2rb.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/tools/bmp2rb.c b/tools/bmp2rb.c index f9f554a304..7fee1e6177 100644 --- a/tools/bmp2rb.c +++ b/tools/bmp2rb.c | |||
@@ -453,19 +453,21 @@ int transform_bitmap(const struct RGBQUAD *src, int width, int height, | |||
453 | 453 | ||
454 | void generate_c_source(char *id, char* header_dir, int width, int height, | 454 | void generate_c_source(char *id, char* header_dir, int width, int height, |
455 | const unsigned short *t_bitmap, int t_width, | 455 | const unsigned short *t_bitmap, int t_width, |
456 | int t_height, int t_depth) | 456 | int t_height, int t_depth, bool t_mono, bool create_bm) |
457 | { | 457 | { |
458 | FILE *f; | 458 | FILE *f; |
459 | FILE *fh; | 459 | FILE *fh; |
460 | int i, a; | 460 | int i, a; |
461 | char header_name[1024]; | 461 | char header_name[1024]; |
462 | bool have_header = header_dir && header_dir[0]; | ||
463 | create_bm = have_header && create_bm; | ||
462 | 464 | ||
463 | if (!id || !id[0]) | 465 | if (!id || !id[0]) |
464 | id = "bitmap"; | 466 | id = "bitmap"; |
465 | 467 | ||
466 | f = stdout; | 468 | f = stdout; |
467 | 469 | ||
468 | if (header_dir && header_dir[0]) | 470 | if (have_header) |
469 | { | 471 | { |
470 | snprintf(header_name,sizeof(header_name),"%s/%s.h",header_dir,id); | 472 | snprintf(header_name,sizeof(header_name),"%s/%s.h",header_dir,id); |
471 | fh = fopen(header_name,"w+"); | 473 | fh = fopen(header_name,"w+"); |
@@ -484,6 +486,11 @@ void generate_c_source(char *id, char* header_dir, int width, int height, | |||
484 | else | 486 | else |
485 | fprintf(fh, "extern const unsigned short %s[];\n", id); | 487 | fprintf(fh, "extern const unsigned short %s[];\n", id); |
486 | 488 | ||
489 | if (create_bm) | ||
490 | { | ||
491 | fprintf(f, "#include \"lcd.h\"\n"); | ||
492 | fprintf(fh, "extern const struct bitmap bm_%s;\n", id); | ||
493 | } | ||
487 | fclose(fh); | 494 | fclose(fh); |
488 | } else { | 495 | } else { |
489 | fprintf(f, | 496 | fprintf(f, |
@@ -492,6 +499,10 @@ void generate_c_source(char *id, char* header_dir, int width, int height, | |||
492 | id, height, id, width); | 499 | id, height, id, width); |
493 | } | 500 | } |
494 | 501 | ||
502 | if (create_bm) { | ||
503 | fprintf(f, "#include \"%s\"\n", header_name); | ||
504 | } | ||
505 | |||
495 | if (t_depth <= 8) | 506 | if (t_depth <= 8) |
496 | fprintf(f, "const unsigned char %s[] = {\n", id); | 507 | fprintf(f, "const unsigned char %s[] = {\n", id); |
497 | else | 508 | else |
@@ -511,7 +522,20 @@ void generate_c_source(char *id, char* header_dir, int width, int height, | |||
511 | fprintf(f, "\n"); | 522 | fprintf(f, "\n"); |
512 | } | 523 | } |
513 | 524 | ||
514 | fprintf(f, "\n};\n"); | 525 | fprintf(f, "\n};\n\n"); |
526 | |||
527 | if (create_bm) { | ||
528 | char format_line[] = " .format = FORMAT_NATIVE, \n"; | ||
529 | fprintf(f, "const struct bitmap bm_%s = { \n" | ||
530 | " .width = BMPWIDTH_%s, \n" | ||
531 | " .height = BMPHEIGHT_%s, \n" | ||
532 | "%s" | ||
533 | " .data = (unsigned char*)%s,\n" | ||
534 | "};\n", | ||
535 | id, id, id, | ||
536 | t_mono ? "" : format_line, | ||
537 | id); | ||
538 | } | ||
515 | } | 539 | } |
516 | 540 | ||
517 | void generate_raw_file(const unsigned short *t_bitmap, | 541 | void generate_raw_file(const unsigned short *t_bitmap, |
@@ -573,6 +597,7 @@ void print_usage(void) | |||
573 | "\t-i <id> Bitmap name (default is filename without extension)\n" | 597 | "\t-i <id> Bitmap name (default is filename without extension)\n" |
574 | "\t-h <dir> Create header file in <dir>/<id>.h\n" | 598 | "\t-h <dir> Create header file in <dir>/<id>.h\n" |
575 | "\t-a Show ascii picture of bitmap\n" | 599 | "\t-a Show ascii picture of bitmap\n" |
600 | "\t-b Create bitmap struct along with pixel array\n" | ||
576 | "\t-r Generate RAW file (little-endian)\n" | 601 | "\t-r Generate RAW file (little-endian)\n" |
577 | "\t-f <n> Generate destination format n, default = 0\n" | 602 | "\t-f <n> Generate destination format n, default = 0\n" |
578 | "\t 0 Archos recorder, Ondio, Iriver H1x0 mono\n" | 603 | "\t 0 Archos recorder, Ondio, Iriver H1x0 mono\n" |
@@ -601,6 +626,7 @@ int main(int argc, char **argv) | |||
601 | int width, height; | 626 | int width, height; |
602 | int t_width, t_height, t_depth; | 627 | int t_width, t_height, t_depth; |
603 | bool raw = false; | 628 | bool raw = false; |
629 | bool create_bm = false; | ||
604 | 630 | ||
605 | 631 | ||
606 | for (i = 1;i < argc;i++) | 632 | for (i = 1;i < argc;i++) |
@@ -647,6 +673,10 @@ int main(int argc, char **argv) | |||
647 | ascii = true; | 673 | ascii = true; |
648 | break; | 674 | break; |
649 | 675 | ||
676 | case 'b': | ||
677 | create_bm = true; | ||
678 | break; | ||
679 | |||
650 | case 'r': /* Raw File */ | 680 | case 'r': /* Raw File */ |
651 | raw = true; | 681 | raw = true; |
652 | break; | 682 | break; |
@@ -724,7 +754,8 @@ int main(int argc, char **argv) | |||
724 | generate_raw_file(t_bitmap, t_width, t_height, t_depth); | 754 | generate_raw_file(t_bitmap, t_width, t_height, t_depth); |
725 | else | 755 | else |
726 | generate_c_source(id, header_dir, width, height, t_bitmap, | 756 | generate_c_source(id, header_dir, width, height, t_bitmap, |
727 | t_width, t_height, t_depth); | 757 | t_width, t_height, t_depth, |
758 | format <= 1, create_bm); | ||
728 | } | 759 | } |
729 | 760 | ||
730 | return 0; | 761 | return 0; |