summaryrefslogtreecommitdiff
path: root/tools/bmp2rb.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/bmp2rb.c')
-rw-r--r--tools/bmp2rb.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/tools/bmp2rb.c b/tools/bmp2rb.c
index 61c0268c49..d50b8c6f33 100644
--- a/tools/bmp2rb.c
+++ b/tools/bmp2rb.c
@@ -49,7 +49,7 @@
49struct Fileheader 49struct Fileheader
50{ 50{
51 unsigned short Type; /* signature - 'BM' */ 51 unsigned short Type; /* signature - 'BM' */
52 unsigned int Size; /* file size in bytes */ 52 unsigned int Size; /* file size in bytes */
53 unsigned short Reserved1; /* 0 */ 53 unsigned short Reserved1; /* 0 */
54 unsigned short Reserved2; /* 0 */ 54 unsigned short Reserved2; /* 0 */
55 unsigned int OffBits; /* offset to bitmap */ 55 unsigned int OffBits; /* offset to bitmap */
@@ -278,41 +278,48 @@ int read_bmp_file(char* filename,
278 278
279int transform_bitmap(const struct RGBQUAD *src, int width, int height, 279int transform_bitmap(const struct RGBQUAD *src, int width, int height,
280 int format, unsigned short **dest, int *dst_width, 280 int format, unsigned short **dest, int *dst_width,
281 int *dst_height) 281 int *dst_height, int *dst_depth)
282{ 282{
283 int row, col; 283 int row, col;
284 int dst_w, dst_h; 284 int dst_w, dst_h, dst_d;
285 285
286 switch (format) 286 switch (format)
287 { 287 {
288 case 0: /* Archos recorders, Ondio, Gmini 120/SP, Iriver H1x0 monochrome */ 288 case 0: /* Archos recorders, Ondio, Gmini 120/SP, Iriver H1x0 monochrome */
289 dst_w = width; 289 dst_w = width;
290 dst_h = (height + 7) / 8; 290 dst_h = (height + 7) / 8;
291 dst_d = 8;
291 break; 292 break;
292 293
293 case 1: /* Archos player graphics library */ 294 case 1: /* Archos player graphics library */
294 dst_w = (width + 7) / 8; 295 dst_w = (width + 7) / 8;
295 dst_h = height; 296 dst_h = height;
297 dst_d = 8;
296 break; 298 break;
297 299
298 case 2: /* Iriver H1x0 4-grey */ 300 case 2: /* Iriver H1x0 4-grey */
299 dst_w = width; 301 dst_w = width;
300 dst_h = (height + 3) / 4; 302 dst_h = (height + 3) / 4;
303 dst_d = 8;
301 break; 304 break;
302 305
303 case 3: /* Canonical 8-bit grayscale */ 306 case 3: /* Canonical 8-bit grayscale */
304 dst_w = width; 307 dst_w = width;
305 dst_h = height; 308 dst_h = height;
309 dst_d = 8;
306 break; 310 break;
307 311
308 case 4: /* 16-bit packed RGB (5-6-5) */ 312 case 4: /* 16-bit packed RGB (5-6-5) */
313 case 5: /* 16-bit packed and byte-swapped RGB (5-6-5) */
309 dst_w = width; 314 dst_w = width;
310 dst_h = height; 315 dst_h = height;
316 dst_d = 16;
311 break; 317 break;
312 318
313 case 5: /* 16-bit packed and byte-swapped RGB (5-6-5) */ 319 case 6: /* greyscale iPods 4-grey */
314 dst_w = width; 320 dst_w = (width + 3) / 4;
315 dst_h = height; 321 dst_h = height;
322 dst_d = 8;
316 break; 323 break;
317 324
318 default: /* unknown */ 325 default: /* unknown */
@@ -329,6 +336,7 @@ int transform_bitmap(const struct RGBQUAD *src, int width, int height,
329 memset(*dest, 0, dst_w * dst_h * sizeof(short)); 336 memset(*dest, 0, dst_w * dst_h * sizeof(short));
330 *dst_width = dst_w; 337 *dst_width = dst_w;
331 *dst_height = dst_h; 338 *dst_height = dst_h;
339 *dst_depth = dst_d;
332 340
333 switch (format) 341 switch (format)
334 { 342 {
@@ -383,6 +391,15 @@ int transform_bitmap(const struct RGBQUAD *src, int width, int height,
383 (*dest)[row * dst_w + col] = ((rgb&0xff00)>>8)|((rgb&0x00ff)<<8); 391 (*dest)[row * dst_w + col] = ((rgb&0xff00)>>8)|((rgb&0x00ff)<<8);
384 } 392 }
385 break; 393 break;
394
395 case 6: /* greyscale iPods 4-grey */
396 for (row = 0; row < height; row++)
397 for (col = 0; col < width; col++)
398 {
399 (*dest)[row * dst_w + (col/4)] |=
400 (~brightness(src[row * width + col]) & 0xC0) >> (2 * (~col & 3));
401 }
402 break;
386 } 403 }
387 404
388 return 0; 405 return 0;
@@ -397,7 +414,7 @@ int transform_bitmap(const struct RGBQUAD *src, int width, int height,
397 414
398void generate_c_source(char *id, int width, int height, 415void generate_c_source(char *id, int width, int height,
399 const unsigned short *t_bitmap, int t_width, 416 const unsigned short *t_bitmap, int t_width,
400 int t_height, int format) 417 int t_height, int t_depth)
401{ 418{
402 FILE *f; 419 FILE *f;
403 int i, a; 420 int i, a;
@@ -411,7 +428,7 @@ void generate_c_source(char *id, int width, int height,
411 "#define BMPHEIGHT_%s %ld\n" 428 "#define BMPHEIGHT_%s %ld\n"
412 "#define BMPWIDTH_%s %ld\n", 429 "#define BMPWIDTH_%s %ld\n",
413 id, height, id, width); 430 id, height, id, width);
414 if(format < 4) 431 if (t_depth <= 8)
415 fprintf(f, "const unsigned char %s[] = {\n", id); 432 fprintf(f, "const unsigned char %s[] = {\n", id);
416 else 433 else
417 fprintf(f, "const unsigned short %s[] = {\n", id); 434 fprintf(f, "const unsigned short %s[] = {\n", id);
@@ -420,7 +437,7 @@ void generate_c_source(char *id, int width, int height,
420 { 437 {
421 for (a = 0; a < t_width; a++) 438 for (a = 0; a < t_width; a++)
422 { 439 {
423 if(format < 4) 440 if (t_depth <= 8)
424 fprintf(f, "0x%02x,%c", t_bitmap[i * t_width + a], 441 fprintf(f, "0x%02x,%c", t_bitmap[i * t_width + a],
425 (a + 1) % 13 ? ' ' : '\n'); 442 (a + 1) % 13 ? ' ' : '\n');
426 else 443 else
@@ -469,6 +486,7 @@ void print_usage(void)
469 "\t 3 Canonical 8-bit grayscale\n" 486 "\t 3 Canonical 8-bit grayscale\n"
470 "\t 4 16-bit packed 5-6-5 RGB (iriver H300)\n" 487 "\t 4 16-bit packed 5-6-5 RGB (iriver H300)\n"
471 "\t 5 16-bit packed and byte-swapped 5-6-5 RGB (iPod)\n" 488 "\t 5 16-bit packed and byte-swapped 5-6-5 RGB (iPod)\n"
489 "\t 6 Greayscale iPod 4-grey\n"
472 , APPLICATION_NAME); 490 , APPLICATION_NAME);
473 printf("build date: " __DATE__ "\n\n"); 491 printf("build date: " __DATE__ "\n\n");
474} 492}
@@ -483,7 +501,7 @@ int main(int argc, char **argv)
483 struct RGBQUAD *bitmap = NULL; 501 struct RGBQUAD *bitmap = NULL;
484 unsigned short *t_bitmap = NULL; 502 unsigned short *t_bitmap = NULL;
485 int width, height; 503 int width, height;
486 int t_width, t_height; 504 int t_width, t_height, t_depth;
487 505
488 506
489 for (i = 1;i < argc;i++) 507 for (i = 1;i < argc;i++)
@@ -580,9 +598,9 @@ int main(int argc, char **argv)
580 else 598 else
581 { 599 {
582 if (transform_bitmap(bitmap, width, height, format, &t_bitmap, 600 if (transform_bitmap(bitmap, width, height, format, &t_bitmap,
583 &t_width, &t_height)) 601 &t_width, &t_height, &t_depth))
584 exit(1); 602 exit(1);
585 generate_c_source(id, width, height, t_bitmap, t_width, t_height, format); 603 generate_c_source(id, width, height, t_bitmap, t_width, t_height, t_depth);
586 } 604 }
587 605
588 return 0; 606 return 0;