+#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
+
+#define FILL_8BIT_332RGB(r,g,b) { \
+ *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
+ fb ++; \
+}
+
+#define FILL_15BIT_555RGB(r,g,b) { \
+ *(unsigned short *)fb = SWAP16((unsigned short)(((r>>3)<<10) | ((g>>3)<<5) | (b>>3))); \
+ fb += 2; \
+}
+
+#define FILL_16BIT_565RGB(r,g,b) { \
+ *(unsigned short *)fb = SWAP16((unsigned short)((((r)>>3)<<11) | (((g)>>2)<<5) | ((b)>>3))); \
+ fb += 2; \
+}
+
+#define FILL_32BIT_X888RGB(r,g,b) { \
+ *(unsigned long *)fb = SWAP32((unsigned long)(((r<<16) | (g<<8) | b))); \
+ fb += 4; \
+}
+
+#ifdef VIDEO_FB_LITTLE_ENDIAN
+#define FILL_24BIT_888RGB(r,g,b) { \
+ fb[0] = b; \
+ fb[1] = g; \
+ fb[2] = r; \
+ fb += 3; \
+}
+#else
+#define FILL_24BIT_888RGB(r,g,b) { \
+ fb[0] = r; \
+ fb[1] = g; \
+ fb[2] = b; \
+ fb += 3; \
+}
+#endif
+
+
+/*
+ * Display the BMP file located at address bmp_image.
+ * Only uncompressed
+ */
+int video_display_bitmap (ulong bmp_image, int x, int y)
+{
+ ushort xcount, ycount;
+ uchar *fb;
+ bmp_image_t *bmp = (bmp_image_t *) bmp_image;
+ uchar *bmap;
+ ushort padded_line;
+ unsigned long width, height, bpp;
+ unsigned colors;
+ unsigned long compression;
+ bmp_color_table_entry_t cte;
+#ifdef CONFIG_VIDEO_BMP_GZIP
+ unsigned char *dst = NULL;
+ ulong len;
+#endif
+
+ WATCHDOG_RESET ();
+
+ if (!((bmp->header.signature[0] == 'B') &&
+ (bmp->header.signature[1] == 'M'))) {
+
+#ifdef CONFIG_VIDEO_BMP_GZIP
+ /*
+ * Could be a gzipped bmp image, try to decrompress...
+ */
+ len = CFG_VIDEO_LOGO_MAX_SIZE;
+ dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE);
+ if (dst == NULL) {
+ printf("Error: malloc in gunzip failed!\n");
+ return(1);
+ }
+ if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)bmp_image, &len) != 0) {
+ printf ("Error: no valid bmp or bmp.gz image at %lx\n", bmp_image);
+ free(dst);
+ return 1;
+ }
+ if (len == CFG_VIDEO_LOGO_MAX_SIZE) {
+ printf("Image could be truncated (increase CFG_VIDEO_LOGO_MAX_SIZE)!\n");
+ }
+
+ /*
+ * Set addr to decompressed image
+ */
+ bmp = (bmp_image_t *)dst;
+
+ if (!((bmp->header.signature[0] == 'B') &&
+ (bmp->header.signature[1] == 'M'))) {
+ printf ("Error: no valid bmp.gz image at %lx\n", bmp_image);
+ return 1;
+ }
+#else
+ printf ("Error: no valid bmp image at %lx\n", bmp_image);
+ return 1;
+#endif /* CONFIG_VIDEO_BMP_GZIP */
+ }
+
+ width = le32_to_cpu (bmp->header.width);
+ height = le32_to_cpu (bmp->header.height);
+ bpp = le16_to_cpu (bmp->header.bit_count);
+ colors = le32_to_cpu (bmp->header.colors_used);
+ compression = le32_to_cpu (bmp->header.compression);
+
+ debug ("Display-bmp: %d x %d with %d colors\n",
+ width, height, colors);
+
+ if (compression != BMP_BI_RGB) {
+ printf ("Error: compression type %ld not supported\n",
+ compression);
+ return 1;
+ }
+
+ padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
+
+ if ((x + width) > VIDEO_VISIBLE_COLS)
+ width = VIDEO_VISIBLE_COLS - x;
+ if ((y + height) > VIDEO_VISIBLE_ROWS)
+ height = VIDEO_VISIBLE_ROWS - y;
+
+ bmap = (uchar *) bmp + le32_to_cpu (bmp->header.data_offset);
+ fb = (uchar *) (video_fb_address +
+ ((y + height - 1) * VIDEO_COLS * VIDEO_PIXEL_SIZE) +
+ x * VIDEO_PIXEL_SIZE);
+
+ /* We handle only 8bpp or 24 bpp bitmap */
+ switch (le16_to_cpu (bmp->header.bit_count)) {
+ case 8:
+ padded_line -= width;
+ if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
+ /* Copy colormap */
+ for (xcount = 0; xcount < colors; ++xcount) {
+ cte = bmp->color_table[xcount];
+ video_set_lut (xcount, cte.red, cte.green, cte.blue);
+ }
+ }
+ ycount = height;
+ switch (VIDEO_DATA_FORMAT) {
+ case GDF__8BIT_INDEX:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ *fb++ = *bmap++;
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF__8BIT_332RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ cte = bmp->color_table[*bmap++];
+ FILL_8BIT_332RGB (cte.red, cte.green, cte.blue);
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF_15BIT_555RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ cte = bmp->color_table[*bmap++];
+ FILL_15BIT_555RGB (cte.red, cte.green, cte.blue);
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF_16BIT_565RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ cte = bmp->color_table[*bmap++];
+ FILL_16BIT_565RGB (cte.red, cte.green, cte.blue);
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF_32BIT_X888RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ cte = bmp->color_table[*bmap++];
+ FILL_32BIT_X888RGB (cte.red, cte.green, cte.blue);
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF_24BIT_888RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ cte = bmp->color_table[*bmap++];
+ FILL_24BIT_888RGB (cte.red, cte.green, cte.blue);
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ }
+ break;
+ case 24:
+ padded_line -= 3 * width;
+ ycount = height;
+ switch (VIDEO_DATA_FORMAT) {
+ case GDF__8BIT_332RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ FILL_8BIT_332RGB (bmap[2], bmap[1], bmap[0]);
+ bmap += 3;
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF_15BIT_555RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ FILL_15BIT_555RGB (bmap[2], bmap[1], bmap[0]);
+ bmap += 3;
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF_16BIT_565RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ FILL_16BIT_565RGB (bmap[2], bmap[1], bmap[0]);
+ bmap += 3;
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF_32BIT_X888RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ FILL_32BIT_X888RGB (bmap[2], bmap[1], bmap[0]);
+ bmap += 3;
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ case GDF_24BIT_888RGB:
+ while (ycount--) {
+ WATCHDOG_RESET ();
+ xcount = width;
+ while (xcount--) {
+ FILL_24BIT_888RGB (bmap[2], bmap[1], bmap[0]);
+ bmap += 3;
+ }
+ bmap += padded_line;
+ fb -= (VIDEO_VISIBLE_COLS + width) * VIDEO_PIXEL_SIZE;
+ }
+ break;
+ default:
+ printf ("Error: 24 bits/pixel bitmap incompatible with current video mode\n");
+ break;
+ }
+ break;
+ default:
+ printf ("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
+ le16_to_cpu (bmp->header.bit_count));
+ break;
+ }
+
+#ifdef CONFIG_VIDEO_BMP_GZIP
+ if (dst) {
+ free(dst);
+ }
+#endif
+
+ return (0);
+}
+#endif
+
+/*****************************************************************************/
+