[U-Boot] [PATCH 20/24] lcd: Support colour lookup table on 16bpp display in BMP images

Simon Glass
2015-05-04T17:31:13Z

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>
---

common/lcd.c | 23 ++++++++++++++++++++---
include/bmp_layout.h | 4 ++--
2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/common/lcd.c b/common/lcd.c
index 055c366..2d11578 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -578,6 +578,8 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
unsigned long width, height, byte_width;
unsigned long pwidth = panel_info.vl_col;
unsigned colors, bpix, bmp_bpix;
+ int hdr_size;
+ bmp_color_table_entry_t *palette = bmp->color_table;

if (!bmp || !(bmp->header.signature[0] == 'B' &&
bmp->header.signature[1] == 'M')) {
@@ -589,6 +591,8 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
width = get_unaligned_le32(&bmp->header.width);
height = get_unaligned_le32(&bmp->header.height);
bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
+ hdr_size = get_unaligned_le16(&bmp->header.size);
+ debug("hdr_size=%d, bmp_bpix=%d\n", hdr_size, bmp_bpix);

colors = 1 << bmp_bpix;

@@ -613,8 +617,8 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
return 1;
}

- debug("Display-bmp: %d x %d with %d colors\n",
- (int)width, (int)height, (int)colors);
+ debug("Display-bmp: %d x %d with %d colors, display %d\n",
+ (int)width, (int)height, (int)colors, 1 << bpix);

if (bmp_bpix == 8)
lcd_set_cmap(bmp, colors);
@@ -641,6 +645,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
cmap_base = configuration_get_cmap();
#ifdef CONFIG_LCD_BMP_RLE8
u32 compression = get_unaligned_le32(&bmp->header.compression);
+ debug("compressed %d %d\n", compression, BMP_BI_RLE8);
if (compression == BMP_BI_RLE8) {
if (bpix != 16) {
/* TODO implement render code for bpix != 16 */
@@ -663,7 +668,19 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
if (bpix != 16) {
fb_put_byte(&fb, &bmap);
} else {
- *(uint16_t *)fb = cmap_base[*(bmap++)];
+ struct bmp_color_table_entry *entry;
+ uint val;
+
+ if (cmap_base) {
+ val = cmap_base[*bmap];
+ } else {
+ entry = &palette[*bmap];
+ val = entry->blue >> 3 |
+ entry->green >> 2 << 5 |
+ entry->red >> 3 << 11;
+ }
+ *(uint16_t *)fb = val;
+ bmap++;
fb += sizeof(uint16_t) / sizeof(*fb);
}
}
diff --git a/include/bmp_layout.h b/include/bmp_layout.h
index 22b1fbc..47f505c 100644
--- a/include/bmp_layout.h
+++ b/include/bmp_layout.h
@@ -11,12 +11,12 @@
#ifndef _BMP_H_
#define _BMP_H_

-typedef struct bmp_color_table_entry {
+typedef struct __packed bmp_color_table_entry {
__u8 blue;
__u8 green;
__u8 red;
__u8 reserved;
-} __attribute__ ((packed)) bmp_color_table_entry_t;
+} bmp_color_table_entry_t;

/* When accessing these fields, remember that they are stored in little
endian format, so use linux macros, e.g. le32_to_cpu(width) */
--
2.2.0.rc0.207.ga3a616c