summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2018-06-12 12:55:56 +0200
committerMarcin Bukat <marcin.bukat@gmail.com>2018-06-12 12:55:56 +0200
commitf4390794ef37f5c9f9e4c17d9435f8bff9e65034 (patch)
tree530714319efb5242655222b98638198bbb4d746f
parent307ea8382e756bc6265e9edece074ff08c54267e (diff)
downloadrockbox-f4390794ef37f5c9f9e4c17d9435f8bff9e65034.tar.gz
rockbox-f4390794ef37f5c9f9e4c17d9435f8bff9e65034.zip
bmp2rb: Add XRGB 32bit native format
Change-Id: Ic4af5a7c53c032e58dc252d1f69001d7aafd7f26
-rw-r--r--tools/bmp2rb.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/tools/bmp2rb.c b/tools/bmp2rb.c
index 24ea1a8026..387bcc05fe 100644
--- a/tools/bmp2rb.c
+++ b/tools/bmp2rb.c
@@ -81,6 +81,7 @@ union RAWDATA {
81 void *d; /* unspecified */ 81 void *d; /* unspecified */
82 unsigned short *d16; /* depth <= 16 */ 82 unsigned short *d16; /* depth <= 16 */
83 struct { unsigned char b, g, r; } *d24; /* depth = 24 BGR */ 83 struct { unsigned char b, g, r; } *d24; /* depth = 24 BGR */
84 struct { unsigned char b, g, r, x; } *d32;
84}; 85};
85 86
86short readshort(void* value) 87short readshort(void* value)
@@ -351,6 +352,12 @@ int transform_bitmap(const struct RGBQUAD *src, int width, int height,
351 dst_d = 24; 352 dst_d = 24;
352 break; 353 break;
353 354
355 case 10: /* 32-bit XRGB */
356 dst_w = width;
357 dst_h = height;
358 dst_d = 32;
359 break;
360
354 default: /* unknown */ 361 default: /* unknown */
355 debugf("error - Undefined destination format\n"); 362 debugf("error - Undefined destination format\n");
356 return 1; 363 return 1;
@@ -358,8 +365,10 @@ int transform_bitmap(const struct RGBQUAD *src, int width, int height,
358 365
359 if (dst_d <= 16) 366 if (dst_d <= 16)
360 alloc_size = sizeof(dest.d16[0]); 367 alloc_size = sizeof(dest.d16[0]);
361 else /* 24 bit */ 368 else if (dst_d <= 24)
362 alloc_size = sizeof(dest.d24[0]); 369 alloc_size = sizeof(dest.d24[0]);
370 else
371 alloc_size = sizeof(dest.d32[0]);
363 dest.d = calloc(dst_w * dst_h, alloc_size); 372 dest.d = calloc(dst_w * dst_h, alloc_size);
364 373
365 if (dest.d == NULL) 374 if (dest.d == NULL)
@@ -468,6 +477,15 @@ int transform_bitmap(const struct RGBQUAD *src, int width, int height,
468 dest.d24[row * width + col].b = src[row * width + col].rgbBlue; 477 dest.d24[row * width + col].b = src[row * width + col].rgbBlue;
469 } 478 }
470 break; 479 break;
480
481 case 10: /* 32-bit XRGB */
482 for (row = 0; row < height; row++)
483 for (col = 0; col < width; col++)
484 {
485 dest.d32[row * width + col].r = src[row * width + col].rgbRed;
486 dest.d32[row * width + col].g = src[row * width + col].rgbGreen;
487 dest.d32[row * width + col].b = src[row * width + col].rgbBlue;
488 }
471 } 489 }
472 490
473 return 0; 491 return 0;
@@ -537,9 +555,9 @@ void generate_c_source(char *id, char* header_dir, int width, int height,
537 555
538 if (t_depth <= 8) 556 if (t_depth <= 8)
539 fprintf(f, "const unsigned char %s[] = {\n", id); 557 fprintf(f, "const unsigned char %s[] = {\n", id);
540 else if (t_depth == 16) 558 else if (t_depth <= 16)
541 fprintf(f, "const unsigned short %s[] = {\n", id); 559 fprintf(f, "const unsigned short %s[] = {\n", id);
542 else if (t_depth == 24) 560 else
543 fprintf(f, "const fb_data %s[] = {\n", id); 561 fprintf(f, "const fb_data %s[] = {\n", id);
544 562
545 for (i = 0; i < t_height; i++) 563 for (i = 0; i < t_height; i++)
@@ -558,6 +576,12 @@ void generate_c_source(char *id, char* header_dir, int width, int height,
558 t_bitmap->d24[i * t_width + a].g, 576 t_bitmap->d24[i * t_width + a].g,
559 t_bitmap->d24[i * t_width + a].b, 577 t_bitmap->d24[i * t_width + a].b,
560 (a + 1) % 4 ? ' ' : '\n'); 578 (a + 1) % 4 ? ' ' : '\n');
579 else if (t_depth == 32)
580 fprintf(f, "{ .r = 0x%02x, .g = 0x%02x, .b = 0x%02x, .x = 0x00 },%c",
581 t_bitmap->d32[i * t_width + a].r,
582 t_bitmap->d32[i * t_width + a].g,
583 t_bitmap->d32[i * t_width + a].b,
584 (a + 1) % 4 ? ' ' : '\n');
561 } 585 }
562 fprintf(f, "\n"); 586 fprintf(f, "\n");
563 } 587 }
@@ -603,10 +627,14 @@ void generate_raw_file(const union RAWDATA *t_bitmap,
603 fwrite(&lo, 1, 1, f); 627 fwrite(&lo, 1, 1, f);
604 fwrite(&hi, 1, 1, f); 628 fwrite(&hi, 1, 1, f);
605 } 629 }
606 else /* 24 */ 630 else if (t_depth == 24)
607 { 631 {
608 fwrite(&t_bitmap->d24[i * t_width + a], 3, 1, f); 632 fwrite(&t_bitmap->d24[i * t_width + a], 3, 1, f);
609 } 633 }
634 else /* 32 */
635 {
636 fwrite(&t_bitmap->d32[i * t_width + a], 4, 1, f);
637 }
610 } 638 }
611 } 639 }
612} 640}
@@ -654,7 +682,8 @@ void print_usage(void)
654 "\t 6 Greyscale iPod 4-grey\n" 682 "\t 6 Greyscale iPod 4-grey\n"
655 "\t 7 Greyscale X5 remote 4-grey\n" 683 "\t 7 Greyscale X5 remote 4-grey\n"
656 "\t 8 16-bit packed 5-6-5 RGB with a vertical stride\n" 684 "\t 8 16-bit packed 5-6-5 RGB with a vertical stride\n"
657 "\t 9 24-bit BGR\n"); 685 "\t 9 24-bit BGR\n"
686 "\t 10 32-bit XRGB8888\n");
658 printf("build date: " __DATE__ "\n\n"); 687 printf("build date: " __DATE__ "\n\n");
659} 688}
660 689