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
This commit is contained in:
Andrew Mahone 2009-01-04 21:22:05 +00:00
parent b93874fefc
commit 4eedc93357
9 changed files with 188 additions and 50 deletions

View file

@ -4,6 +4,10 @@ fixedpoint.c
playback_control.c playback_control.c
rgb_hsv.c rgb_hsv.c
#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
#if LCD_DEPTH == 1
core_bmp.c
core_resize.c
#endif
grey_core.c grey_core.c
grey_draw.c grey_draw.c
grey_parm.c grey_parm.c

View file

@ -87,6 +87,8 @@ int save_bmp_file( char* filename, struct bitmap *bm, const struct plugin_api* r
} }
#endif #endif
#include "../../recorder/bmp.c"
/** /**
Very simple image scale from src to dst (nearest neighbour). Very simple image scale from src to dst (nearest neighbour).
Source and destination dimensions are read from the struct bitmap. Source and destination dimensions are read from the struct bitmap.

View file

@ -0,0 +1,24 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* This is a wrapper for the core bmp.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <plugin.h>
#include "../../recorder/bmp.c"

View file

@ -0,0 +1,24 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* This is a wrapper for the core bmp.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <plugin.h>
#include "../../recorder/resize.c"

View file

@ -22,6 +22,12 @@
#include "plugin.h" #include "plugin.h"
#include "lib/grey.h" #include "lib/grey.h"
#if LCD_DEPTH == 1
#define BMP_LOAD read_bmp_file
#else
#define BMP_LOAD rb->read_bmp_file
#endif
PLUGIN_HEADER PLUGIN_HEADER
GREY_INFO_STRUCT GREY_INFO_STRUCT
static unsigned char grey_bm_buf[LCD_WIDTH * LCD_HEIGHT + static unsigned char grey_bm_buf[LCD_WIDTH * LCD_HEIGHT +
@ -30,6 +36,8 @@ static unsigned char grey_display_buf[2*LCD_WIDTH * LCD_HEIGHT];
static const struct plugin_api* rb; /* global api struct pointer */ static const struct plugin_api* rb; /* global api struct pointer */
MEM_FUNCTION_WRAPPERS(rb)
/* this is the plugin entry point */ /* this is the plugin entry point */
enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
{ {
@ -47,9 +55,14 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame
rb->strcpy(filename, parameter); rb->strcpy(filename, parameter);
ret = rb->read_bmp_file(filename, &grey_bm, sizeof(grey_bm_buf), #if LCD_DEPTH == 1
FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT, bmp_init(rb);
&format_grey); resize_init(rb);
#endif
ret = BMP_LOAD(filename, &grey_bm, sizeof(grey_bm_buf),
FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
&format_grey);
if(ret < 1) if(ret < 1)
{ {

View file

@ -42,7 +42,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "inttypes.h" #include "inttypes.h"
#ifndef PLUGIN
#include "debug.h" #include "debug.h"
#endif
#include "lcd.h" #include "lcd.h"
#include "file.h" #include "file.h"
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
@ -58,7 +60,6 @@
#include "system.h" #include "system.h"
#include "bmp.h" #include "bmp.h"
#include "resize.h" #include "resize.h"
#include "debug.h"
#else #else
#undef DEBUGF #undef DEBUGF
#define DEBUGF(...) #define DEBUGF(...)
@ -71,6 +72,19 @@
#pragma pack (push, 2) #pragma pack (push, 2)
#endif #endif
#ifndef PLUGIN
#define API(x) x
#else
#define API(x) rb->x
static const struct plugin_api *rb;
void bmp_init(const struct plugin_api * api)
{
rb = api;
}
#endif
/* BMP header structure */ /* BMP header structure */
struct bmp_header { struct bmp_header {
uint16_t type; /* signature - 'BM' */ uint16_t type; /* signature - 'BM' */
@ -123,13 +137,15 @@ static const struct uint8_rgb bitfields[3][3] = {
}, },
}; };
#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
/* the full 16x16 Bayer dither matrix may be calculated quickly with this table /* the full 16x16 Bayer dither matrix may be calculated quickly with this table
*/ */
const unsigned char dither_table[16] = const unsigned char dither_table[16] =
{ 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }; { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 };
#endif #endif
#ifndef PLUGIN
#if ((LCD_DEPTH == 2) && (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)) \ #if ((LCD_DEPTH == 2) && (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)) \
|| (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH == 2) \ || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH == 2) \
&& (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED)) && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED))
@ -137,6 +153,7 @@ const unsigned short vi_pattern[4] = {
0x0101, 0x0100, 0x0001, 0x0000 0x0101, 0x0100, 0x0001, 0x0000
}; };
#endif #endif
#endif
/****************************************************************************** /******************************************************************************
* read_bmp_file() * read_bmp_file()
@ -151,7 +168,7 @@ int read_bmp_file(const char* filename,
const struct custom_format *cformat) const struct custom_format *cformat)
{ {
int fd, ret; int fd, ret;
fd = open(filename, O_RDONLY); fd = API(open)(filename, O_RDONLY);
/* Exit if file opening failed */ /* Exit if file opening failed */
if (fd < 0) { if (fd < 0) {
@ -163,7 +180,7 @@ int read_bmp_file(const char* filename,
filename, !!(format & FORMAT_REMOTE), !!(format & FORMAT_RESIZE), filename, !!(format & FORMAT_REMOTE), !!(format & FORMAT_RESIZE),
!!(format & FORMAT_KEEP_ASPECT)); !!(format & FORMAT_KEEP_ASPECT));
ret = read_bmp_fd(fd, bm, maxsize, format, cformat); ret = read_bmp_fd(fd, bm, maxsize, format, cformat);
close(fd); API(close)(fd);
return ret; return ret;
} }
@ -182,7 +199,8 @@ struct bmp_args {
short depth; short depth;
unsigned char buf[BM_MAX_WIDTH * 4]; unsigned char buf[BM_MAX_WIDTH * 4];
struct uint8_rgb *palette; struct uint8_rgb *palette;
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
int cur_row; int cur_row;
int cur_col; int cur_col;
struct img_part part; struct img_part part;
@ -195,7 +213,8 @@ static unsigned int read_part_line(struct bmp_args *ba)
const int read_width = ba->read_width; const int read_width = ba->read_width;
const int width = ba->width; const int width = ba->width;
const int depth = ba->depth; const int depth = ba->depth;
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
int cur_row = ba->cur_row; int cur_row = ba->cur_row;
int cur_col = ba->cur_col; int cur_col = ba->cur_col;
#endif #endif
@ -207,7 +226,8 @@ static unsigned int read_part_line(struct bmp_args *ba)
int ret; int ret;
int i, cols, len; int i, cols, len;
#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
cols = MIN(width - cur_col,(int)BM_MAX_WIDTH); cols = MIN(width - cur_col,(int)BM_MAX_WIDTH);
BDEBUGF("reading %d cols (width: %d, max: %d)\n",cols,width,BM_MAX_WIDTH); BDEBUGF("reading %d cols (width: %d, max: %d)\n",cols,width,BM_MAX_WIDTH);
len = (cols * (depth == 15 ? 16 : depth) + 7) >> 3; len = (cols * (depth == 15 ? 16 : depth) + 7) >> 3;
@ -217,13 +237,16 @@ static unsigned int read_part_line(struct bmp_args *ba)
#endif #endif
ibuf = ((unsigned char *)buf) + (BM_MAX_WIDTH << 2) - len; ibuf = ((unsigned char *)buf) + (BM_MAX_WIDTH << 2) - len;
BDEBUGF("read_part_line: cols=%d len=%d\n",cols,len); BDEBUGF("read_part_line: cols=%d len=%d\n",cols,len);
ret = read(fd, ibuf, len); ret = API(read)(fd, ibuf, len);
if (ret != len) if (ret != len)
{ {
DEBUGF("read_part_line: error reading image, read returned %d " DEBUGF("read_part_line: error reading image, read returned %d "
"expected %d\n", ret, len); "expected %d\n", ret, len);
#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
BDEBUGF("cur_row: %d cur_col: %d cols: %d len: %d\n", cur_row, cur_col, BDEBUGF("cur_row: %d cur_col: %d cols: %d len: %d\n", cur_row, cur_col,
cols, len); cols, len);
#endif
return 0; return 0;
} }
while (ibuf < ba->buf + (BM_MAX_WIDTH << 2)) while (ibuf < ba->buf + (BM_MAX_WIDTH << 2))
@ -282,15 +305,17 @@ static unsigned int read_part_line(struct bmp_args *ba)
} }
} }
#if !defined(HAVE_LCD_COLOR) && \ #if (!defined(HAVE_LCD_COLOR) && \
(LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)) (LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1))) || \
defined(PLUGIN)
ibuf = ba->buf; ibuf = ba->buf;
buf = (struct uint8_rgb*)ba->buf; buf = (struct uint8_rgb*)ba->buf;
while (ibuf < ba->buf + cols) while (ibuf < ba->buf + cols)
*ibuf++ = brightness(*buf++); *ibuf++ = brightness(*buf++);
#endif #endif
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
cur_col += cols; cur_col += cols;
if (cur_col == width) if (cur_col == width)
{ {
@ -299,9 +324,10 @@ static unsigned int read_part_line(struct bmp_args *ba)
if (pad > 0) if (pad > 0)
{ {
BDEBUGF("seeking %d bytes to next line\n",pad); BDEBUGF("seeking %d bytes to next line\n",pad);
lseek(fd, pad, SEEK_CUR); API(lseek)(fd, pad, SEEK_CUR);
} }
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
cur_col = 0; cur_col = 0;
BDEBUGF("read_part_line: completed row %d\n", cur_row); BDEBUGF("read_part_line: completed row %d\n", cur_row);
cur_row += 1; cur_row += 1;
@ -313,7 +339,8 @@ static unsigned int read_part_line(struct bmp_args *ba)
return cols; return cols;
} }
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
static struct img_part *store_part_bmp(void *args) static struct img_part *store_part_bmp(void *args)
{ {
struct bmp_args *ba = (struct bmp_args *)args; struct bmp_args *ba = (struct bmp_args *)args;
@ -363,13 +390,14 @@ int read_bmp_fd(int fd,
struct uint8_rgb palette[256]; struct uint8_rgb palette[256];
struct rowset rset; struct rowset rset;
struct dim src_dim; struct dim src_dim;
#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) \
bool remote = false; || defined(PLUGIN)
unsigned int resize = IMG_NORESIZE; unsigned int resize = IMG_NORESIZE;
bool dither = false; bool dither = false;
bool transparent = false; bool transparent = false;
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
bool remote = false;
if (format & FORMAT_REMOTE) { if (format & FORMAT_REMOTE) {
remote = true; remote = true;
#if LCD_REMOTE_DEPTH == 1 #if LCD_REMOTE_DEPTH == 1
@ -394,7 +422,7 @@ int read_bmp_fd(int fd,
#endif /*(LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)*/ #endif /*(LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)*/
/* read fileheader */ /* read fileheader */
ret = read(fd, &bmph, sizeof(struct bmp_header)); ret = API(read)(fd, &bmph, sizeof(struct bmp_header));
if (ret < 0) { if (ret < 0) {
return ret * 10 - 2; return ret * 10 - 2;
} }
@ -433,14 +461,17 @@ int read_bmp_fd(int fd,
{ {
resize &= ~IMG_RESIZE; resize &= ~IMG_RESIZE;
resize |= IMG_NORESIZE; resize |= IMG_NORESIZE;
#ifdef HAVE_REMOTE_LCD
remote = 0; remote = 0;
#endif
} }
#else #elif !defined(PLUGIN)
if (src_dim.width > BM_MAX_WIDTH) if (src_dim.width > BM_MAX_WIDTH)
return -6; return -6;
#endif /*(LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)*/ #endif /*(LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)*/
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
if (resize & IMG_RESIZE) { if (resize & IMG_RESIZE) {
if(format & FORMAT_KEEP_ASPECT) { if(format & FORMAT_KEEP_ASPECT) {
/* keep aspect ratio.. */ /* keep aspect ratio.. */
@ -463,7 +494,8 @@ int read_bmp_fd(int fd,
bm->width = src_dim.width; bm->width = src_dim.width;
bm->height = src_dim.height; bm->height = src_dim.height;
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
} }
#endif #endif
@ -499,7 +531,7 @@ int read_bmp_fd(int fd,
int i; int i;
union rgb_union pal; union rgb_union pal;
for (i = 0; i < numcolors; i++) { for (i = 0; i < numcolors; i++) {
if (read(fd, &pal, sizeof(pal)) != (int)sizeof(pal)) if (API(read)(fd, &pal, sizeof(pal)) != (int)sizeof(pal))
{ {
DEBUGF("read_bmp_fd: Can't read color palette\n"); DEBUGF("read_bmp_fd: Can't read color palette\n");
return -7; return -7;
@ -557,20 +589,24 @@ int read_bmp_fd(int fd,
} }
/* Search to the beginning of the image data */ /* Search to the beginning of the image data */
lseek(fd, (off_t)letoh32(bmph.off_bits), SEEK_SET); API(lseek)(fd, (off_t)letoh32(bmph.off_bits), SEEK_SET);
memset(bitmap, 0, totalsize); API(memset)(bitmap, 0, totalsize);
struct bmp_args ba = { struct bmp_args ba = {
.fd = fd, .padded_width = padded_width, .read_width = read_width, .fd = fd, .padded_width = padded_width, .read_width = read_width,
.width = src_dim.width, .depth = depth, .palette = palette, .width = src_dim.width, .depth = depth, .palette = palette,
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
.cur_row = 0, .cur_col = 0, .part = {0,0} .cur_row = 0, .cur_col = 0, .part = {0,0}
#endif #endif
}; };
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
#if LCD_DEPTH > 1
if (resize || cformat) if (resize || cformat)
#endif
{ {
if (resize_on_load(bm, dither, &src_dim, &rset, if (resize_on_load(bm, dither, &src_dim, &rset,
bitmap + totalsize, maxsize - totalsize, bitmap + totalsize, maxsize - totalsize,
@ -579,10 +615,12 @@ int read_bmp_fd(int fd,
else else
return 0; return 0;
} }
#ifndef PLUGIN
int fb_width = BM_WIDTH(bm->width,bm->format,remote); int fb_width = BM_WIDTH(bm->width,bm->format,remote);
#endif
#endif /* LCD_DEPTH */ #endif /* LCD_DEPTH */
#ifndef PLUGIN
int col, row; int col, row;
/* loop to read rows and put them to buffer */ /* loop to read rows and put them to buffer */
@ -718,4 +756,5 @@ int read_bmp_fd(int fd,
} }
} }
return totalsize; /* return the used buffer size. */ return totalsize; /* return the used buffer size. */
#endif
} }

View file

@ -52,7 +52,8 @@ struct rowset {
short rowstop; short rowstop;
}; };
#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) || \
defined(PLUGIN)
extern const unsigned char dither_table[16]; extern const unsigned char dither_table[16];
#define DITHERY(y) (dither_table[(y) & 15] & 0xAA) #define DITHERY(y) (dither_table[(y) & 15] & 0xAA)
#define DITHERX(x) (dither_table[(x) & 15]) #define DITHERX(x) (dither_table[(x) & 15])
@ -67,7 +68,7 @@ extern const unsigned char dither_table[16];
*/ */
static inline unsigned brightness(struct uint8_rgb color) static inline unsigned brightness(struct uint8_rgb color)
{ {
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1 || defined(PLUGIN)
return (77 * (unsigned)color.red + 150 * (unsigned)color.green return (77 * (unsigned)color.red + 150 * (unsigned)color.green
+ 29 * (unsigned)color.blue) / 256; + 29 * (unsigned)color.blue) / 256;
#else #else
@ -211,4 +212,9 @@ int read_bmp_fd(int fd,
int maxsize, int maxsize,
int format, int format,
const struct custom_format *cformat); const struct custom_format *cformat);
#ifdef PLUGIN
struct plugin_api;
void bmp_init(const struct plugin_api * api);
#endif
#endif #endif

View file

@ -36,7 +36,9 @@
#include <string.h> #include <string.h>
#include <general.h> #include <general.h>
#include "inttypes.h" #include "inttypes.h"
#ifndef PLUGIN
#include "debug.h" #include "debug.h"
#endif
#include "lcd.h" #include "lcd.h"
#include "file.h" #include "file.h"
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
@ -50,15 +52,26 @@
#ifndef __PCTOOL__ #ifndef __PCTOOL__
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "bmp.h" #include <bmp.h>
#include "resize.h" #include "resize.h"
#include "resize.h"
#include "debug.h"
#else #else
#undef DEBUGF #undef DEBUGF
#define DEBUGF(...) #define DEBUGF(...)
#endif #endif
#ifndef PLUGIN
#define API(x) x
#else
#define API(x) rb->x
static const struct plugin_api *rb;
void resize_init(const struct plugin_api *api)
{
rb = api;
}
#endif
/* calculate the maximum dimensions which will preserve the aspect ration of /* calculate the maximum dimensions which will preserve the aspect ration of
src while fitting in the constraints passed in dst, and store result in dst, src while fitting in the constraints passed in dst, and store result in dst,
returning 0 if rounding and 1 if not rounding. returning 0 if rounding and 1 if not rounding.
@ -141,7 +154,7 @@ static bool scale_h_area(void *out_line_ptr,
oxe = 0; oxe = 0;
mul = 0; mul = 0;
/* give other tasks a chance to run */ /* give other tasks a chance to run */
yield(); API(yield)();
for (ix = 0; ix < (unsigned int)ctx->src->width; ix++) for (ix = 0; ix < (unsigned int)ctx->src->width; ix++)
{ {
oxe += ctx->bm->width; oxe += ctx->bm->width;
@ -244,11 +257,11 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
uint32_t *rowacc = (uint32_t *) ctx->buf, uint32_t *rowacc = (uint32_t *) ctx->buf,
*rowtmp = rowacc + 3 * ctx->bm->width; *rowtmp = rowacc + 3 * ctx->bm->width;
memset((void *)ctx->buf, 0, ctx->bm->width * 2 * sizeof(struct uint32_rgb)); API(memset)((void *)ctx->buf, 0, ctx->bm->width * 2 * sizeof(struct uint32_rgb));
#else #else
uint32_t *rowacc = (uint32_t *) ctx->buf, uint32_t *rowacc = (uint32_t *) ctx->buf,
*rowtmp = rowacc + ctx->bm->width; *rowtmp = rowacc + ctx->bm->width;
memset((void *)ctx->buf, 0, ctx->bm->width * 2 * sizeof(uint32_t)); API(memset)((void *)ctx->buf, 0, ctx->bm->width * 2 * sizeof(uint32_t));
#endif #endif
SDEBUGF("scale_v_area\n"); SDEBUGF("scale_v_area\n");
/* zero the accumulator and temp rows */ /* zero the accumulator and temp rows */
@ -285,9 +298,9 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
ctx->output_row(oy, (void*)rowacc, ctx); ctx->output_row(oy, (void*)rowacc, ctx);
/* clear accumulator row, store partial coverage for next row */ /* clear accumulator row, store partial coverage for next row */
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
memset((void *)rowacc, 0, ctx->bm->width * sizeof(uint32_t) * 3); API(memset)((void *)rowacc, 0, ctx->bm->width * sizeof(uint32_t) * 3);
#else #else
memset((void *)rowacc, 0, ctx->bm->width * sizeof(uint32_t)); API(memset)((void *)rowacc, 0, ctx->bm->width * sizeof(uint32_t));
#endif #endif
mul = oye; mul = oye;
oy += rset->rowstep; oy += rset->rowstep;
@ -333,7 +346,7 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
/* The error is set so that values are initialized on the first pass. */ /* The error is set so that values are initialized on the first pass. */
ixe = ctx->bm->width - 1; ixe = ctx->bm->width - 1;
/* give other tasks a chance to run */ /* give other tasks a chance to run */
yield(); API(yield)();
for (ox = 0; ox < (uint32_t)ctx->bm->width; ox++) for (ox = 0; ox < (uint32_t)ctx->bm->width; ox++)
{ {
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
@ -500,8 +513,8 @@ static inline bool scale_v_linear(struct rowset *rset,
} }
#endif /* HAVE_UPSCALER */ #endif /* HAVE_UPSCALER */
static void output_row_native(uint32_t row, void * row_in, #ifndef PLUGIN
struct scaler_context *ctx) void output_row_native(uint32_t row, void * row_in, struct scaler_context *ctx)
{ {
int col; int col;
int fb_width = BM_WIDTH(ctx->bm->width,FORMAT_NATIVE,0); 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,
#else #else
uint32_t *qp = (uint32_t*)row_in; uint32_t *qp = (uint32_t*)row_in;
#endif #endif
SDEBUGF("output_row: y: %d in: %p\n",row, row_in); SDEBUGF("output_row: y: %lu in: %p\n",row, row_in);
#if LCD_DEPTH == 2 #if LCD_DEPTH == 2
#if LCD_PIXELFORMAT == HORIZONTAL_PACKING #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
/* greyscale iPods */ /* greyscale iPods */
@ -591,6 +604,7 @@ static void output_row_native(uint32_t row, void * row_in,
} }
#endif /* LCD_DEPTH */ #endif /* LCD_DEPTH */
} }
#endif
int resize_on_load(struct bitmap *bm, bool dither, struct dim *src, int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
struct rowset *rset, unsigned char *buf, unsigned int len, 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,
uint8_t sc_buf[(needed <= len || needed > MAX_SC_STACK_ALLOC) ? uint8_t sc_buf[(needed <= len || needed > MAX_SC_STACK_ALLOC) ?
0 : needed]; 0 : needed];
#endif #endif
len = (unsigned int)align_buffer(PUN_PTR(void**, &buf), len, #if CONFIG_CODEC == SWCODEC
len = (unsigned int)API(align_buffer)(PUN_PTR(void**, &buf), len,
sizeof(uint32_t)); sizeof(uint32_t));
#endif
if (needed > len) if (needed > len)
{ {
#if MAX_SC_STACK_ALLOC #if MAX_SC_STACK_ALLOC
@ -642,7 +658,9 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
} }
struct scaler_context ctx; struct scaler_context ctx;
cpu_boost(true); #ifdef HAVE_ADJUSTABLE_CPU_FREQ
API(cpu_boost)(true);
#endif
ctx.store_part = store_part; ctx.store_part = store_part;
ctx.args = args; ctx.args = args;
#if MAX_SC_STACK_ALLOC #if MAX_SC_STACK_ALLOC
@ -654,10 +672,11 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
ctx.bm = bm; ctx.bm = bm;
ctx.src = src; ctx.src = src;
ctx.dither = dither; ctx.dither = dither;
#ifndef PLUGIN
ctx.output_row = output_row_native;
if (format) if (format)
#endif
ctx.output_row = format->output_row; ctx.output_row = format->output_row;
else
ctx.output_row = output_row_native;
#ifdef HAVE_UPSCALER #ifdef HAVE_UPSCALER
if (sw > dw) if (sw > dw)
{ {
@ -678,7 +697,9 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
else else
ret = scale_v_linear(rset, &ctx); ret = scale_v_linear(rset, &ctx);
#endif #endif
cpu_boost(false); #ifdef HAVE_ADJUSTABLE_CPU_FREQ
API(cpu_boost)(false);
#endif
if (!ret) if (!ret)
return 0; return 0;
return 1; return 1;

View file

@ -45,8 +45,7 @@
struct img_part { struct img_part {
int len; int len;
#if !defined(HAVE_LCD_COLOR) && \ #if !defined(HAVE_LCD_COLOR)
(LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1))
uint8_t *buf; uint8_t *buf;
#else #else
struct uint8_rgb* buf; struct uint8_rgb* buf;
@ -95,4 +94,10 @@ int resize_on_load(struct bitmap *bm, bool dither,
const struct custom_format *cformat, const struct custom_format *cformat,
struct img_part* (*store_part)(void *args), struct img_part* (*store_part)(void *args),
void *args); void *args);
#ifdef PLUGIN
struct plugin_api;
void resize_init(const struct plugin_api *api);
#endif
#endif /* _RESIZE_H_ */ #endif /* _RESIZE_H_ */