Make scaler output truly pluggable, add an 8-bit greyscale output to

pluginlib for use with greylib, and add source for a test scaled bmp
viewer using greylib.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19593 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andrew Mahone 2008-12-26 07:05:13 +00:00
parent f7fa7e5ad5
commit 9058620849
17 changed files with 88 additions and 42 deletions

View file

@ -147,7 +147,8 @@ const unsigned short vi_pattern[4] = {
int read_bmp_file(const char* filename,
struct bitmap *bm,
int maxsize,
int format)
int format,
const struct custom_format *cformat)
{
int fd, ret;
fd = open(filename, O_RDONLY);
@ -161,7 +162,7 @@ int read_bmp_file(const char* filename,
BDEBUGF("read_bmp_file: '%s' remote: %d resize: %d keep_aspect: %d\n",
filename, !!(format & FORMAT_REMOTE), !!(format & FORMAT_RESIZE),
!!(format & FORMAT_KEEP_ASPECT));
ret = read_bmp_fd(fd, bm, maxsize, format);
ret = read_bmp_fd(fd, bm, maxsize, format, cformat);
close(fd);
return ret;
}
@ -349,7 +350,8 @@ static inline int rgbcmp(struct uint8_rgb rgb1, struct uint8_rgb rgb2)
int read_bmp_fd(int fd,
struct bitmap *bm,
int maxsize,
int format)
int format,
const struct custom_format *cformat)
{
struct bmp_header bmph;
int padded_width;
@ -473,7 +475,10 @@ int read_bmp_fd(int fd,
rset.rowstop = -1;
}
totalsize = BM_SIZE(bm->width,bm->height,format,remote);
if (cformat)
totalsize = cformat->get_size(bm);
else
totalsize = BM_SIZE(bm->width,bm->height,format,remote);
/* Check if this fits the buffer */
if (totalsize > maxsize) {
@ -565,10 +570,15 @@ int read_bmp_fd(int fd,
};
#if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
if (resize)
return resize_on_load(bm, dither, &src_dim, &rset,
bitmap + totalsize, maxsize - totalsize,
store_part_bmp, &ba);
if (resize || cformat)
{
if (resize_on_load(bm, dither, &src_dim, &rset,
bitmap + totalsize, maxsize - totalsize,
cformat, store_part_bmp, &ba))
return totalsize;
else
return 0;
}
int fb_width = BM_WIDTH(bm->width,bm->format,remote);
#endif /* LCD_DEPTH */

View file

@ -24,6 +24,7 @@
#include "config.h"
#include "lcd.h"
#include "inttypes.h"
#include "resize.h"
#ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h"
#endif
@ -202,10 +203,12 @@ extern const unsigned short vi_pattern[4];
int read_bmp_file(const char* filename,
struct bitmap *bm,
int maxsize,
int format);
int format,
const struct custom_format *cformat);
int read_bmp_fd(int fd,
struct bitmap *bm,
int maxsize,
int format);
int format,
const struct custom_format *cformat);
#endif

View file

@ -114,23 +114,6 @@ int recalc_dimension(struct dim *dst, struct dim *src)
return false; \
}
/* struct which containers various parameters shared between vertical scaler,
horizontal scaler, and row output
*/
struct scaler_context {
uint32_t divisor;
uint32_t round;
struct bitmap *bm;
struct dim *src;
unsigned char *buf;
bool dither;
int len;
void *args;
struct img_part* (*store_part)(void *);
void (*output_row)(uint32_t,void*,struct scaler_context*);
bool (*h_scaler)(void*,struct scaler_context*, bool);
};
/* Set up rounding and scale factors for horizontal area scaler */
static inline void scale_h_area_setup(struct scaler_context *ctx)
{
@ -610,6 +593,7 @@ void output_row_native(uint32_t row, void * row_in, struct scaler_context *ctx)
int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
struct rowset *rset, unsigned char *buf, unsigned int len,
const struct custom_format *format,
struct img_part* (*store_part)(void *args),
void *args)
{
@ -669,7 +653,10 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
ctx.bm = bm;
ctx.src = src;
ctx.dither = dither;
ctx.output_row = output_row_native;
if (format)
ctx.output_row = format->output_row;
else
ctx.output_row = output_row_native;
#ifdef HAVE_UPSCALER
if (sw > dw)
{
@ -693,5 +680,5 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
cpu_boost(false);
if (!ret)
return 0;
return BM_SIZE(bm->width,bm->height,bm->format,0);
return 1;
}

View file

@ -20,7 +20,6 @@
****************************************************************************/
#ifndef _RESIZE_H_
#define _RESIZE_H_
#include "config.h"
#include "lcd.h"
#include "inttypes.h"
@ -65,11 +64,35 @@ struct uint32_rgb {
};
#endif
/* struct which contains various parameters shared between vertical scaler,
horizontal scaler, and row output
*/
struct scaler_context {
uint32_t divisor;
uint32_t round;
struct bitmap *bm;
struct dim *src;
unsigned char *buf;
bool dither;
int len;
void *args;
struct img_part* (*store_part)(void *);
void (*output_row)(uint32_t,void*,struct scaler_context*);
bool (*h_scaler)(void*,struct scaler_context*, bool);
};
struct custom_format {
void (*output_row)(uint32_t,void*,struct scaler_context*);
unsigned int (*get_size)(struct bitmap *bm);
};
struct rowset;
int recalc_dimension(struct dim *dst, struct dim *src);
int resize_on_load(struct bitmap *bm, bool dither,
struct dim *src, struct rowset *tmp_row,
unsigned char *buf, unsigned int len,
const struct custom_format *cformat,
struct img_part* (*store_part)(void *args),
void *args);
#endif /* _RESIZE_H_ */