Commit 8d379f179a18d6e9f3d7af8873c942a6834fb780
1 parent
1c3dbe56f7
Exists in
v2017.01-smarct4x
and in
34 other branches
lcd: Support colour lookup table on 16bpp display in BMP images
For 16-bit-per-pixel displays it is useful to support 8 bit-per-pixel images to reduce image size. Add support for this when drawing BMP images. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 1 changed file with 20 additions and 3 deletions Side-by-side Diff
common/lcd.c
... | ... | @@ -578,6 +578,8 @@ |
578 | 578 | unsigned long width, height, byte_width; |
579 | 579 | unsigned long pwidth = panel_info.vl_col; |
580 | 580 | unsigned colors, bpix, bmp_bpix; |
581 | + int hdr_size; | |
582 | + struct bmp_color_table_entry *palette = bmp->color_table; | |
581 | 583 | |
582 | 584 | if (!bmp || !(bmp->header.signature[0] == 'B' && |
583 | 585 | bmp->header.signature[1] == 'M')) { |
... | ... | @@ -589,6 +591,8 @@ |
589 | 591 | width = get_unaligned_le32(&bmp->header.width); |
590 | 592 | height = get_unaligned_le32(&bmp->header.height); |
591 | 593 | bmp_bpix = get_unaligned_le16(&bmp->header.bit_count); |
594 | + hdr_size = get_unaligned_le16(&bmp->header.size); | |
595 | + debug("hdr_size=%d, bmp_bpix=%d\n", hdr_size, bmp_bpix); | |
592 | 596 | |
593 | 597 | colors = 1 << bmp_bpix; |
594 | 598 | |
... | ... | @@ -613,8 +617,8 @@ |
613 | 617 | return 1; |
614 | 618 | } |
615 | 619 | |
616 | - debug("Display-bmp: %d x %d with %d colors\n", | |
617 | - (int)width, (int)height, (int)colors); | |
620 | + debug("Display-bmp: %d x %d with %d colors, display %d\n", | |
621 | + (int)width, (int)height, (int)colors, 1 << bpix); | |
618 | 622 | |
619 | 623 | if (bmp_bpix == 8) |
620 | 624 | lcd_set_cmap(bmp, colors); |
... | ... | @@ -641,6 +645,7 @@ |
641 | 645 | cmap_base = configuration_get_cmap(); |
642 | 646 | #ifdef CONFIG_LCD_BMP_RLE8 |
643 | 647 | u32 compression = get_unaligned_le32(&bmp->header.compression); |
648 | + debug("compressed %d %d\n", compression, BMP_BI_RLE8); | |
644 | 649 | if (compression == BMP_BI_RLE8) { |
645 | 650 | if (bpix != 16) { |
646 | 651 | /* TODO implement render code for bpix != 16 */ |
... | ... | @@ -663,7 +668,19 @@ |
663 | 668 | if (bpix != 16) { |
664 | 669 | fb_put_byte(&fb, &bmap); |
665 | 670 | } else { |
666 | - *(uint16_t *)fb = cmap_base[*(bmap++)]; | |
671 | + struct bmp_color_table_entry *entry; | |
672 | + uint val; | |
673 | + | |
674 | + if (cmap_base) { | |
675 | + val = cmap_base[*bmap]; | |
676 | + } else { | |
677 | + entry = &palette[*bmap]; | |
678 | + val = entry->blue >> 3 | | |
679 | + entry->green >> 2 << 5 | | |
680 | + entry->red >> 3 << 11; | |
681 | + } | |
682 | + *(uint16_t *)fb = val; | |
683 | + bmap++; | |
667 | 684 | fb += sizeof(uint16_t) / sizeof(*fb); |
668 | 685 | } |
669 | 686 | } |