[U-Boot-Users] [PATCH] color map 565 support

Rodolfo Giometti giometti at linux.it
Wed Jul 12 11:53:55 CEST 2006


Hello,

here a patch to add color map 565 support.

The main trick is to modify the tool "tools/bmp_logo.c" in such a way
to save full color map (8bits for red, green and blue) into
bmp_logo_palette[] vector and then convert the color map to 444 or 565
as defined by CFG_LOGO_CMAP_MODE define.

Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    giometti at enneenne.com
Linux Device Driver                             giometti at gnudd.com
Embedded Systems                     		giometti at linux.it
UNIX programming                     phone:     +39 349 2432127
-------------- next part --------------
diff --git a/README b/README
index 9c1905e..a145086 100644
--- a/README
+++ b/README
@@ -2184,6 +2184,10 @@ Low Level (hardware related) configurati
   CFG_POCMR2_MASK_ATTRIB: (MPC826x only)
 		Overrides the default PCI memory map in cpu/mpc8260/pci.c if set.
 
+- CFG_LOGO_CMAP_MODE
+		Define the current LCD color map mode. Default value is 444 but
+		565 can also be used.
+
 - CONFIG_ETHER_ON_FEC[12]
 		Define to enable FEC[12] on a 8xx series processor.
 
diff --git a/common/lcd.c b/common/lcd.c
index f6065f8..7750cbf 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -52,6 +52,10 @@ #endif
 
 #ifdef CONFIG_LCD
 
+#ifndef CFG_LOGO_CMAP_MODE
+#define CFG_LOGO_CMAP_MODE	444	/* the default */
+#endif
+
 /************************************************************************/
 /* ** FONT DATA								*/
 /************************************************************************/
@@ -526,10 +530,11 @@ #elif defined(CONFIG_MPC823)
 #elif defined(CONFIG_AU1X00)
 	uint *cmap;
 #endif
+	uint palette;
 
 	debug ("Logo: width %d  height %d  colors %d  cmap %d\n",
 		BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
-		sizeof(bmp_logo_palette)/(sizeof(ushort)));
+		sizeof(bmp_logo_palette)/(sizeof(uint)));
 
 	bmap = &bmp_logo_bitmap[0];
 	fb   = (uchar *)(lcd_base + y * lcd_line_length + x);
@@ -547,8 +552,20 @@ #endif
 		WATCHDOG_RESET();
 
 		/* Set color map */
