diff options
Diffstat (limited to 'miscutils/fbsplash.c')
-rw-r--r-- | miscutils/fbsplash.c | 99 |
1 files changed, 83 insertions, 16 deletions
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 51ba4729e..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; |
@@ -213,14 +272,15 @@ static void fb_drawfullrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos, | |||
213 | */ | 272 | */ |
214 | static void fb_drawprogressbar(unsigned percent) | 273 | static void fb_drawprogressbar(unsigned percent) |
215 | { | 274 | { |
216 | int i, left_x, top_y, width, height; | 275 | int left_x, top_y, pos_x; |
276 | unsigned width, height; | ||
217 | 277 | ||
218 | // outer box | 278 | // outer box |
219 | left_x = G.nbar_posx; | 279 | left_x = G.nbar_posx; |
220 | top_y = G.nbar_posy; | 280 | top_y = G.nbar_posy; |
221 | width = G.nbar_width - 1; | 281 | width = G.nbar_width - 1; |
222 | height = G.nbar_height - 1; | 282 | height = G.nbar_height - 1; |
223 | if ((height | width) < 0) | 283 | if ((int)(height | width) < 0) |
224 | return; | 284 | return; |
225 | // NB: "width" of 1 actually makes rect with width of 2! | 285 | // NB: "width" of 1 actually makes rect with width of 2! |
226 | fb_drawrectangle(); | 286 | fb_drawrectangle(); |
@@ -230,30 +290,37 @@ static void fb_drawprogressbar(unsigned percent) | |||
230 | top_y++; | 290 | top_y++; |
231 | width -= 2; | 291 | width -= 2; |
232 | height -= 2; | 292 | height -= 2; |
233 | if ((height | width) < 0) | 293 | if ((int)(height | width) < 0) |
234 | return; | 294 | return; |
235 | fb_drawfullrectangle( | ||
236 | left_x, top_y, | ||
237 | left_x + width, top_y + height, | ||
238 | G.nbar_colr, G.nbar_colg, G.nbar_colb); | ||
239 | 295 | ||
296 | pos_x = left_x; | ||
240 | if (percent > 0) { | 297 | if (percent > 0) { |
298 | int y; | ||
299 | unsigned i; | ||
300 | |||
241 | // actual progress bar | 301 | // actual progress bar |
242 | width = width * percent / 100; | 302 | pos_x += (unsigned)(width * percent) / 100; |
303 | |||
304 | y = top_y; | ||
243 | i = height; | 305 | i = height; |
244 | if (height == 0) | 306 | if (height == 0) |
245 | height++; // divide by 0 is bad | 307 | height++; // divide by 0 is bad |
246 | while (i >= 0) { | 308 | while (i >= 0) { |
247 | // draw one-line thick "rectangle" | 309 | // draw one-line thick "rectangle" |
248 | // top line will have gray lvl 200, bottom one 100 | 310 | // top line will have gray lvl 200, bottom one 100 |
249 | unsigned gray_level = 100 + i*100/height; | 311 | unsigned gray_level = 100 + i*100 / height; |
250 | fb_drawfullrectangle( | 312 | fb_drawfullrectangle( |
251 | left_x, top_y, left_x + width, top_y, | 313 | left_x, y, pos_x, y, |
252 | gray_level, gray_level, gray_level); | 314 | gray_level, gray_level, gray_level); |
253 | top_y++; | 315 | y++; |
254 | i--; | 316 | i--; |
255 | } | 317 | } |
256 | } | 318 | } |
319 | |||
320 | fb_drawfullrectangle( | ||
321 | pos_x, top_y, | ||
322 | left_x + width, top_y + height, | ||
323 | G.nbar_colr, G.nbar_colg, G.nbar_colb); | ||
257 | } | 324 | } |
258 | 325 | ||
259 | 326 | ||