bmp_helper: fix bmp rle8 display abnormal
authorMark Yao <mark.yao@rock-chips.com>
Tue, 10 Mar 2015 11:22:43 +0000 (19:22 +0800)
committerhjc <hjc@rock-chips.com>
Thu, 12 Mar 2015 08:19:57 +0000 (16:19 +0800)
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
drivers/video/rockchip/bmp_helper.c

index bf7186f31f9b7ce087588f9a9a0289e9194e295f..a50fd58729ea1a8edaa44570db74d82b565f1ebb 100755 (executable)
 
 #include "bmp_helper.h"
 
-unsigned short bmp_logo_palette[] = {
-       0x0000, 0x0021, 0x0840, 0x0841, 0x0041, 0x0862, 0x0043, 0x1060,
-       0x1061, 0x1081, 0x18a1, 0x1082, 0x18c3, 0x18c2, 0x18e4, 0x1904,
-       0x20e2, 0x2901, 0x2123, 0x2902, 0x3123, 0x3983, 0x2104, 0x2945,
-       0x2924, 0x2966, 0x3144, 0x3185, 0x3984, 0x39a5, 0x31a6, 0x39c7,
-       0x51a2, 0x41c4, 0x61e4, 0x4a02, 0x4a24, 0x5a65, 0x5245, 0x5226,
-       0x5a66, 0x62a3, 0x7202, 0x6ac4, 0x62c7, 0x72c5, 0x7285, 0x7b03,
-       0x6b05, 0x6b07, 0x7b46, 0x7326, 0x4228, 0x4a69, 0x5a88, 0x528a,
-       0x5aeb, 0x62a8, 0x7b4a, 0x7ba9, 0x630c, 0x6b4d, 0x73ae, 0x7bcf,
-       0x92c4, 0x8b25, 0x83a4, 0x8bc6, 0x9b65, 0x9ba6, 0xa2a2, 0xa364,
-       0xa324, 0xabe5, 0xb364, 0xb3a4, 0xb386, 0x8369, 0x83a8, 0x8b8b,
-       0x93a8, 0x8bcc, 0xc3c4, 0xebc1, 0x9c23, 0x9c04, 0x9406, 0x9427,
-       0xac23, 0xb483, 0xa445, 0xa407, 0xacc7, 0xbc64, 0xb4c4, 0xbd26,
-       0x9c2d, 0xac4c, 0xbd29, 0xc4c2, 0xc4e4, 0xc4a4, 0xdce5, 0xcc44,
-       0xc563, 0xdd02, 0xdd03, 0xdd83, 0xc544, 0xcd87, 0xd544, 0xdd24,
-       0xdd84, 0xddc4, 0xd5c7, 0xe462, 0xe463, 0xe4c1, 0xeca3, 0xecc2,
-       0xecc2, 0xf442, 0xf4a3, 0xe444, 0xec65, 0xe485, 0xeca5, 0xecc4,
-       0xecc5, 0xe4a4, 0xf465, 0xf4a4, 0xed22, 0xed23, 0xed62, 0xed63,
-       0xe522, 0xedc2, 0xfd20, 0xfd02, 0xfde1, 0xfdc1, 0xf5c3, 0xf5c3,
-       0xe5c1, 0xed04, 0xed25, 0xed64, 0xed65, 0xe505, 0xed66, 0xed26,
-       0xed84, 0xeda5, 0xede4, 0xedc5, 0xe5e4, 0xf525, 0xf5e4, 0xf5e5,
-       0xf5a4, 0xed49, 0xeda8, 0xedab, 0xf5eb, 0xf5cb, 0xedac, 0xf5cc,
-       0xf5ce, 0xee21, 0xee42, 0xee22, 0xfe21, 0xf602, 0xfe63, 0xfe22,
-       0xfea0, 0xfea3, 0xfee2, 0xfec3, 0xf682, 0xee65, 0xe624, 0xee85,
-       0xf625, 0xf664, 0xf645, 0xfe64, 0xf624, 0xf606, 0xf684, 0xf685,
-       0xfea4, 0xfee4, 0xf6c4, 0xf6a6, 0xff03, 0xff02, 0xee2f, 0xf60d,
-       0xf62e, 0xf64f, 0xf64e, 0x8410, 0x8c51, 0x94b2, 0x9cd3, 0xa4b0,
-       0xbd30, 0xbd72, 0xa534, 0xad55, 0xb596, 0xbdd7, 0xde75, 0xf671,
-       0xf691, 0xf692, 0xf6b3, 0xf6d3, 0xfeb3, 0xf673, 0xe6b6, 0xf6d4,
-       0xf6f5, 0xfef5, 0xf6f6, 0xfef6, 0xff15, 0xf716, 0xff16, 0xff17,
-       0xc618, 0xce79, 0xd69a, 0xdefb, 0xef19, 0xff38, 0xff58, 0xff79,
-       0xf718, 0xff7a, 0xf75a, 0xff99, 0xff9a, 0xffbb, 0xffdb, 0xe73c,
-       0xef5d, 0xfffc, 0xf7be, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000,
-};
-
 static void draw_unencoded_bitmap(uint16_t **dst, uint8_t *bmap, uint16_t *cmap,
                                  uint32_t cnt)
 {
@@ -335,8 +300,10 @@ int bmpdecoder(void *bmp_addr, void *pdst, int *width, int *height, int *bits)
 {
        BITMAPHEADER header;
        BITMAPINFOHEADER infoheader;
+       uint16_t *bmp_logo_palette;
        uint32_t size;
        uint16_t linesize;
+       char *cmap_base;
        char *src = bmp_addr;
        char *dst = pdst;
        int i;
@@ -360,16 +327,29 @@ int bmpdecoder(void *bmp_addr, void *pdst, int *width, int *height, int *bits)
 
        size = header.size - header.offset;
        linesize = *width * infoheader.bitcount >> 3;
+       cmap_base = src + sizeof(infoheader);
        src = bmp_addr + header.offset;
 
        switch (infoheader.bitcount) {
        case 8:
+               bmp_logo_palette = kmalloc(sizeof(bmp_logo_palette) * 256, GFP_KERNEL);
+
+               /* Set color map */
+               for (i = 0; i < 256; i++) {
+                       ushort colreg = ((cmap_base[2] << 8) & 0xf800) |
+                                       ((cmap_base[1] << 3) & 0x07e0) |
+                                       ((cmap_base[0] >> 3) & 0x001f) ;
+                       cmap_base += 4;
+                       bmp_logo_palette[i] = colreg;
+               }
+
                /*
                 * only support convert 8bit bmap file to RGB565.
                 */
                decode_rle8_bitmap(src, dst, bmp_logo_palette,
                                   infoheader.width, infoheader.height,
                                   infoheader.bitcount, 0, 0, flip);
+               kfree(bmp_logo_palette);
                *bits = 16;
                break;
        case 16: