diff options
Diffstat (limited to 'apps/recorder')
-rw-r--r-- | apps/recorder/bmp.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index 75165528e7..43afcc5e98 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c | |||
@@ -191,8 +191,11 @@ struct bmp_args { | |||
191 | struct img_part part; | 191 | struct img_part part; |
192 | #endif | 192 | #endif |
193 | /* as read_part_line() goes through the rows it'll set this to true | 193 | /* as read_part_line() goes through the rows it'll set this to true |
194 | * if it finds transparency. Initialize to false before calling */ | 194 | * if it finds transparency. Initialize to 0 before calling */ |
195 | bool alpha_detected; | 195 | int alpha_detected; |
196 | /* for checking transparency it checks the against the very first byte | ||
197 | * of the bitmap. Initalize to 0x80 before calling */ | ||
198 | unsigned char first_alpha_byte; | ||
196 | }; | 199 | }; |
197 | 200 | ||
198 | static unsigned int read_part_line(struct bmp_args *ba) | 201 | static unsigned int read_part_line(struct bmp_args *ba) |
@@ -238,6 +241,15 @@ static unsigned int read_part_line(struct bmp_args *ba) | |||
238 | return 0; | 241 | return 0; |
239 | } | 242 | } |
240 | 243 | ||
244 | /* detect if the image has useful alpha information. | ||
245 | * if all alpha bits are 0xff or 0x00 discard the information. | ||
246 | * if it has other bits, or is mixed with 0x00 and 0xff then interpret | ||
247 | * as alpha. assume no alpha until the opposite is proven. as mixed | ||
248 | * is alpha, compare to the first byte instead of 0xff and 0x00 separately | ||
249 | */ | ||
250 | if (depth == 32 && ba->first_alpha_byte == 0x80) | ||
251 | ba->first_alpha_byte = ibuf[3] ? 0xff : 0x0; | ||
252 | |||
241 | while (ibuf < ba->buf + (BM_MAX_WIDTH << 2)) | 253 | while (ibuf < ba->buf + (BM_MAX_WIDTH << 2)) |
242 | { | 254 | { |
243 | switch (depth) | 255 | switch (depth) |
@@ -283,13 +295,19 @@ static unsigned int read_part_line(struct bmp_args *ba) | |||
283 | buf++; | 295 | buf++; |
284 | ibuf += 2; | 296 | ibuf += 2; |
285 | break; | 297 | break; |
286 | case 32: | ||
287 | case 24: | 298 | case 24: |
288 | buf->blue = *ibuf++; | 299 | buf->blue = *ibuf++; |
289 | buf->green = *ibuf++; | 300 | buf->green = *ibuf++; |
290 | buf->red = *ibuf++; | 301 | buf->red = *ibuf++; |
291 | buf->alpha = (depth == 32) ? *ibuf++ : 0xff; | 302 | buf->alpha = 0xff; |
292 | if (buf->alpha != 0xff) ba->alpha_detected = true; | 303 | buf++; |
304 | break; | ||
305 | case 32: | ||
306 | buf->blue = *ibuf++; | ||
307 | buf->green = *ibuf++; | ||
308 | buf->red = *ibuf++; | ||
309 | buf->alpha = *ibuf++; | ||
310 | ba->alpha_detected |= (buf->alpha != ba->first_alpha_byte); | ||
293 | buf++; | 311 | buf++; |
294 | break; | 312 | break; |
295 | } | 313 | } |
@@ -732,7 +750,7 @@ int read_bmp_fd(int fd, | |||
732 | defined(HAVE_BMP_SCALING) || defined(PLUGIN) | 750 | defined(HAVE_BMP_SCALING) || defined(PLUGIN) |
733 | .cur_row = 0, .cur_col = 0, .part = {0,0}, | 751 | .cur_row = 0, .cur_col = 0, .part = {0,0}, |
734 | #endif | 752 | #endif |
735 | .alpha_detected = false, | 753 | .alpha_detected = false, .first_alpha_byte = 0x80, |
736 | }; | 754 | }; |
737 | 755 | ||
738 | #if (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) && \ | 756 | #if (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) && \ |