[PATCH 2/2] fbsplash: support 8bit mode

Peter Korsgaard jacmet at sunsite.dk
Fri Oct 14 08:29:13 UTC 2011


Fake truecolor support using a RGB:332 palette.

function                                             old     new   delta
fb_setpal                                              -     212    +212
fbsplash_main                                       1136    1184     +48
fb_pixel_value                                        52      84     +32
fb_write_pixel                                        60      68      +8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 300/0)             Total: 300 bytes

Signed-off-by: Peter Korsgaard <jacmet at sunsite.dk>
---
 miscutils/fbsplash.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index 937c6a4..d9077c5 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -74,6 +74,33 @@ struct globals {
 #define DEBUG_MESSAGE(...) ((void)0)
 #endif
 
+/**
+ * Configure palette for RGB:332
+ */
+static void fb_setpal(int fd)
+{
+	struct fb_cmap cmap;
+	/* fb colors are 16 bit */
+	unsigned short red[256], green[256], blue[256];
+	int i;
+
+	/* RGB:332 */
+	for (i = 0; i < 256; i++)
+	{
+		red[i]   = ((i & 0xe0) << 8)  + ((i & 0x20) ? 0x1fff : 0);
+		green[i] = ((i & 0x1c) << 11) + ((i & 0x04) ? 0x1fff : 0);
+		blue[i]  = ((i & 0x03) << 14) + ((i & 0x01) ? 0x3fff : 0);
+	}
+
+	cmap.start = 0;
+	cmap.len   = 256;
+	cmap.red   = red;
+	cmap.green = green;
+	cmap.blue  = blue;
+	cmap.transp = 0;
+
+	xioctl(fd, FBIOPUTCMAP, &cmap);
+}
 
 /**
  * Open and initialize the framebuffer device
@@ -87,8 +114,21 @@ static void fb_open(const char *strfb_device)
 	xioctl(fbfd, FBIOGET_VSCREENINFO, &G.scr_var);
 	xioctl(fbfd, FBIOGET_FSCREENINFO, &G.scr_fix);
 
-	if (G.scr_var.bits_per_pixel < 16 || G.scr_var.bits_per_pixel > 32)
+	switch (G.scr_var.bits_per_pixel) {
+	case 8:
+		fb_setpal(fbfd);
+		break;
+
+	case 16:
+	case 24:
+	case 32:
+		break;
+
+	default:
 		bb_error_msg_and_die("unsupported %u bpp", (int)G.scr_var.bits_per_pixel);
+		break;
+	}
+
 	G.bytes_per_pixel = (G.scr_var.bits_per_pixel + 7) >> 3;
 
 	// map the device in memory
@@ -109,6 +149,13 @@ static void fb_open(const char *strfb_device)
  */
 static unsigned fb_pixel_value(unsigned r, unsigned g, unsigned b)
 {
+	if (G.bytes_per_pixel == 1) {
+		r >>= 5;  // 3-bit red
+		g >>= 5;  // 3-bit green
+		b >>= 6;  // 2-bit blue
+		return b + (g << 2) + (r << (2+3));
+	}
+
 	if (G.bytes_per_pixel == 2) {
 		r >>= 3;  // 5-bit red
 		g >>= 2;  // 6-bit green
@@ -125,6 +172,9 @@ static unsigned fb_pixel_value(unsigned r, unsigned g, unsigned b)
 static void fb_write_pixel(unsigned char *addr, unsigned pixel)
 {
 	switch (G.bytes_per_pixel) {
+	case 1:
+		*addr = pixel;
+		break;
 	case 2:
 		*(uint16_t *)addr = pixel;
 		break;
-- 
1.7.6.3



More information about the busybox mailing list