-		for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(ushort))); ++i) {
-			ushort colreg = bmp_logo_palette[i];
+		for (i=0; i<(sizeof(bmp_logo_palette)/(sizeof(uint))); ++i) {
+			palette = bmp_logo_palette[i];
+#if CFG_LOGO_CMAP_MODE == 444
+			ushort colreg = ((palette & 0xf00000)>>12) | \
+					((palette & 0x00f000)>>8)  | \
+					((palette & 0x0000f0)>>4);
+#elif CFG_LOGO_CMAP_MODE == 565
+			ushort colreg = ((palette & 0xf80000)>>8) | \
+					((palette & 0x00fc00)>>5) | \
+					((palette & 0x0000f8)>>3);
+#else
+# error "Unsupported CMAP mode"
+#endif
+
 #ifdef  CFG_INVERT_COLORS
 			*cmap++ = 0xffff - colreg;
 #else
@@ -568,8 +585,18 @@ #endif
 		fb16 = (ushort *)(lcd_base + y * lcd_line_length + x);
 		for (i=0; i<BMP_LOGO_HEIGHT; ++i) {
 			for (j=0; j<BMP_LOGO_WIDTH; j++) {
-				fb16[j] = bmp_logo_palette[(bmap[j])];
+				palette = bmp_logo_palette[bmap[j]-BMP_LOGO_OFFSET];
+#if CFG_LOGO_CMAP_MODE == 444
+				fb16[j] = ((palette & 0xf00000)>>12) | \
+					  ((palette & 0x00f000)>>8)  | \
+					  ((palette & 0x0000f0)>>4);
+#elif CFG_LOGO_CMAP_MODE == 565
+				fb16[j] = ((palette & 0xf80000)>>8) | \
+					  ((palette & 0x00fc00)>>5) | \
+					  ((palette & 0x0000f8)>>3);
+#endif
 				}
+
 			bmap += BMP_LOGO_WIDTH;
 			fb16 += panel_info.vl_col;
 		}
diff --git a/tools/bmp_logo.c b/tools/bmp_logo.c
index 98be617..f54d259 100644
--- a/tools/bmp_logo.c
+++ b/tools/bmp_logo.c
@@ -14,7 +14,6 @@ #endif
 typedef struct bitmap_s {		/* bitmap description */
 	uint16_t width;
 	uint16_t height;
-	uint8_t	palette[256*3];
 	uint8_t	*data;
 } bitmap_t;
 
@@ -42,11 +41,12 @@ void skip_bytes (FILE *fp, int n)
 
 int main (int argc, char *argv[])
 {
-	int	i, x;
+	int	i, x, d;
 	FILE	*fp;
 	bitmap_t bmp;
 	bitmap_t *b = &bmp;
-	uint16_t data_offset, n_colors;
+	uint16_t data_offset, bit_count, n_colors;
+	uint32_t red, green, blue;
 
 	if (argc < 2) {
 		fprintf (stderr, "Usage: %s file\n", argv[0]);
@@ -73,7 +73,9 @@ int main (int argc, char *argv[])
 	fread (&b->width,   sizeof (uint16_t), 1, fp);
 	skip_bytes (fp, 2);
 	fread (&b->height,  sizeof (uint16_t), 1, fp);
-	skip_bytes (fp, 22);
+	skip_bytes (fp, 4);
+	fread (&bit_count,  sizeof (uint16_t), 1, fp);
+	skip_bytes (fp, 16);
 	fread (&n_colors, sizeof (uint16_t), 1, fp);
 	skip_bytes (fp, 6);
 
@@ -83,10 +85,20 @@ int main (int argc, char *argv[])
 	data_offset = le_short(data_offset);
 	b->width = le_short(b->width);
 	b->height = le_short(b->height);
+	bit_count = le_short(bit_count);
 	n_colors = le_short(n_colors);
 
-	/* assume we are working with an 8-bit file */
-	if ((n_colors == 0) || (n_colors > 256 - DEFAULT_CMAP_SIZE)) {
+	/*
+	 * Sanity checks.
+	 */
+	if (bit_count != 8) {
+		fprintf (stderr, "%s is not a 8bpp image.\n", argv[1]);
+		exit (EXIT_FAILURE);
+	}
+
+	if (n_colors == 0)
+		n_colors = 1 << bit_count;
+	if (n_colors > 256 - DEFAULT_CMAP_SIZE) {
 		/* reserve DEFAULT_CMAP_SIZE color map entries for default map */
 		n_colors = 256 - DEFAULT_CMAP_SIZE;
 	}
@@ -115,25 +127,26 @@ int main (int argc, char *argv[])
 	}
 
 	/* read and print the palette information */
-	printf ("unsigned short bmp_logo_palette[] = {\n");
+	printf ("unsigned int bmp_logo_palette[] = {\n");
 
 	for (i=0; i<n_colors; ++i) {
-		b->palette[(int)(i*3+2)] = fgetc(fp);
-		b->palette[(int)(i*3+1)] = fgetc(fp);
-		b->palette[(int)(i*3+0)] = fgetc(fp);
-		x=fgetc(fp);
+		blue  = fgetc(fp);
+		green = fgetc(fp);
+		red   = fgetc(fp);
+		x     = fgetc(fp);
 
-		printf ("%s0x0%X%X%X,%s",
+		printf ("%s0x%06X,%s",
 			((i%8) == 0) ? "\t" : "  ",
-			(b->palette[(int)(i*3+0)] >> 4) & 0x0F,
-			(b->palette[(int)(i*3+1)] >> 4) & 0x0F,
-			(b->palette[(int)(i*3+2)] >> 4) & 0x0F,
+			(red<<16) | (green<<8) | blue,
 			((i%8) == 7) ? "\n" : ""
 		);
 	}
 
 	/* seek to offset indicated by file header */
-	fseek(fp, (long)data_offset, SEEK_SET);
+	if (fseek(fp, (long)data_offset, SEEK_SET) < 0) {
+		printf ("cannot fseek!\n");
+		exit (EXIT_FAILURE);
+	}
 
 	/* read the bitmap; leave room for default color map */
 	printf ("\n");
@@ -142,8 +155,13 @@ int main (int argc, char *argv[])
 	printf ("unsigned char bmp_logo_bitmap[] = {\n");
 	for (i=(b->height-1)*b->width; i>=0; i-=b->width) {
 		for (x = 0; x < b->width; x++) {
-			b->data[(uint16_t) i + x] = (uint8_t) fgetc (fp) \
-						+ DEFAULT_CMAP_SIZE;
+			d = fgetc (fp);
+			if (feof(fp)) {
+				printf ("unaspected end-of-file!\n");
+				exit (EXIT_FAILURE);
+			}
+
+			*(b->data + i + x) = d + DEFAULT_CMAP_SIZE;
 		}
 	}
 	fclose (fp);
@@ -152,7 +170,7 @@ int main (int argc, char *argv[])
 		if ((i%8) == 0)
 			putchar ('\t');
 		printf ("0x%02X,%c",
-			b->data[i],
+			*(b->data + i),
 			((i%8) == 7) ? '\n' : ' '
 		);
 	}


More information about the U-Boot mailing list