FS#6321: Universal Image Viewer

This unifies jpeg viewer, png viewer, and bmp viewer to one plugin, image viewer, so that you can navigate through different image formats.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28626 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2010-11-21 13:47:56 +00:00
parent eef21cb18a
commit e5b1a7d423
26 changed files with 582 additions and 478 deletions

View file

@ -3,4 +3,3 @@ tinflate.c
tinfzlib.c
png_decoder.c
png.c
png_ui.c

View file

@ -50,18 +50,13 @@ static unsigned char *disp_buf;
#define resize_bitmap grey_resize_bitmap
#endif
bool img_ext(const char *ext)
{
if (!ext)
return false;
if (!rb->strcasecmp(ext,".png"))
return true;
else
return false;
}
#if defined(USEGSLIB) && (CONFIG_PLATFORM & PLATFORM_HOSTED)
/* hack: fix error "undefined reference to `_grey_info'". */
GREY_INFO_STRUCT
#endif /* USEGSLIB */
void draw_image_rect(struct image_info *info,
int x, int y, int width, int height)
static void draw_image_rect(struct image_info *info,
int x, int y, int width, int height)
{
unsigned char **pdisp = (unsigned char **)info->data;
@ -80,7 +75,7 @@ void draw_image_rect(struct image_info *info,
#endif
}
int img_mem(int ds)
static int img_mem(int ds)
{
LodePNG_Decoder *p_decoder = &decoder;
@ -93,8 +88,8 @@ int img_mem(int ds)
#endif
}
int load_image(char *filename, struct image_info *info,
unsigned char *buf, ssize_t *buf_size)
static int load_image(char *filename, struct image_info *info,
unsigned char *buf, ssize_t *buf_size)
{
int fd;
long time = 0; /* measured ticks */
@ -122,7 +117,7 @@ int load_image(char *filename, struct image_info *info,
DEBUGF("reading file '%s'\n", filename);
if (!running_slideshow) {
if (!iv->running_slideshow) {
rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1);
rb->lcd_update();
}
@ -132,7 +127,7 @@ int load_image(char *filename, struct image_info *info,
rb->close(fd);
} else {
if (!running_slideshow) {
if (!iv->running_slideshow) {
rb->lcd_putsf(0, 1, "loading %zu bytes", file_size);
rb->lcd_update();
}
@ -142,12 +137,12 @@ int load_image(char *filename, struct image_info *info,
rb->read(fd, image, file_size);
rb->close(fd);
if (!running_slideshow) {
if (!iv->running_slideshow) {
rb->lcd_puts(0, 2, "decoding image");
rb->lcd_update();
}
#ifdef DISK_SPINDOWN
else if (immediate_ata_off) {
else if (iv->immediate_ata_off) {
/* running slideshow and time is long enough: power down disk */
rb->storage_sleep();
}
@ -167,7 +162,7 @@ int load_image(char *filename, struct image_info *info,
if (!p_decoder->error) {
if (!running_slideshow) {
if (!iv->running_slideshow) {
rb->lcd_putsf(0, 2, "image %dx%d",
p_decoder->infoPng.width,
p_decoder->infoPng.height);
@ -181,16 +176,16 @@ int load_image(char *filename, struct image_info *info,
time = *rb->current_tick;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(true);
LodePNG_decode(p_decoder, image, file_size, cb_progress);
LodePNG_decode(p_decoder, image, file_size, iv->cb_progress);
rb->cpu_boost(false);
#else
LodePNG_decode(p_decoder, image, file_size, cb_progress);
LodePNG_decode(p_decoder, image, file_size, iv->cb_progress);
#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
time = *rb->current_tick - time;
}
}
if (!running_slideshow && !p_decoder->error)
if (!iv->running_slideshow && !p_decoder->error)
{
rb->snprintf(print, sizeof(print), " %ld.%02ld sec ", time/HZ, time%HZ);
rb->lcd_getstringsize(print, &w, &h); /* centered in progress bar */
@ -200,7 +195,7 @@ int load_image(char *filename, struct image_info *info,
if (p_decoder->error) {
#ifdef USE_PLUG_BUF
if (plug_buf && (p_decoder->error == FILE_TOO_LARGE ||
if (iv->plug_buf && (p_decoder->error == FILE_TOO_LARGE ||
p_decoder->error == OUT_OF_MEMORY ||
p_decoder->error == TINF_DATA_ERROR))
return PLUGIN_OUTOFMEM;
@ -244,7 +239,7 @@ int load_image(char *filename, struct image_info *info,
return PLUGIN_OK;
}
int get_image(struct image_info *info, int ds)
static int get_image(struct image_info *info, int ds)
{
unsigned char **p_disp = &disp[ds]; /* short cut */
LodePNG_Decoder *p_decoder = &decoder;
@ -261,7 +256,7 @@ int get_image(struct image_info *info, int ds)
/* assign image buffer */
if (ds > 1) {
if (!running_slideshow)
if (!iv->running_slideshow)
{
rb->lcd_putsf(0, 3, "resizing %d*%d", info->width, info->height);
rb->lcd_update();
@ -303,3 +298,13 @@ int get_image(struct image_info *info, int ds)
return PLUGIN_OK;
}
const struct image_decoder image_decoder = {
true,
img_mem,
load_image,
get_image,
draw_image_rect,
};
IMGDEC_HEADER

View file

@ -10,18 +10,19 @@
PNGSRCDIR := $(IMGVSRCDIR)/png
PNGBUILDDIR := $(IMGVBUILDDIR)/png
ROCKS += $(PNGBUILDDIR)/png.rock
PNG_SRC := $(call preprocess, $(PNGSRCDIR)/SOURCES)
PNG_OBJ := $(call c2obj, $(PNG_SRC))
# add source files to OTHER_SRC to get automatic dependencies
OTHER_SRC += $(PNG_SRC)
# Use -O3 for png plugin : it gives a bigger file but very good performances
PNGFLAGS = $(PLUGINFLAGS) -Os
ROCKS += $(PNGBUILDDIR)/png.ovl
$(PNGBUILDDIR)/png.rock: $(PNG_OBJ)
$(PNGBUILDDIR)/png.refmap: $(PNG_OBJ)
$(PNGBUILDDIR)/png.link: $(PNG_OBJ) $(PNGBUILDDIR)/png.refmap
$(PNGBUILDDIR)/png.ovl: $(PNG_OBJ)
# Use -O3 for png plugin : it gives a bigger file but very good performances
PNGFLAGS = $(IMGDECFLAGS) -Os
# Compile PNG plugin with extra flags (adapted from ZXBox)
$(PNGBUILDDIR)/%.o: $(PNGSRCDIR)/%.c $(PNGSRCDIR)/png.make

View file

@ -1,5 +0,0 @@
#define PNG_VIEWER
#define MENU_TITLE "Png Menu"
#define UNSCALED_IS_AVAILABLE 1
#include "../imageviewer.c"