diff options
Diffstat (limited to 'tools/bmp2rb.c')
-rw-r--r-- | tools/bmp2rb.c | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/tools/bmp2rb.c b/tools/bmp2rb.c index d50b8c6f33..16bf7d9633 100644 --- a/tools/bmp2rb.c +++ b/tools/bmp2rb.c | |||
@@ -412,22 +412,47 @@ int transform_bitmap(const struct RGBQUAD *src, int width, int height, | |||
412 | * some #define's | 412 | * some #define's |
413 | ****************************************************************************/ | 413 | ****************************************************************************/ |
414 | 414 | ||
415 | void generate_c_source(char *id, int width, int height, | 415 | void generate_c_source(char *id, char* header_dir, int width, int height, |
416 | const unsigned short *t_bitmap, int t_width, | 416 | const unsigned short *t_bitmap, int t_width, |
417 | int t_height, int t_depth) | 417 | int t_height, int t_depth) |
418 | { | 418 | { |
419 | FILE *f; | 419 | FILE *f; |
420 | FILE *fh; | ||
420 | int i, a; | 421 | int i, a; |
421 | 422 | char header_name[1024]; | |
422 | f = stdout; | ||
423 | 423 | ||
424 | if (!id || !id[0]) | 424 | if (!id || !id[0]) |
425 | id = "bitmap"; | 425 | id = "bitmap"; |
426 | 426 | ||
427 | fprintf(f, | 427 | f = stdout; |
428 | "#define BMPHEIGHT_%s %ld\n" | 428 | |
429 | "#define BMPWIDTH_%s %ld\n", | 429 | if (header_dir && header_dir[0]) |
430 | id, height, id, width); | 430 | { |
431 | snprintf(header_name,sizeof(header_name),"%s/%s.h",header_dir,id); | ||
432 | fh = fopen(header_name,"w+"); | ||
433 | |||
434 | if (fh == NULL) | ||
435 | { | ||
436 | debugf("error - can't open '%s'\n", header_name); | ||
437 | return; | ||
438 | } | ||
439 | fprintf(fh, | ||
440 | "#define BMPHEIGHT_%s %ld\n" | ||
441 | "#define BMPWIDTH_%s %ld\n", | ||
442 | id, height, id, width); | ||
443 | if (t_depth <= 8) | ||
444 | fprintf(fh, "extern const unsigned char %s[];\n", id); | ||
445 | else | ||
446 | fprintf(fh, "extern const unsigned short %s[];\n", id); | ||
447 | |||
448 | fclose(fh); | ||
449 | } else { | ||
450 | fprintf(f, | ||
451 | "#define BMPHEIGHT_%s %ld\n" | ||
452 | "#define BMPWIDTH_%s %ld\n", | ||
453 | id, height, id, width); | ||
454 | } | ||
455 | |||
431 | if (t_depth <= 8) | 456 | if (t_depth <= 8) |
432 | fprintf(f, "const unsigned char %s[] = {\n", id); | 457 | fprintf(f, "const unsigned char %s[] = {\n", id); |
433 | else | 458 | else |
@@ -478,6 +503,7 @@ void print_usage(void) | |||
478 | { | 503 | { |
479 | printf("Usage: %s [-i <id>] [-a] <bitmap file>\n" | 504 | printf("Usage: %s [-i <id>] [-a] <bitmap file>\n" |
480 | "\t-i <id> Bitmap name (default is filename without extension)\n" | 505 | "\t-i <id> Bitmap name (default is filename without extension)\n" |
506 | "\t-h <dir> Create header file in <dir>/<id>.h\n" | ||
481 | "\t-a Show ascii picture of bitmap\n" | 507 | "\t-a Show ascii picture of bitmap\n" |
482 | "\t-f <n> Generate destination format n, default = 0\n" | 508 | "\t-f <n> Generate destination format n, default = 0\n" |
483 | "\t 0 Archos recorder, Ondio, Gmini 120/SP, Iriver H1x0 mono\n" | 509 | "\t 0 Archos recorder, Ondio, Gmini 120/SP, Iriver H1x0 mono\n" |
@@ -495,6 +521,7 @@ int main(int argc, char **argv) | |||
495 | { | 521 | { |
496 | char *bmp_filename = NULL; | 522 | char *bmp_filename = NULL; |
497 | char *id = NULL; | 523 | char *id = NULL; |
524 | char* header_dir = NULL; | ||
498 | int i; | 525 | int i; |
499 | int ascii = false; | 526 | int ascii = false; |
500 | int format = 0; | 527 | int format = 0; |
@@ -510,6 +537,23 @@ int main(int argc, char **argv) | |||
510 | { | 537 | { |
511 | switch (argv[i][1]) | 538 | switch (argv[i][1]) |
512 | { | 539 | { |
540 | case 'h': /* .h filename */ | ||
541 | if (argv[i][2]) | ||
542 | { | ||
543 | header_dir = &argv[i][2]; | ||
544 | } | ||
545 | else if (argc > i+1) | ||
546 | { | ||
547 | header_dir = argv[i+1]; | ||
548 | i++; | ||
549 | } | ||
550 | else | ||
551 | { | ||
552 | print_usage(); | ||
553 | exit(1); | ||
554 | } | ||
555 | break; | ||
556 | |||
513 | case 'i': /* ID */ | 557 | case 'i': /* ID */ |
514 | if (argv[i][2]) | 558 | if (argv[i][2]) |
515 | { | 559 | { |
@@ -600,7 +644,8 @@ int main(int argc, char **argv) | |||
600 | if (transform_bitmap(bitmap, width, height, format, &t_bitmap, | 644 | if (transform_bitmap(bitmap, width, height, format, &t_bitmap, |
601 | &t_width, &t_height, &t_depth)) | 645 | &t_width, &t_height, &t_depth)) |
602 | exit(1); | 646 | exit(1); |
603 | generate_c_source(id, width, height, t_bitmap, t_width, t_height, t_depth); | 647 | generate_c_source(id, header_dir, width, height, t_bitmap, |
648 | t_width, t_height, t_depth); | ||
604 | } | 649 | } |
605 | 650 | ||
606 | return 0; | 651 | return 0; |