summaryrefslogtreecommitdiff
path: root/apps/recorder/bmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder/bmp.c')
-rw-r--r--apps/recorder/bmp.c91
1 files changed, 65 insertions, 26 deletions
diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c
index 86c057a907..01b57d2116 100644
--- a/apps/recorder/bmp.c
+++ b/apps/recorder/bmp.c
@@ -42,7 +42,9 @@
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44#include "inttypes.h" 44#include "inttypes.h"
45#ifndef PLUGIN
45#include "debug.h" 46#include "debug.h"
47#endif
46#include "lcd.h" 48#include "lcd.h"
47#include "file.h" 49#include "file.h"
48#ifdef HAVE_REMOTE_LCD 50#ifdef HAVE_REMOTE_LCD
@@ -58,7 +60,6 @@
58#include "system.h" 60#include "system.h"
59#include "bmp.h" 61#include "bmp.h"
60#include "resize.h" 62#include "resize.h"
61#include "debug.h"
62#else 63#else
63#undef DEBUGF 64#undef DEBUGF
64#define DEBUGF(...) 65#define DEBUGF(...)
@@ -71,6 +72,19 @@
71#pragma pack (push, 2) 72#pragma pack (push, 2)
72#endif 73#endif
73 74
75#ifndef PLUGIN
76#define API(x) x
77#else
78#define API(x) rb->x
79
80static const struct plugin_api *rb;
81
82void bmp_init(const struct plugin_api * api)
83{
84 rb = api;
85}
86#endif
87
74/* BMP header structure */ 88/* BMP header structure */
75struct bmp_header { 89struct bmp_header {
76 uint16_t type; /* signature - 'BM' */ 90 uint16_t type; /* signature - 'BM' */
@@ -123,13 +137,15 @@ static const struct uint8_rgb bitfields[3][3] = {
123 }, 137 },
124}; 138};
125 139
126#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) 140#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) || \
141 defined(PLUGIN)
127/* the full 16x16 Bayer dither matrix may be calculated quickly with this table 142/* the full 16x16 Bayer dither matrix may be calculated quickly with this table
128*/ 143*/
129const unsigned char dither_table[16] = 144const unsigned char dither_table[16] =
130 { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }; 145 { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 };
131#endif 146#endif
132 147
148#ifndef PLUGIN
133#if ((LCD_DEPTH == 2) && (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)) \ 149#if ((LCD_DEPTH == 2) && (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)) \
134 || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH == 2) \ 150 || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH == 2) \
135 && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED)) 151 && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED))
@@ -137,6 +153,7 @@ const unsigned short vi_pattern[4] = {
137 0x0101, 0x0100, 0x0001, 0x0000 153 0x0101, 0x0100, 0x0001, 0x0000
138}; 154};
139#endif 155#endif
156#endif
140 157
141/****************************************************************************** 158/******************************************************************************
142 * read_bmp_file() 159 * read_bmp_file()
@@ -151,7 +168,7 @@ int read_bmp_file(const char* filename,
151 const struct custom_format *cformat) 168 const struct custom_format *cformat)
152{ 169{
153 int fd, ret; 170 int fd, ret;
154 fd = open(filename, O_RDONLY); 171 fd = API(open)(filename, O_RDONLY);
155 172
156 /* Exit if file opening failed */ 173 /* Exit if file opening failed */
157 if (fd < 0) { 174 if (fd < 0) {
@@ -163,7 +180,7 @@ int read_bmp_file(const char* filename,
163 filename, !!(format & FORMAT_REMOTE), !!(format & FORMAT_RESIZE), 180 filename, !!(format & FORMAT_REMOTE), !!(format & FORMAT_RESIZE),
164 !!(format & FORMAT_KEEP_ASPECT)); 181 !!(format & FORMAT_KEEP_ASPECT));
165 ret = read_bmp_fd(fd, bm, maxsize, format, cformat); 182 ret = read_bmp_fd(fd, bm, maxsize, format, cformat);
166 close(fd); 183 API(close)(fd);
167 return ret; 184 return ret;
168} 185}
169 186
@@ -182,7 +199,8 @@ struct bmp_args {
182 short depth; 199 short depth;
183 unsigned char buf[BM_MAX_WIDTH * 4]; 200 unsigned char buf[BM_MAX_WIDTH * 4];
184 struct uint8_rgb *palette; 201 struct uint8_rgb *palette;
185#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 202#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
203 defined(PLUGIN)
186 int cur_row; 204 int cur_row;
187 int cur_col; 205 int cur_col;
188 struct img_part part; 206 struct img_part part;
@@ -195,7 +213,8 @@ static unsigned int read_part_line(struct bmp_args *ba)
195 const int read_width = ba->read_width; 213 const int read_width = ba->read_width;
196 const int width = ba->width; 214 const int width = ba->width;
197 const int depth = ba->depth; 215 const int depth = ba->depth;
198#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 216#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
217 defined(PLUGIN)
199 int cur_row = ba->cur_row; 218 int cur_row = ba->cur_row;
200 int cur_col = ba->cur_col; 219 int cur_col = ba->cur_col;
201#endif 220#endif
@@ -207,7 +226,8 @@ static unsigned int read_part_line(struct bmp_args *ba)
207 int ret; 226 int ret;
208 int i, cols, len; 227 int i, cols, len;
209 228
210#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) 229#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) || \
230 defined(PLUGIN)
211 cols = MIN(width - cur_col,(int)BM_MAX_WIDTH); 231 cols = MIN(width - cur_col,(int)BM_MAX_WIDTH);
212 BDEBUGF("reading %d cols (width: %d, max: %d)\n",cols,width,BM_MAX_WIDTH); 232 BDEBUGF("reading %d cols (width: %d, max: %d)\n",cols,width,BM_MAX_WIDTH);
213 len = (cols * (depth == 15 ? 16 : depth) + 7) >> 3; 233 len = (cols * (depth == 15 ? 16 : depth) + 7) >> 3;
@@ -217,13 +237,16 @@ static unsigned int read_part_line(struct bmp_args *ba)
217#endif 237#endif
218 ibuf = ((unsigned char *)buf) + (BM_MAX_WIDTH << 2) - len; 238 ibuf = ((unsigned char *)buf) + (BM_MAX_WIDTH << 2) - len;
219 BDEBUGF("read_part_line: cols=%d len=%d\n",cols,len); 239 BDEBUGF("read_part_line: cols=%d len=%d\n",cols,len);
220 ret = read(fd, ibuf, len); 240 ret = API(read)(fd, ibuf, len);
221 if (ret != len) 241 if (ret != len)
222 { 242 {
223 DEBUGF("read_part_line: error reading image, read returned %d " 243 DEBUGF("read_part_line: error reading image, read returned %d "
224 "expected %d\n", ret, len); 244 "expected %d\n", ret, len);
245#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) || \
246 defined(PLUGIN)
225 BDEBUGF("cur_row: %d cur_col: %d cols: %d len: %d\n", cur_row, cur_col, 247 BDEBUGF("cur_row: %d cur_col: %d cols: %d len: %d\n", cur_row, cur_col,
226 cols, len); 248 cols, len);
249#endif
227 return 0; 250 return 0;
228 } 251 }
229 while (ibuf < ba->buf + (BM_MAX_WIDTH << 2)) 252 while (ibuf < ba->buf + (BM_MAX_WIDTH << 2))
@@ -282,15 +305,17 @@ static unsigned int read_part_line(struct bmp_args *ba)
282 } 305 }
283 } 306 }
284 307
285#if !defined(HAVE_LCD_COLOR) && \ 308#if (!defined(HAVE_LCD_COLOR) && \
286 (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) 309 (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1))) || \
310 defined(PLUGIN)
287 ibuf = ba->buf; 311 ibuf = ba->buf;
288 buf = (struct uint8_rgb*)ba->buf; 312 buf = (struct uint8_rgb*)ba->buf;
289 while (ibuf < ba->buf + cols) 313 while (ibuf < ba->buf + cols)
290 *ibuf++ = brightness(*buf++); 314 *ibuf++ = brightness(*buf++);
291#endif 315#endif
292 316
293#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 317#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
318 defined(PLUGIN)
294 cur_col += cols; 319 cur_col += cols;
295 if (cur_col == width) 320 if (cur_col == width)
296 { 321 {
@@ -299,9 +324,10 @@ static unsigned int read_part_line(struct bmp_args *ba)
299 if (pad > 0) 324 if (pad > 0)
300 { 325 {
301 BDEBUGF("seeking %d bytes to next line\n",pad); 326 BDEBUGF("seeking %d bytes to next line\n",pad);
302 lseek(fd, pad, SEEK_CUR); 327 API(lseek)(fd, pad, SEEK_CUR);
303 } 328 }
304#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 329#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
330 defined(PLUGIN)
305 cur_col = 0; 331 cur_col = 0;
306 BDEBUGF("read_part_line: completed row %d\n", cur_row); 332 BDEBUGF("read_part_line: completed row %d\n", cur_row);
307 cur_row += 1; 333 cur_row += 1;
@@ -313,7 +339,8 @@ static unsigned int read_part_line(struct bmp_args *ba)
313 return cols; 339 return cols;
314} 340}
315 341
316#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 342#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
343 defined(PLUGIN)
317static struct img_part *store_part_bmp(void *args) 344static struct img_part *store_part_bmp(void *args)
318{ 345{
319 struct bmp_args *ba = (struct bmp_args *)args; 346 struct bmp_args *ba = (struct bmp_args *)args;
@@ -363,13 +390,14 @@ int read_bmp_fd(int fd,
363 struct uint8_rgb palette[256]; 390 struct uint8_rgb palette[256];
364 struct rowset rset; 391 struct rowset rset;
365 struct dim src_dim; 392 struct dim src_dim;
366#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) 393#if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) \
367 bool remote = false; 394 || defined(PLUGIN)
368 unsigned int resize = IMG_NORESIZE; 395 unsigned int resize = IMG_NORESIZE;
369 bool dither = false; 396 bool dither = false;
370 bool transparent = false; 397 bool transparent = false;
371 398
372#ifdef HAVE_REMOTE_LCD 399#ifdef HAVE_REMOTE_LCD
400 bool remote = false;
373 if (format & FORMAT_REMOTE) { 401 if (format & FORMAT_REMOTE) {
374 remote = true; 402 remote = true;
375#if LCD_REMOTE_DEPTH == 1 403#if LCD_REMOTE_DEPTH == 1
@@ -394,7 +422,7 @@ int read_bmp_fd(int fd,
394#endif /*(LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)*/ 422#endif /*(LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)*/
395 423
396 /* read fileheader */ 424 /* read fileheader */
397 ret = read(fd, &bmph, sizeof(struct bmp_header)); 425 ret = API(read)(fd, &bmph, sizeof(struct bmp_header));
398 if (ret < 0) { 426 if (ret < 0) {
399 return ret * 10 - 2; 427 return ret * 10 - 2;
400 } 428 }
@@ -433,14 +461,17 @@ int read_bmp_fd(int fd,
433 { 461 {
434 resize &= ~IMG_RESIZE; 462 resize &= ~IMG_RESIZE;
435 resize |= IMG_NORESIZE; 463 resize |= IMG_NORESIZE;
464#ifdef HAVE_REMOTE_LCD
436 remote = 0; 465 remote = 0;
466#endif
437 } 467 }
438#else 468#elif !defined(PLUGIN)
439 if (src_dim.width > BM_MAX_WIDTH) 469 if (src_dim.width > BM_MAX_WIDTH)
440 return -6; 470 return -6;
441#endif /*(LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)*/ 471#endif /*(LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)*/
442 472
443#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 473#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
474 defined(PLUGIN)
444 if (resize & IMG_RESIZE) { 475 if (resize & IMG_RESIZE) {
445 if(format & FORMAT_KEEP_ASPECT) { 476 if(format & FORMAT_KEEP_ASPECT) {
446 /* keep aspect ratio.. */ 477 /* keep aspect ratio.. */
@@ -463,7 +494,8 @@ int read_bmp_fd(int fd,
463 bm->width = src_dim.width; 494 bm->width = src_dim.width;
464 bm->height = src_dim.height; 495 bm->height = src_dim.height;
465 496
466#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 497#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
498 defined(PLUGIN)
467 } 499 }
468#endif 500#endif
469 501
@@ -499,7 +531,7 @@ int read_bmp_fd(int fd,
499 int i; 531 int i;
500 union rgb_union pal; 532 union rgb_union pal;
501 for (i = 0; i < numcolors; i++) { 533 for (i = 0; i < numcolors; i++) {
502 if (read(fd, &pal, sizeof(pal)) != (int)sizeof(pal)) 534 if (API(read)(fd, &pal, sizeof(pal)) != (int)sizeof(pal))
503 { 535 {
504 DEBUGF("read_bmp_fd: Can't read color palette\n"); 536 DEBUGF("read_bmp_fd: Can't read color palette\n");
505 return -7; 537 return -7;
@@ -557,20 +589,24 @@ int read_bmp_fd(int fd,
557 } 589 }
558 590
559 /* Search to the beginning of the image data */ 591 /* Search to the beginning of the image data */
560 lseek(fd, (off_t)letoh32(bmph.off_bits), SEEK_SET); 592 API(lseek)(fd, (off_t)letoh32(bmph.off_bits), SEEK_SET);
561 593
562 memset(bitmap, 0, totalsize); 594 API(memset)(bitmap, 0, totalsize);
563 595
564 struct bmp_args ba = { 596 struct bmp_args ba = {
565 .fd = fd, .padded_width = padded_width, .read_width = read_width, 597 .fd = fd, .padded_width = padded_width, .read_width = read_width,
566 .width = src_dim.width, .depth = depth, .palette = palette, 598 .width = src_dim.width, .depth = depth, .palette = palette,
567#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 599#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
600 defined(PLUGIN)
568 .cur_row = 0, .cur_col = 0, .part = {0,0} 601 .cur_row = 0, .cur_col = 0, .part = {0,0}
569#endif 602#endif
570 }; 603 };
571 604
572#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) 605#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
606 defined(PLUGIN)
607#if LCD_DEPTH > 1
573 if (resize || cformat) 608 if (resize || cformat)
609#endif
574 { 610 {
575 if (resize_on_load(bm, dither, &src_dim, &rset, 611 if (resize_on_load(bm, dither, &src_dim, &rset,
576 bitmap + totalsize, maxsize - totalsize, 612 bitmap + totalsize, maxsize - totalsize,
@@ -579,10 +615,12 @@ int read_bmp_fd(int fd,
579 else 615 else
580 return 0; 616 return 0;
581 } 617 }
582 618#ifndef PLUGIN
583 int fb_width = BM_WIDTH(bm->width,bm->format,remote); 619 int fb_width = BM_WIDTH(bm->width,bm->format,remote);
620#endif
584#endif /* LCD_DEPTH */ 621#endif /* LCD_DEPTH */
585 622
623#ifndef PLUGIN
586 int col, row; 624 int col, row;
587 625
588 /* loop to read rows and put them to buffer */ 626 /* loop to read rows and put them to buffer */
@@ -718,4 +756,5 @@ int read_bmp_fd(int fd,
718 } 756 }
719 } 757 }
720 return totalsize; /* return the used buffer size. */ 758 return totalsize; /* return the used buffer size. */
759#endif
721} 760}