summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-01-04 21:22:05 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-01-04 21:22:05 +0000
commit4eedc933572605e42f6f2fb00d099fe4a2075032 (patch)
tree4e623580b92763369fb824ec725a28b71f9272ef
parentb93874fefcb152f5e079366c6bf65df7ebf657fa (diff)
downloadrockbox-4eedc933572605e42f6f2fb00d099fe4a2075032.tar.gz
rockbox-4eedc933572605e42f6f2fb00d099fe4a2075032.zip
build a scaling-enabled bitmap loader in pluginlib for mono bitmap targets, and use it in the test greylib scaler plugin
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19671 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/lib/SOURCES4
-rw-r--r--apps/plugins/lib/bmp.c2
-rw-r--r--apps/plugins/lib/core_bmp.c24
-rw-r--r--apps/plugins/lib/core_resize.c24
-rw-r--r--apps/plugins/test_greylib_bitmap_scale.c19
-rw-r--r--apps/recorder/bmp.c91
-rw-r--r--apps/recorder/bmp.h10
-rw-r--r--apps/recorder/resize.c55
-rw-r--r--apps/recorder/resize.h9
9 files changed, 188 insertions, 50 deletions
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index d21f21af15..c8c1553dc8 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -4,6 +4,10 @@ fixedpoint.c
4playback_control.c 4playback_control.c
5rgb_hsv.c 5rgb_hsv.c
6#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) 6#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
7#if LCD_DEPTH == 1
8core_bmp.c
9core_resize.c
10#endif
7grey_core.c 11grey_core.c
8grey_draw.c 12grey_draw.c
9grey_parm.c 13grey_parm.c
diff --git a/apps/plugins/lib/bmp.c b/apps/plugins/lib/bmp.c
index a8ebbffc27..85e996c5e2 100644
--- a/apps/plugins/lib/bmp.c
+++ b/apps/plugins/lib/bmp.c
@@ -87,6 +87,8 @@ int save_bmp_file( char* filename, struct bitmap *bm, const struct plugin_api* r
87} 87}
88#endif 88#endif
89 89
90#include "../../recorder/bmp.c"
91
90/** 92/**
91 Very simple image scale from src to dst (nearest neighbour). 93 Very simple image scale from src to dst (nearest neighbour).
92 Source and destination dimensions are read from the struct bitmap. 94 Source and destination dimensions are read from the struct bitmap.
diff --git a/apps/plugins/lib/core_bmp.c b/apps/plugins/lib/core_bmp.c
new file mode 100644
index 0000000000..28d70b1bb8
--- /dev/null
+++ b/apps/plugins/lib/core_bmp.c
@@ -0,0 +1,24 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* This is a wrapper for the core bmp.c
11*
12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include <plugin.h>
23#include "../../recorder/bmp.c"
24
diff --git a/apps/plugins/lib/core_resize.c b/apps/plugins/lib/core_resize.c
new file mode 100644
index 0000000000..099d4079ed
--- /dev/null
+++ b/apps/plugins/lib/core_resize.c
@@ -0,0 +1,24 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* This is a wrapper for the core bmp.c
11*
12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include <plugin.h>
23#include "../../recorder/resize.c"
24
diff --git a/apps/plugins/test_greylib_bitmap_scale.c b/apps/plugins/test_greylib_bitmap_scale.c
index f8a7bb92cc..3d6f81f91e 100644
--- a/apps/plugins/test_greylib_bitmap_scale.c
+++ b/apps/plugins/test_greylib_bitmap_scale.c
@@ -22,6 +22,12 @@
22#include "plugin.h" 22#include "plugin.h"
23#include "lib/grey.h" 23#include "lib/grey.h"
24 24
25#if LCD_DEPTH == 1
26#define BMP_LOAD read_bmp_file
27#else
28#define BMP_LOAD rb->read_bmp_file
29#endif
30
25PLUGIN_HEADER 31PLUGIN_HEADER
26GREY_INFO_STRUCT 32GREY_INFO_STRUCT
27static unsigned char grey_bm_buf[LCD_WIDTH * LCD_HEIGHT + 33static unsigned char grey_bm_buf[LCD_WIDTH * LCD_HEIGHT +
@@ -30,6 +36,8 @@ static unsigned char grey_display_buf[2*LCD_WIDTH * LCD_HEIGHT];
30 36
31static const struct plugin_api* rb; /* global api struct pointer */ 37static const struct plugin_api* rb; /* global api struct pointer */
32 38
39MEM_FUNCTION_WRAPPERS(rb)
40
33/* this is the plugin entry point */ 41/* this is the plugin entry point */
34enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) 42enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
35{ 43{
@@ -47,9 +55,14 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame
47 55
48 rb->strcpy(filename, parameter); 56 rb->strcpy(filename, parameter);
49 57
50 ret = rb->read_bmp_file(filename, &grey_bm, sizeof(grey_bm_buf), 58#if LCD_DEPTH == 1
51 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT, 59 bmp_init(rb);
52 &format_grey); 60 resize_init(rb);
61#endif
62
63 ret = BMP_LOAD(filename, &grey_bm, sizeof(grey_bm_buf),
64 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
65 &format_grey);
53 66
54 if(ret < 1) 67 if(ret < 1)
55 { 68 {
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}
diff --git a/apps/recorder/bmp.h b/apps/recorder/bmp.h
index c53f295dfb..946bc6f8b8 100644
--- a/apps/recorder/bmp.h
+++ b/apps/recorder/bmp.h
@@ -52,7 +52,8 @@ struct rowset {
52 short rowstop; 52 short rowstop;
53}; 53};
54 54
55#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) 55#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) || \
56 defined(PLUGIN)
56extern const unsigned char dither_table[16]; 57extern const unsigned char dither_table[16];
57#define DITHERY(y) (dither_table[(y) & 15] & 0xAA) 58#define DITHERY(y) (dither_table[(y) & 15] & 0xAA)
58#define DITHERX(x) (dither_table[(x) & 15]) 59#define DITHERX(x) (dither_table[(x) & 15])
@@ -67,7 +68,7 @@ extern const unsigned char dither_table[16];
67*/ 68*/
68static inline unsigned brightness(struct uint8_rgb color) 69static inline unsigned brightness(struct uint8_rgb color)
69{ 70{
70#if LCD_DEPTH > 1 71#if LCD_DEPTH > 1 || defined(PLUGIN)
71 return (77 * (unsigned)color.red + 150 * (unsigned)color.green 72 return (77 * (unsigned)color.red + 150 * (unsigned)color.green
72 + 29 * (unsigned)color.blue) / 256; 73 + 29 * (unsigned)color.blue) / 256;
73#else 74#else
@@ -211,4 +212,9 @@ int read_bmp_fd(int fd,
211 int maxsize, 212 int maxsize,
212 int format, 213 int format,
213 const struct custom_format *cformat); 214 const struct custom_format *cformat);
215#ifdef PLUGIN
216struct plugin_api;
217void bmp_init(const struct plugin_api * api);
218#endif
219
214#endif 220#endif
diff --git a/apps/recorder/resize.c b/apps/recorder/resize.c
index 5c9f7a6dd6..6e5e9c4efb 100644
--- a/apps/recorder/resize.c
+++ b/apps/recorder/resize.c
@@ -36,7 +36,9 @@
36#include <string.h> 36#include <string.h>
37#include <general.h> 37#include <general.h>
38#include "inttypes.h" 38#include "inttypes.h"
39#ifndef PLUGIN
39#include "debug.h" 40#include "debug.h"
41#endif
40#include "lcd.h" 42#include "lcd.h"
41#include "file.h" 43#include "file.h"
42#ifdef HAVE_REMOTE_LCD 44#ifdef HAVE_REMOTE_LCD
@@ -50,15 +52,26 @@
50#ifndef __PCTOOL__ 52#ifndef __PCTOOL__
51#include "config.h" 53#include "config.h"
52#include "system.h" 54#include "system.h"
53#include "bmp.h" 55#include <bmp.h>
54#include "resize.h"
55#include "resize.h" 56#include "resize.h"
56#include "debug.h"
57#else 57#else
58#undef DEBUGF 58#undef DEBUGF
59#define DEBUGF(...) 59#define DEBUGF(...)
60#endif 60#endif
61 61
62#ifndef PLUGIN
63#define API(x) x
64#else
65#define API(x) rb->x
66
67static const struct plugin_api *rb;
68
69void resize_init(const struct plugin_api *api)
70{
71 rb = api;
72}
73#endif
74
62/* calculate the maximum dimensions which will preserve the aspect ration of 75/* calculate the maximum dimensions which will preserve the aspect ration of
63 src while fitting in the constraints passed in dst, and store result in dst, 76 src while fitting in the constraints passed in dst, and store result in dst,
64 returning 0 if rounding and 1 if not rounding. 77 returning 0 if rounding and 1 if not rounding.
@@ -141,7 +154,7 @@ static bool scale_h_area(void *out_line_ptr,
141 oxe = 0; 154 oxe = 0;
142 mul = 0; 155 mul = 0;
143 /* give other tasks a chance to run */ 156 /* give other tasks a chance to run */
144 yield(); 157 API(yield)();
145 for (ix = 0; ix < (unsigned int)ctx->src->width; ix++) 158 for (ix = 0; ix < (unsigned int)ctx->src->width; ix++)
146 { 159 {
147 oxe += ctx->bm->width; 160 oxe += ctx->bm->width;
@@ -244,11 +257,11 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
244#ifdef HAVE_LCD_COLOR 257#ifdef HAVE_LCD_COLOR
245 uint32_t *rowacc = (uint32_t *) ctx->buf, 258 uint32_t *rowacc = (uint32_t *) ctx->buf,
246 *rowtmp = rowacc + 3 * ctx->bm->width; 259 *rowtmp = rowacc + 3 * ctx->bm->width;
247 memset((void *)ctx->buf, 0, ctx->bm->width * 2 * sizeof(struct uint32_rgb)); 260 API(memset)((void *)ctx->buf, 0, ctx->bm->width * 2 * sizeof(struct uint32_rgb));
248#else 261#else
249 uint32_t *rowacc = (uint32_t *) ctx->buf, 262 uint32_t *rowacc = (uint32_t *) ctx->buf,
250 *rowtmp = rowacc + ctx->bm->width; 263 *rowtmp = rowacc + ctx->bm->width;
251 memset((void *)ctx->buf, 0, ctx->bm->width * 2 * sizeof(uint32_t)); 264 API(memset)((void *)ctx->buf, 0, ctx->bm->width * 2 * sizeof(uint32_t));
252#endif 265#endif
253 SDEBUGF("scale_v_area\n"); 266 SDEBUGF("scale_v_area\n");
254 /* zero the accumulator and temp rows */ 267 /* zero the accumulator and temp rows */
@@ -285,9 +298,9 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
285 ctx->output_row(oy, (void*)rowacc, ctx); 298 ctx->output_row(oy, (void*)rowacc, ctx);
286 /* clear accumulator row, store partial coverage for next row */ 299 /* clear accumulator row, store partial coverage for next row */
287#ifdef HAVE_LCD_COLOR 300#ifdef HAVE_LCD_COLOR
288 memset((void *)rowacc, 0, ctx->bm->width * sizeof(uint32_t) * 3); 301 API(memset)((void *)rowacc, 0, ctx->bm->width * sizeof(uint32_t) * 3);
289#else 302#else
290 memset((void *)rowacc, 0, ctx->bm->width * sizeof(uint32_t)); 303 API(memset)((void *)rowacc, 0, ctx->bm->width * sizeof(uint32_t));
291#endif 304#endif
292 mul = oye; 305 mul = oye;
293 oy += rset->rowstep; 306 oy += rset->rowstep;
@@ -333,7 +346,7 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
333 /* The error is set so that values are initialized on the first pass. */ 346 /* The error is set so that values are initialized on the first pass. */
334 ixe = ctx->bm->width - 1; 347 ixe = ctx->bm->width - 1;
335 /* give other tasks a chance to run */ 348 /* give other tasks a chance to run */
336 yield(); 349 API(yield)();
337 for (ox = 0; ox < (uint32_t)ctx->bm->width; ox++) 350 for (ox = 0; ox < (uint32_t)ctx->bm->width; ox++)
338 { 351 {
339#ifdef HAVE_LCD_COLOR 352#ifdef HAVE_LCD_COLOR
@@ -500,8 +513,8 @@ static inline bool scale_v_linear(struct rowset *rset,
500} 513}
501#endif /* HAVE_UPSCALER */ 514#endif /* HAVE_UPSCALER */
502 515
503static void output_row_native(uint32_t row, void * row_in, 516#ifndef PLUGIN
504 struct scaler_context *ctx) 517void output_row_native(uint32_t row, void * row_in, struct scaler_context *ctx)
505{ 518{
506 int col; 519 int col;
507 int fb_width = BM_WIDTH(ctx->bm->width,FORMAT_NATIVE,0); 520 int fb_width = BM_WIDTH(ctx->bm->width,FORMAT_NATIVE,0);
@@ -511,7 +524,7 @@ static void output_row_native(uint32_t row, void * row_in,
511#else 524#else
512 uint32_t *qp = (uint32_t*)row_in; 525 uint32_t *qp = (uint32_t*)row_in;
513#endif 526#endif
514 SDEBUGF("output_row: y: %d in: %p\n",row, row_in); 527 SDEBUGF("output_row: y: %lu in: %p\n",row, row_in);
515#if LCD_DEPTH == 2 528#if LCD_DEPTH == 2
516#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 529#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
517 /* greyscale iPods */ 530 /* greyscale iPods */
@@ -591,6 +604,7 @@ static void output_row_native(uint32_t row, void * row_in,
591 } 604 }
592#endif /* LCD_DEPTH */ 605#endif /* LCD_DEPTH */
593} 606}
607#endif
594 608
595int resize_on_load(struct bitmap *bm, bool dither, struct dim *src, 609int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
596 struct rowset *rset, unsigned char *buf, unsigned int len, 610 struct rowset *rset, unsigned char *buf, unsigned int len,
@@ -615,8 +629,10 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
615 uint8_t sc_buf[(needed <= len || needed > MAX_SC_STACK_ALLOC) ? 629 uint8_t sc_buf[(needed <= len || needed > MAX_SC_STACK_ALLOC) ?
616 0 : needed]; 630 0 : needed];
617#endif 631#endif
618 len = (unsigned int)align_buffer(PUN_PTR(void**, &buf), len, 632#if CONFIG_CODEC == SWCODEC
633 len = (unsigned int)API(align_buffer)(PUN_PTR(void**, &buf), len,
619 sizeof(uint32_t)); 634 sizeof(uint32_t));
635#endif
620 if (needed > len) 636 if (needed > len)
621 { 637 {
622#if MAX_SC_STACK_ALLOC 638#if MAX_SC_STACK_ALLOC
@@ -642,7 +658,9 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
642 } 658 }
643 659
644 struct scaler_context ctx; 660 struct scaler_context ctx;
645 cpu_boost(true); 661#ifdef HAVE_ADJUSTABLE_CPU_FREQ
662 API(cpu_boost)(true);
663#endif
646 ctx.store_part = store_part; 664 ctx.store_part = store_part;
647 ctx.args = args; 665 ctx.args = args;
648#if MAX_SC_STACK_ALLOC 666#if MAX_SC_STACK_ALLOC
@@ -654,10 +672,11 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
654 ctx.bm = bm; 672 ctx.bm = bm;
655 ctx.src = src; 673 ctx.src = src;
656 ctx.dither = dither; 674 ctx.dither = dither;
675#ifndef PLUGIN
676 ctx.output_row = output_row_native;
657 if (format) 677 if (format)
678#endif
658 ctx.output_row = format->output_row; 679 ctx.output_row = format->output_row;
659 else
660 ctx.output_row = output_row_native;
661#ifdef HAVE_UPSCALER 680#ifdef HAVE_UPSCALER
662 if (sw > dw) 681 if (sw > dw)
663 { 682 {
@@ -678,7 +697,9 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
678 else 697 else
679 ret = scale_v_linear(rset, &ctx); 698 ret = scale_v_linear(rset, &ctx);
680#endif 699#endif
681 cpu_boost(false); 700#ifdef HAVE_ADJUSTABLE_CPU_FREQ
701 API(cpu_boost)(false);
702#endif
682 if (!ret) 703 if (!ret)
683 return 0; 704 return 0;
684 return 1; 705 return 1;
diff --git a/apps/recorder/resize.h b/apps/recorder/resize.h
index ca7e6326d0..9b52a7aa65 100644
--- a/apps/recorder/resize.h
+++ b/apps/recorder/resize.h
@@ -45,8 +45,7 @@
45 45
46struct img_part { 46struct img_part {
47 int len; 47 int len;
48#if !defined(HAVE_LCD_COLOR) && \ 48#if !defined(HAVE_LCD_COLOR)
49 (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1))
50 uint8_t *buf; 49 uint8_t *buf;
51#else 50#else
52 struct uint8_rgb* buf; 51 struct uint8_rgb* buf;
@@ -95,4 +94,10 @@ int resize_on_load(struct bitmap *bm, bool dither,
95 const struct custom_format *cformat, 94 const struct custom_format *cformat,
96 struct img_part* (*store_part)(void *args), 95 struct img_part* (*store_part)(void *args),
97 void *args); 96 void *args);
97
98#ifdef PLUGIN
99struct plugin_api;
100void resize_init(const struct plugin_api *api);
101#endif
102
98#endif /* _RESIZE_H_ */ 103#endif /* _RESIZE_H_ */