summaryrefslogtreecommitdiff
path: root/tools/bmp2rb.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2005-11-14 14:47:23 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2005-11-14 14:47:23 +0000
commit057c8ec9d036191a2a1c79fe7f15a5ba11ec8300 (patch)
treed0f5e3bf8d0a5f1d57c931d8f61a0fe00f20f3c1 /tools/bmp2rb.c
parent5e883c36b1876f00ee6c1625018c30b1bd2ac275 (diff)
downloadrockbox-057c8ec9d036191a2a1c79fe7f15a5ba11ec8300.tar.gz
rockbox-057c8ec9d036191a2a1c79fe7f15a5ba11ec8300.zip
Added 16-bit RGB format to bmp2rb
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7861 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/bmp2rb.c')
-rw-r--r--tools/bmp2rb.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/tools/bmp2rb.c b/tools/bmp2rb.c
index 2489ca9cdc..08de2e2390 100644
--- a/tools/bmp2rb.c
+++ b/tools/bmp2rb.c
@@ -277,7 +277,7 @@ int read_bmp_file(char* filename,
277 ****************************************************************************/ 277 ****************************************************************************/
278 278
279int transform_bitmap(const struct RGBQUAD *src, long width, long height, 279int transform_bitmap(const struct RGBQUAD *src, long width, long height,
280 int format, unsigned char **dest, long *dst_width, 280 int format, unsigned short **dest, long *dst_width,
281 long *dst_height) 281 long *dst_height)
282{ 282{
283 long row, col; 283 long row, col;
@@ -305,12 +305,17 @@ int transform_bitmap(const struct RGBQUAD *src, long width, long height,
305 dst_h = height; 305 dst_h = height;
306 break; 306 break;
307 307
308 case 4: /* 16-bit packed RGB (5-6-5) */
309 dst_w = width;
310 dst_h = height;
311 break;
312
308 default: /* unknown */ 313 default: /* unknown */
309 debugf("error - Undefined destination format\n"); 314 debugf("error - Undefined destination format\n");
310 return 1; 315 return 1;
311 } 316 }
312 317
313 *dest = (unsigned char *)malloc(dst_w * dst_h); 318 *dest = (unsigned short *)malloc(dst_w * dst_h);
314 if (*dest == NULL) 319 if (*dest == NULL)
315 { 320 {
316 debugf("error - Out of memory.\n"); 321 debugf("error - Out of memory.\n");
@@ -356,6 +361,19 @@ int transform_bitmap(const struct RGBQUAD *src, long width, long height,
356 (*dest)[row * dst_w + col] = brightness(src[row * width + col]); 361 (*dest)[row * dst_w + col] = brightness(src[row * width + col]);
357 } 362 }
358 break; 363 break;
364
365 case 4: /* 16-bit packed RGB (5-6-5) */
366 for (row = 0; row < height; row++)
367 for (col = 0; col < width; col++)
368 {
369 unsigned short rgb =
370 (((src[row * width + col].rgbRed >> 3) << 11) |
371 ((src[row * width + col].rgbGreen >> 2) << 5) |
372 ((src[row * width + col].rgbBlue >> 3)));
373
374 (*dest)[row * dst_w + col] = rgb;
375 }
376 break;
359 } 377 }
360 378
361 return 0; 379 return 0;
@@ -369,8 +387,8 @@ int transform_bitmap(const struct RGBQUAD *src, long width, long height,
369 ****************************************************************************/ 387 ****************************************************************************/
370 388
371void generate_c_source(char *id, long width, long height, 389void generate_c_source(char *id, long width, long height,
372 const unsigned char *t_bitmap, long t_width, 390 const unsigned short *t_bitmap, long t_width,
373 long t_height) 391 long t_height, int format)
374{ 392{
375 FILE *f; 393 FILE *f;
376 long i, a; 394 long i, a;
@@ -382,15 +400,24 @@ void generate_c_source(char *id, long width, long height,
382 400
383 fprintf(f, 401 fprintf(f,
384 "#define BMPHEIGHT_%s %ld\n" 402 "#define BMPHEIGHT_%s %ld\n"
385 "#define BMPWIDTH_%s %ld\n" 403 "#define BMPWIDTH_%s %ld\n",
386 "const unsigned char %s[] = {\n", 404 id, height, id, width);
387 id, height, id, width, id); 405 if(format < 4)
406 fprintf(f, "const unsigned char %s[] = {\n", id);
407 else
408 fprintf(f, "const unsigned short %s[] = {\n", id);
388 409
389 for (i = 0; i < t_height; i++) 410 for (i = 0; i < t_height; i++)
390 { 411 {
391 for (a = 0; a < t_width; a++) 412 for (a = 0; a < t_width; a++)
392 fprintf(f, "0x%02x,%c", t_bitmap[i * t_width + a], 413 {
393 (a + 1) % 13 ? ' ' : '\n'); 414 if(format < 4)
415 fprintf(f, "0x%02x,%c", t_bitmap[i * t_width + a],
416 (a + 1) % 13 ? ' ' : '\n');
417 else
418 fprintf(f, "0x%04x,%c", t_bitmap[i * t_width + a],
419 (a + 1) % 10 ? ' ' : '\n');
420 }
394 fprintf(f, "\n"); 421 fprintf(f, "\n");
395 } 422 }
396 423
@@ -431,6 +458,7 @@ void print_usage(void)
431 "\t 1 Archos player graphics library\n" 458 "\t 1 Archos player graphics library\n"
432 "\t 2 Iriver H1x0 4-grey\n" 459 "\t 2 Iriver H1x0 4-grey\n"
433 "\t 3 Canonical 8-bit grayscale\n" 460 "\t 3 Canonical 8-bit grayscale\n"
461 "\t 4 16-bit packed 5-6-5 RGB (iriver H300)\n"
434 , APPLICATION_NAME); 462 , APPLICATION_NAME);
435 printf("build date: " __DATE__ "\n\n"); 463 printf("build date: " __DATE__ "\n\n");
436} 464}
@@ -443,7 +471,7 @@ int main(int argc, char **argv)
443 int ascii = false; 471 int ascii = false;
444 int format = 0; 472 int format = 0;
445 struct RGBQUAD *bitmap = NULL; 473 struct RGBQUAD *bitmap = NULL;
446 unsigned char *t_bitmap = NULL; 474 unsigned short *t_bitmap = NULL;
447 long width, height; 475 long width, height;
448 long t_width, t_height; 476 long t_width, t_height;
449 477
@@ -544,7 +572,7 @@ int main(int argc, char **argv)
544 if (transform_bitmap(bitmap, width, height, format, &t_bitmap, 572 if (transform_bitmap(bitmap, width, height, format, &t_bitmap,
545 &t_width, &t_height)) 573 &t_width, &t_height))
546 exit(1); 574 exit(1);
547 generate_c_source(id, width, height, t_bitmap, t_width, t_height); 575 generate_c_source(id, width, height, t_bitmap, t_width, t_height, format);
548 } 576 }
549 577
550 return 0; 578 return 0;