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

Denys Vlasenko vda.linux at googlemail.com
Mon Oct 17 03:34:04 UTC 2011


On Friday 14 October 2011 10:29, Peter Korsgaard wrote:
> 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);
> +	}

This doesn't map values entirely correctly.
How about this?

        /* RGB:332 */
        for (i = 0; i < 256; i++) {
                /* Color is encoded in pixel value as rrrgggbb.
                 * 3-bit color is mapped to 16-bit one as:
                 * 000 -> 00000000 00000000
                 * 001 -> 00100100 10010010
                 * ...
                 * 011 -> 01101101 10110110
                 * 100 -> 10010010 01001001
                 * ...
                 * 111 -> 11111111 11111111
                 */
                red[i]   = (( i >> 5       ) * 0x9249) >> 2; // rrr * 00 10010010 01001001 >> 2
                green[i] = (((i >> 2) & 0x7) * 0x9249) >> 2; // ggg * 00 10010010 01001001 >> 2
                /* 2-bit color is easier: */
                blue[i]  =  ( i       & 0x3) * 0x5555; // bb * 01010101 01010101
        }


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

((r >> 5) << 5) doesn't feel optimal.

> +	}


Applied both patches, thanks!
-- 
vda


More information about the busybox mailing list