diff options
| author | Peter Korsgaard <jacmet@sunsite.dk> | 2011-10-17 05:31:52 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-10-17 05:31:52 +0200 |
| commit | cd06e06eee3ef89e45b60d7122e5518995c7f65e (patch) | |
| tree | 27856d2e966353f4d332dcb609f81d348eb1415c /miscutils | |
| parent | e4fa7b7965fd574cff2a6a9b877522d613804a38 (diff) | |
| download | busybox-w32-cd06e06eee3ef89e45b60d7122e5518995c7f65e.tar.gz busybox-w32-cd06e06eee3ef89e45b60d7122e5518995c7f65e.tar.bz2 busybox-w32-cd06e06eee3ef89e45b60d7122e5518995c7f65e.zip | |
fbsplash: support 8bit mode
Fake truecolor support using a RGB:332 palette.
function old new delta
fb_setpal - 172 +172
fbsplash_main 920 953 +33
fb_pixel_value 50 80 +30
fb_write_pixel 47 51 +4
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 239/0) Total: 239 bytes
Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/fbsplash.c | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index bc9ac8fe1..04d583df6 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c | |||
| @@ -74,6 +74,43 @@ struct globals { | |||
| 74 | #define DEBUG_MESSAGE(...) ((void)0) | 74 | #define DEBUG_MESSAGE(...) ((void)0) |
| 75 | #endif | 75 | #endif |
| 76 | 76 | ||
| 77 | /** | ||
| 78 | * Configure palette for RGB:332 | ||
| 79 | */ | ||
| 80 | static void fb_setpal(int fd) | ||
| 81 | { | ||
| 82 | struct fb_cmap cmap; | ||
| 83 | /* fb colors are 16 bit */ | ||
| 84 | unsigned short red[256], green[256], blue[256]; | ||
| 85 | unsigned i; | ||
| 86 | |||
| 87 | /* RGB:332 */ | ||
| 88 | for (i = 0; i < 256; i++) { | ||
| 89 | /* Color is encoded in pixel value as rrrgggbb. | ||
| 90 | * 3-bit color is mapped to 16-bit one as: | ||
| 91 | * 000 -> 00000000 00000000 | ||
| 92 | * 001 -> 00100100 10010010 | ||
| 93 | * ... | ||
| 94 | * 011 -> 01101101 10110110 | ||
| 95 | * 100 -> 10010010 01001001 | ||
| 96 | * ... | ||
| 97 | * 111 -> 11111111 11111111 | ||
| 98 | */ | ||
| 99 | red[i] = (( i >> 5 ) * 0x9249) >> 2; // rrr * 00 10010010 01001001 >> 2 | ||
| 100 | green[i] = (((i >> 2) & 0x7) * 0x9249) >> 2; // ggg * 00 10010010 01001001 >> 2 | ||
| 101 | /* 2-bit color is easier: */ | ||
| 102 | blue[i] = ( i & 0x3) * 0x5555; // bb * 01010101 01010101 | ||
| 103 | } | ||
| 104 | |||
| 105 | cmap.start = 0; | ||
| 106 | cmap.len = 256; | ||
| 107 | cmap.red = red; | ||
| 108 | cmap.green = green; | ||
| 109 | cmap.blue = blue; | ||
| 110 | cmap.transp = 0; | ||
| 111 | |||
| 112 | xioctl(fd, FBIOPUTCMAP, &cmap); | ||
| 113 | } | ||
| 77 | 114 | ||
| 78 | /** | 115 | /** |
| 79 | * Open and initialize the framebuffer device | 116 | * Open and initialize the framebuffer device |
| @@ -87,8 +124,21 @@ static void fb_open(const char *strfb_device) | |||
| 87 | xioctl(fbfd, FBIOGET_VSCREENINFO, &G.scr_var); | 124 | xioctl(fbfd, FBIOGET_VSCREENINFO, &G.scr_var); |
| 88 | xioctl(fbfd, FBIOGET_FSCREENINFO, &G.scr_fix); | 125 | xioctl(fbfd, FBIOGET_FSCREENINFO, &G.scr_fix); |
| 89 | 126 | ||
| 90 | if (G.scr_var.bits_per_pixel < 16 || G.scr_var.bits_per_pixel > 32) | 127 | switch (G.scr_var.bits_per_pixel) { |
| 128 | case 8: | ||
| 129 | fb_setpal(fbfd); | ||
| 130 | break; | ||
| 131 | |||
| 132 | case 16: | ||
| 133 | case 24: | ||
| 134 | case 32: | ||
| 135 | break; | ||
| 136 | |||
| 137 | default: | ||
| 91 | bb_error_msg_and_die("unsupported %u bpp", (int)G.scr_var.bits_per_pixel); | 138 | bb_error_msg_and_die("unsupported %u bpp", (int)G.scr_var.bits_per_pixel); |
| 139 | break; | ||
| 140 | } | ||
| 141 | |||
| 92 | G.bytes_per_pixel = (G.scr_var.bits_per_pixel + 7) >> 3; | 142 | G.bytes_per_pixel = (G.scr_var.bits_per_pixel + 7) >> 3; |
| 93 | 143 | ||
| 94 | // map the device in memory | 144 | // map the device in memory |
| @@ -109,11 +159,17 @@ static void fb_open(const char *strfb_device) | |||
| 109 | */ | 159 | */ |
| 110 | static unsigned fb_pixel_value(unsigned r, unsigned g, unsigned b) | 160 | static unsigned fb_pixel_value(unsigned r, unsigned g, unsigned b) |
| 111 | { | 161 | { |
| 162 | if (G.bytes_per_pixel == 1) { | ||
| 163 | r = r & 0xe0; // 3-bit red | ||
| 164 | g = (g >> 3) & 0x1c; // 3-bit green | ||
| 165 | b = b >> 6; // 2-bit blue | ||
| 166 | return r + g + b; | ||
| 167 | } | ||
| 112 | if (G.bytes_per_pixel == 2) { | 168 | if (G.bytes_per_pixel == 2) { |
| 113 | r >>= 3; // 5-bit red | 169 | r = (r & 0xf8) << 8; // 5-bit red |
| 114 | g >>= 2; // 6-bit green | 170 | g = (g & 0xfc) << 3; // 6-bit green |
| 115 | b >>= 3; // 5-bit blue | 171 | b = b >> 3; // 5-bit blue |
| 116 | return b + (g << 5) + (r << (5+6)); | 172 | return r + g + b; |
| 117 | } | 173 | } |
| 118 | // RGB 888 | 174 | // RGB 888 |
| 119 | return b + (g << 8) + (r << 16); | 175 | return b + (g << 8) + (r << 16); |
| @@ -125,6 +181,9 @@ static unsigned fb_pixel_value(unsigned r, unsigned g, unsigned b) | |||
| 125 | static void fb_write_pixel(unsigned char *addr, unsigned pixel) | 181 | static void fb_write_pixel(unsigned char *addr, unsigned pixel) |
| 126 | { | 182 | { |
| 127 | switch (G.bytes_per_pixel) { | 183 | switch (G.bytes_per_pixel) { |
| 184 | case 1: | ||
| 185 | *addr = pixel; | ||
| 186 | break; | ||
| 128 | case 2: | 187 | case 2: |
| 129 | *(uint16_t *)addr = pixel; | 188 | *(uint16_t *)addr = pixel; |
| 130 | break; | 189 | break; |
