diff options
author | Andrew Mahone <andrew.mahone@gmail.com> | 2009-05-09 07:31:27 +0000 |
---|---|---|
committer | Andrew Mahone <andrew.mahone@gmail.com> | 2009-05-09 07:31:27 +0000 |
commit | 91efc162564cd9c04677e2e38550cde21995b06e (patch) | |
tree | c927cefc7f12a49396541dbac246dc76ca444c71 /apps/recorder/bmp.c | |
parent | 67695617a13e9f37f17e3718b03046f6d748a9e1 (diff) | |
download | rockbox-91efc162564cd9c04677e2e38550cde21995b06e.tar.gz rockbox-91efc162564cd9c04677e2e38550cde21995b06e.zip |
Split 8-bit-to-native conversion in bmp.c into a function, add support for plugging unscaled output in BMP and JPEG loaders, use output_row_8_native in JPEG decoder when possible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20884 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/recorder/bmp.c')
-rw-r--r-- | apps/recorder/bmp.c | 218 |
1 files changed, 129 insertions, 89 deletions
diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index f1fc1f83b4..4897b2db18 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c | |||
@@ -351,6 +351,93 @@ static inline int rgbcmp(struct uint8_rgb rgb1, struct uint8_rgb rgb2) | |||
351 | else | 351 | else |
352 | return 1; | 352 | return 1; |
353 | } | 353 | } |
354 | #if LCD_DEPTH > 1 | ||
355 | void output_row_8_native(uint32_t row, void * row_in, | ||
356 | struct scaler_context *ctx) | ||
357 | { | ||
358 | int col; | ||
359 | int fb_width = BM_WIDTH(ctx->bm->width,FORMAT_NATIVE,0); | ||
360 | uint8_t dy = DITHERY(row); | ||
361 | #ifdef HAVE_LCD_COLOR | ||
362 | struct uint8_rgb *qp = (struct uint8_rgb*)row_in; | ||
363 | #else | ||
364 | uint8_t *qp = (uint8_t*)row_in; | ||
365 | #endif | ||
366 | BDEBUGF("output_row: y: %lu in: %p\n",row, row_in); | ||
367 | #if LCD_DEPTH == 2 | ||
368 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING | ||
369 | /* greyscale iPods */ | ||
370 | fb_data *dest = (fb_data *)ctx->bm->data + fb_width * row; | ||
371 | int shift = 6; | ||
372 | int delta = 127; | ||
373 | unsigned bright; | ||
374 | unsigned data = 0; | ||
375 | |||
376 | for (col = 0; col < ctx->bm->width; col++) { | ||
377 | if (ctx->dither) | ||
378 | delta = DITHERXDY(col,dy); | ||
379 | bright = *qp++; | ||
380 | bright = (3 * bright + (bright >> 6) + delta) >> 8; | ||
381 | data |= (~bright & 3) << shift; | ||
382 | shift -= 2; | ||
383 | if (shift < 0) { | ||
384 | *dest++ = data; | ||
385 | data = 0; | ||
386 | shift = 6; | ||
387 | } | ||
388 | } | ||
389 | if (shift < 6) | ||
390 | *dest++ = data; | ||
391 | #elif LCD_PIXELFORMAT == VERTICAL_PACKING | ||
392 | /* iriver H1x0 */ | ||
393 | fb_data *dest = (fb_data *)ctx->bm->data + fb_width * | ||
394 | (row >> 2); | ||
395 | int shift = 2 * (row & 3); | ||
396 | int delta = 127; | ||
397 | unsigned bright; | ||
398 | |||
399 | for (col = 0; col < ctx->bm->width; col++) { | ||
400 | if (ctx->dither) | ||
401 | delta = DITHERXDY(col,dy); | ||
402 | bright = *qp++; | ||
403 | bright = (3 * bright + (bright >> 6) + delta) >> 8; | ||
404 | *dest++ |= (~bright & 3) << shift; | ||
405 | } | ||
406 | #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED | ||
407 | /* iAudio M3 */ | ||
408 | fb_data *dest = (fb_data *)ctx->bm->data + fb_width * | ||
409 | (row >> 3); | ||
410 | int shift = row & 7; | ||
411 | int delta = 127; | ||
412 | unsigned bright; | ||
413 | |||
414 | for (col = 0; col < ctx->bm->width; col++) { | ||
415 | if (ctx->dither) | ||
416 | delta = DITHERXDY(col,dy); | ||
417 | bright = *qp++; | ||
418 | bright = (3 * bright + (bright >> 6) + delta) >> 8; | ||
419 | *dest++ |= vi_pattern[bright] << shift; | ||
420 | } | ||
421 | #endif /* LCD_PIXELFORMAT */ | ||
422 | #elif LCD_DEPTH == 16 | ||
423 | /* iriver h300, colour iPods, X5 */ | ||
424 | fb_data *dest = (fb_data *)ctx->bm->data + fb_width * row; | ||
425 | int delta = 127; | ||
426 | unsigned r, g, b; | ||
427 | for (col = 0; col < ctx->bm->width; col++) { | ||
428 | if (ctx->dither) | ||
429 | delta = DITHERXDY(col,dy); | ||
430 | r = qp->red; | ||
431 | g = qp->green; | ||
432 | b = (qp++)->blue; | ||
433 | r = (31 * r + (r >> 3) + delta) >> 8; | ||
434 | g = (63 * g + (g >> 2) + delta) >> 8; | ||
435 | b = (31 * b + (b >> 3) + delta) >> 8; | ||
436 | *dest++ = LCD_RGBPACK_LCD(r, g, b); | ||
437 | } | ||
438 | #endif /* LCD_DEPTH */ | ||
439 | } | ||
440 | #endif | ||
354 | 441 | ||
355 | /****************************************************************************** | 442 | /****************************************************************************** |
356 | * read_bmp_fd() | 443 | * read_bmp_fd() |
@@ -598,7 +685,7 @@ int read_bmp_fd(int fd, | |||
598 | #if (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) && \ | 685 | #if (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) && \ |
599 | defined(HAVE_BMP_SCALING) || defined(PLUGIN) | 686 | defined(HAVE_BMP_SCALING) || defined(PLUGIN) |
600 | #if LCD_DEPTH > 1 && defined(HAVE_BMP_SCALING) | 687 | #if LCD_DEPTH > 1 && defined(HAVE_BMP_SCALING) |
601 | if (resize || cformat) | 688 | if (resize) |
602 | #endif | 689 | #endif |
603 | { | 690 | { |
604 | if (resize_on_load(bm, dither, &src_dim, &rset, | 691 | if (resize_on_load(bm, dither, &src_dim, &rset, |
@@ -610,31 +697,43 @@ int read_bmp_fd(int fd, | |||
610 | } | 697 | } |
611 | #endif /* LCD_DEPTH */ | 698 | #endif /* LCD_DEPTH */ |
612 | 699 | ||
613 | #ifndef PLUGIN | 700 | #if LCD_DEPTH > 1 || defined(PLUGIN) |
614 | #if (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) | 701 | struct scaler_context ctx = { |
615 | int fb_width = BM_WIDTH(bm->width,bm->format,remote); | 702 | .bm = bm, |
703 | .dither = dither, | ||
704 | }; | ||
705 | #endif | ||
706 | #if LCD_DEPTH > 1 | ||
707 | void (*output_row_8)(uint32_t, void*, struct scaler_context*) = | ||
708 | output_row_8_native; | ||
709 | #elif defined(PLUGIN) | ||
710 | void (*output_row_8)(uint32_t, void*, struct scaler_context*) = NULL; | ||
711 | #endif | ||
712 | #if LCD_DEPTH > 1 || defined(PLUGIN) | ||
713 | if (cformat) | ||
714 | output_row_8 = cformat->output_row_8; | ||
616 | #endif | 715 | #endif |
617 | int col, row; | ||
618 | 716 | ||
717 | int row; | ||
619 | /* loop to read rows and put them to buffer */ | 718 | /* loop to read rows and put them to buffer */ |
620 | for (row = rset.rowstart; row != rset.rowstop; row += rset.rowstep) { | 719 | for (row = rset.rowstart; row != rset.rowstop; row += rset.rowstep) { |
720 | if (!read_part_line(&ba)) | ||
721 | return -9; | ||
722 | #ifndef PLUGIN | ||
621 | #if !defined(HAVE_LCD_COLOR) && \ | 723 | #if !defined(HAVE_LCD_COLOR) && \ |
622 | (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) | 724 | (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) |
623 | uint8_t* qp = ba.buf; | 725 | uint8_t* qp = ba.buf; |
624 | #else | 726 | #else |
625 | struct uint8_rgb *qp = (struct uint8_rgb *)ba.buf; | 727 | struct uint8_rgb *qp = (struct uint8_rgb *)ba.buf; |
626 | #endif | 728 | #endif |
627 | unsigned mask; | 729 | #endif |
628 | unsigned char *p; | ||
629 | if (!read_part_line(&ba)) | ||
630 | return -9; | ||
631 | |||
632 | /* Convert to destination format */ | 730 | /* Convert to destination format */ |
633 | #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) | 731 | #if ((LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) && \ |
634 | unsigned char dy = DITHERY(row); | 732 | !defined(PLUGIN) |
635 | if (format == FORMAT_NATIVE) { | 733 | if (format == FORMAT_NATIVE) { |
636 | #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 | 734 | #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 |
637 | if (remote) { | 735 | if (remote) { |
736 | unsigned char dy = DITHERY(row); | ||
638 | #if (LCD_REMOTE_DEPTH == 2) && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED) | 737 | #if (LCD_REMOTE_DEPTH == 2) && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED) |
639 | /* iAudio X5/M5 remote */ | 738 | /* iAudio X5/M5 remote */ |
640 | fb_remote_data *dest = (fb_remote_data *)bitmap | 739 | fb_remote_data *dest = (fb_remote_data *)bitmap |
@@ -643,6 +742,7 @@ int read_bmp_fd(int fd, | |||
643 | int delta = 127; | 742 | int delta = 127; |
644 | unsigned bright; | 743 | unsigned bright; |
645 | 744 | ||
745 | int col; | ||
646 | for (col = 0; col < bm->width; col++) { | 746 | for (col = 0; col < bm->width; col++) { |
647 | if (dither) | 747 | if (dither) |
648 | delta = DITHERXDY(col,dy); | 748 | delta = DITHERXDY(col,dy); |
@@ -658,85 +758,25 @@ int read_bmp_fd(int fd, | |||
658 | #endif /* LCD_REMOTE_DEPTH / LCD_REMOTE_PIXELFORMAT */ | 758 | #endif /* LCD_REMOTE_DEPTH / LCD_REMOTE_PIXELFORMAT */ |
659 | } else | 759 | } else |
660 | #endif /* defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 */ | 760 | #endif /* defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 */ |
761 | #endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && | ||
762 | (LCD_REMOTE_DEPTH > 1) */ | ||
763 | #if LCD_DEPTH > 1 || defined(PLUGIN) | ||
661 | { | 764 | { |
662 | #if LCD_DEPTH == 2 | 765 | output_row_8(row, ba.buf, &ctx); |
663 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING | ||
664 | /* greyscale iPods */ | ||
665 | fb_data *dest = (fb_data *)bitmap + fb_width * row; | ||
666 | int shift = 6; | ||
667 | int delta = 127; | ||
668 | unsigned bright; | ||
669 | unsigned data = 0; | ||
670 | |||
671 | for (col = 0; col < bm->width; col++) { | ||
672 | if (dither) | ||
673 | delta = DITHERXDY(col,dy); | ||
674 | bright = *qp++; | ||
675 | bright = (3 * bright + (bright >> 6) + delta) >> 8; | ||
676 | data |= (~bright & 3) << shift; | ||
677 | shift -= 2; | ||
678 | if (shift < 0) { | ||
679 | *dest++ = data; | ||
680 | data = 0; | ||
681 | shift = 6; | ||
682 | } | ||
683 | } | ||
684 | if (shift < 6) | ||
685 | *dest++ = data; | ||
686 | #elif LCD_PIXELFORMAT == VERTICAL_PACKING | ||
687 | /* iriver H1x0 */ | ||
688 | fb_data *dest = (fb_data *)bitmap + fb_width * (row >> 2); | ||
689 | int shift = 2 * (row & 3); | ||
690 | int delta = 127; | ||
691 | unsigned bright; | ||
692 | |||
693 | for (col = 0; col < bm->width; col++) { | ||
694 | if (dither) | ||
695 | delta = DITHERXDY(col,dy); | ||
696 | bright = *qp++; | ||
697 | bright = (3 * bright + (bright >> 6) + delta) >> 8; | ||
698 | *dest++ |= (~bright & 3) << shift; | ||
699 | } | ||
700 | #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED | ||
701 | /* iAudio M3 */ | ||
702 | fb_data *dest = (fb_data *)bitmap + fb_width * (row >> 3); | ||
703 | int shift = row & 7; | ||
704 | int delta = 127; | ||
705 | unsigned bright; | ||
706 | |||
707 | for (col = 0; col < bm->width; col++) { | ||
708 | if (dither) | ||
709 | delta = DITHERXDY(col,dy); | ||
710 | bright = *qp++; | ||
711 | bright = (3 * bright + (bright >> 6) + delta) >> 8; | ||
712 | *dest++ |= vi_pattern[bright] << shift; | ||
713 | } | ||
714 | #endif /* LCD_PIXELFORMAT */ | ||
715 | #elif LCD_DEPTH == 16 | ||
716 | /* iriver h300, colour iPods, X5 */ | ||
717 | fb_data *dest = (fb_data *)bitmap + fb_width * row; | ||
718 | int delta = 127; | ||
719 | unsigned r, g, b; | ||
720 | struct uint8_rgb q0; | ||
721 | |||
722 | for (col = 0; col < bm->width; col++) { | ||
723 | if (dither) | ||
724 | delta = DITHERXDY(col,dy); | ||
725 | q0 = *qp++; | ||
726 | r = (31 * q0.red + (q0.red >> 3) + delta) >> 8; | ||
727 | g = (63 * q0.green + (q0.green >> 2) + delta) >> 8; | ||
728 | b = (31 * q0.blue + (q0.blue >> 3) + delta) >> 8; | ||
729 | *dest++ = LCD_RGBPACK_LCD(r, g, b); | ||
730 | } | ||
731 | #endif /* LCD_DEPTH */ | ||
732 | } | 766 | } |
733 | } else | 767 | #endif |
734 | #endif /* (LCD_DEPTH > 1) || | 768 | #if ((LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) && \ |
735 | defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ | 769 | !defined(PLUGIN) |
770 | } | ||
771 | #ifndef PLUGIN | ||
772 | else | ||
773 | #endif | ||
774 | #endif | ||
775 | #ifndef PLUGIN | ||
736 | { | 776 | { |
737 | p = bitmap + bm->width * (row >> 3); | 777 | unsigned char *p = bitmap + bm->width * (row >> 3); |
738 | mask = 1 << (row & 7); | 778 | unsigned char mask = 1 << (row & 7); |
739 | 779 | int col; | |
740 | for (col = 0; col < bm->width; col++, p++) | 780 | for (col = 0; col < bm->width; col++, p++) |
741 | #if !defined(HAVE_LCD_COLOR) && \ | 781 | #if !defined(HAVE_LCD_COLOR) && \ |
742 | (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) | 782 | (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) |
@@ -747,7 +787,7 @@ int read_bmp_fd(int fd, | |||
747 | *p |= mask; | 787 | *p |= mask; |
748 | #endif | 788 | #endif |
749 | } | 789 | } |
790 | #endif | ||
750 | } | 791 | } |
751 | return totalsize; /* return the used buffer size. */ | 792 | return totalsize; /* return the used buffer size. */ |
752 | #endif | ||
753 | } | 793 | } |