2008-10-21 16:05:46 +00:00
|
|
|
/***************************************************************************
|
2010-01-18 12:46:19 +00:00
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2010-11-21 13:47:56 +00:00
|
|
|
* user intereface of image viewer
|
2010-01-18 12:46:19 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* - check magick value in file header to determine image type.
|
|
|
|
*/
|
2008-10-21 16:05:46 +00:00
|
|
|
#include "plugin.h"
|
|
|
|
#include <lib/playback_control.h>
|
|
|
|
#include <lib/helper.h>
|
|
|
|
#include <lib/configfile.h>
|
2010-01-18 12:46:19 +00:00
|
|
|
#include "imageviewer.h"
|
2011-01-17 13:47:57 +00:00
|
|
|
#include "imageviewer_button.h"
|
2010-11-21 13:47:56 +00:00
|
|
|
#include "image_decoder.h"
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#ifdef USEGSLIB
|
2008-10-21 16:05:46 +00:00
|
|
|
GREY_INFO_STRUCT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Headings */
|
|
|
|
#define DIR_PREV 1
|
|
|
|
#define DIR_NEXT -1
|
|
|
|
#define DIR_NONE 0
|
|
|
|
|
|
|
|
/******************************* Globals ***********************************/
|
|
|
|
|
|
|
|
/* Persistent configuration */
|
2010-01-18 12:46:19 +00:00
|
|
|
#define IMGVIEW_CONFIGFILE "imageviewer.cfg"
|
|
|
|
#define IMGVIEW_SETTINGS_MINVERSION 1
|
|
|
|
#define IMGVIEW_SETTINGS_VERSION 2
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
/* Slideshow times */
|
2010-01-18 12:46:19 +00:00
|
|
|
#define SS_MIN_TIMEOUT 1
|
|
|
|
#define SS_MAX_TIMEOUT 20
|
|
|
|
#define SS_DEFAULT_TIMEOUT 5
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
2010-01-18 12:46:19 +00:00
|
|
|
/* needed for value of settings */
|
|
|
|
#include "jpeg/yuv2rgb.h"
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
static struct imgview_settings settings =
|
2009-12-18 13:06:21 +00:00
|
|
|
{
|
2008-10-21 16:05:46 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2009-12-18 13:06:21 +00:00
|
|
|
COLOURMODE_COLOUR,
|
|
|
|
DITHER_NONE,
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2009-12-18 13:06:21 +00:00
|
|
|
SS_DEFAULT_TIMEOUT
|
|
|
|
};
|
2010-01-18 12:46:19 +00:00
|
|
|
static struct imgview_settings old_settings;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
static struct configdata config[] =
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
2010-01-18 12:46:19 +00:00
|
|
|
{ TYPE_ENUM, 0, COLOUR_NUM_MODES, { .int_p = &settings.jpeg_colour_mode },
|
2009-12-18 13:06:21 +00:00
|
|
|
"Colour Mode", (char *[]){ "Colour", "Grayscale" } },
|
2010-01-18 12:46:19 +00:00
|
|
|
{ TYPE_ENUM, 0, DITHER_NUM_MODES, { .int_p = &settings.jpeg_dither_mode },
|
2009-12-18 13:06:21 +00:00
|
|
|
"Dither Mode", (char *[]){ "None", "Ordered", "Diffusion" } },
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2009-12-18 13:06:21 +00:00
|
|
|
{ TYPE_INT, SS_MIN_TIMEOUT, SS_MAX_TIMEOUT,
|
2010-01-18 12:46:19 +00:00
|
|
|
{ .int_p = &settings.ss_timeout }, "Slideshow Time", NULL },
|
2008-10-21 16:05:46 +00:00
|
|
|
};
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
static void cb_progress(int current, int total);
|
|
|
|
|
|
|
|
static struct imgdec_api iv_api = {
|
|
|
|
.settings = &settings,
|
|
|
|
.slideshow_enabled = false,
|
|
|
|
.running_slideshow = false,
|
|
|
|
#ifdef DISK_SPINDOWN
|
|
|
|
.immediate_ata_off = false,
|
|
|
|
#endif
|
|
|
|
#ifdef USE_PLUG_BUF
|
|
|
|
.plug_buf = true,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.cb_progress = cb_progress,
|
|
|
|
|
|
|
|
#ifdef USEGSLIB
|
|
|
|
.gray_bitmap_part = myxlcd_ub_(gray_bitmap_part),
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
/**************** begin Application ********************/
|
|
|
|
|
|
|
|
|
|
|
|
/************************* Globals ***************************/
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2010-01-18 12:46:19 +00:00
|
|
|
static fb_data rgb_linebuf[LCD_WIDTH]; /* Line buffer for scrolling when
|
|
|
|
DITHER_DIFFUSION is set */
|
|
|
|
#endif
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
/* buffer to load image decoder */
|
|
|
|
static unsigned char* decoder_buf;
|
|
|
|
static size_t decoder_buf_size;
|
2010-01-18 12:46:19 +00:00
|
|
|
/* the remaining free part of the buffer for loaded+resized images */
|
2009-11-17 15:15:29 +00:00
|
|
|
static unsigned char* buf;
|
2010-05-07 19:35:09 +00:00
|
|
|
static size_t buf_size;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2008-10-22 08:50:13 +00:00
|
|
|
static int ds, ds_min, ds_max; /* downscaling and limits */
|
2010-01-18 12:46:19 +00:00
|
|
|
static struct image_info image_info;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
/* the current full file name */
|
|
|
|
static char np_file[MAX_PATH];
|
2010-11-21 13:47:56 +00:00
|
|
|
static int curfile = -1, direction = DIR_NEXT, entries = 0;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
/* list of the supported image files */
|
2008-10-22 08:50:13 +00:00
|
|
|
static char **file_pt;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
static const struct image_decoder *imgdec = NULL;
|
|
|
|
static enum image_type image_type = IMAGE_UNKNOWN;
|
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
/************************* Implementation ***************************/
|
|
|
|
|
2010-01-21 12:06:02 +00:00
|
|
|
/* Read directory contents for scrolling. */
|
2010-01-18 12:46:19 +00:00
|
|
|
static void get_pic_list(void)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-02-12 14:41:52 +00:00
|
|
|
struct tree_context *tree = rb->tree_get_context();
|
|
|
|
struct entry *dircache = tree->dircache;
|
2008-10-21 16:05:46 +00:00
|
|
|
int i;
|
|
|
|
char *pname;
|
|
|
|
|
2009-11-15 16:14:45 +00:00
|
|
|
file_pt = (char **) buf;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
/* Remove path and leave only the name.*/
|
|
|
|
pname = rb->strrchr(np_file,'/');
|
|
|
|
pname++;
|
|
|
|
|
2010-05-07 19:36:51 +00:00
|
|
|
for (i = 0; i < tree->filesindir && buf_size > sizeof(char**); i++)
|
2009-11-15 16:14:45 +00:00
|
|
|
{
|
2011-01-22 13:41:53 +00:00
|
|
|
/* Add all files. Non-image files will be filtered out while loading. */
|
|
|
|
if (!(dircache[i].attr & ATTR_DIRECTORY))
|
2009-11-15 16:14:45 +00:00
|
|
|
{
|
|
|
|
file_pt[entries] = dircache[i].name;
|
|
|
|
/* Set Selected File. */
|
|
|
|
if (!rb->strcmp(file_pt[entries], pname))
|
|
|
|
curfile = entries;
|
|
|
|
entries++;
|
2010-05-07 19:36:51 +00:00
|
|
|
|
|
|
|
buf += (sizeof(char**));
|
|
|
|
buf_size -= (sizeof(char**));
|
2009-11-15 16:14:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
static int change_filename(int direct)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2009-11-18 13:54:14 +00:00
|
|
|
bool file_erased = (file_pt[curfile] == NULL);
|
2008-10-21 16:05:46 +00:00
|
|
|
direction = direct;
|
|
|
|
|
2009-11-18 13:54:14 +00:00
|
|
|
curfile += (direct == DIR_PREV? entries - 1: 1);
|
|
|
|
if (curfile >= entries)
|
|
|
|
curfile -= entries;
|
|
|
|
|
|
|
|
if (file_erased)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2009-11-18 13:54:14 +00:00
|
|
|
/* remove 'erased' file names from list. */
|
|
|
|
int count, i;
|
|
|
|
for (count = i = 0; i < entries; i++)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2009-11-18 13:54:14 +00:00
|
|
|
if (curfile == i)
|
|
|
|
curfile = count;
|
|
|
|
if (file_pt[i] != NULL)
|
|
|
|
file_pt[count++] = file_pt[i];
|
|
|
|
}
|
|
|
|
entries = count;
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 13:54:14 +00:00
|
|
|
if (entries == 0)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
rb->splash(HZ, "No supported files");
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
2009-11-18 13:54:14 +00:00
|
|
|
|
2010-02-12 14:41:52 +00:00
|
|
|
rb->strcpy(rb->strrchr(np_file, '/')+1, file_pt[curfile]);
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
return PLUGIN_OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* switch off overlay, for handling SYS_ events */
|
2010-01-18 12:46:19 +00:00
|
|
|
static void cleanup(void *parameter)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
(void)parameter;
|
|
|
|
#ifdef USEGSLIB
|
|
|
|
grey_show(false);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2010-01-18 12:46:19 +00:00
|
|
|
static bool set_option_grayscale(void)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
bool gray = settings.jpeg_colour_mode == COLOURMODE_GRAY;
|
2010-11-21 13:47:56 +00:00
|
|
|
rb->set_bool("Grayscale (Jpeg)", &gray);
|
2010-01-18 12:46:19 +00:00
|
|
|
settings.jpeg_colour_mode = gray ? COLOURMODE_GRAY : COLOURMODE_COLOUR;
|
2008-10-21 16:05:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
static bool set_option_dithering(void)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
static const struct opt_items dithering[DITHER_NUM_MODES] = {
|
|
|
|
[DITHER_NONE] = { "Off", -1 },
|
|
|
|
[DITHER_ORDERED] = { "Ordered", -1 },
|
|
|
|
[DITHER_DIFFUSION] = { "Diffusion", -1 },
|
|
|
|
};
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
rb->set_option("Dithering (Jpeg)", &settings.jpeg_dither_mode, INT,
|
2008-10-21 16:05:46 +00:00
|
|
|
dithering, DITHER_NUM_MODES, NULL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
MENUITEM_FUNCTION(grayscale_item, 0, "Greyscale (Jpeg)",
|
2009-06-16 04:25:21 +00:00
|
|
|
set_option_grayscale, NULL, NULL, Icon_NOICON);
|
2010-11-21 13:47:56 +00:00
|
|
|
MENUITEM_FUNCTION(dithering_item, 0, "Dithering (Jpeg)",
|
2009-06-16 04:25:21 +00:00
|
|
|
set_option_dithering, NULL, NULL, Icon_NOICON);
|
|
|
|
MAKE_MENU(display_menu, "Display Options", NULL, Icon_NOICON,
|
|
|
|
&grayscale_item, &dithering_item);
|
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
static void display_options(void)
|
|
|
|
{
|
2009-06-16 04:25:21 +00:00
|
|
|
rb->do_menu(&display_menu, NULL, NULL, false);
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
2010-11-21 13:47:56 +00:00
|
|
|
#endif /* HAVE_LCD_COLOR */
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
static int show_menu(void) /* return 1 to quit */
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
enum menu_id
|
|
|
|
{
|
2009-06-16 04:25:21 +00:00
|
|
|
MIID_RETURN = 0,
|
2008-10-21 16:05:46 +00:00
|
|
|
MIID_TOGGLE_SS_MODE,
|
|
|
|
MIID_CHANGE_SS_MODE,
|
2010-02-12 14:41:52 +00:00
|
|
|
#ifdef USE_PLUG_BUF
|
2008-10-21 16:05:46 +00:00
|
|
|
MIID_SHOW_PLAYBACK_MENU,
|
|
|
|
#endif
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2008-10-21 16:05:46 +00:00
|
|
|
MIID_DISPLAY_OPTIONS,
|
|
|
|
#endif
|
2009-06-16 04:25:21 +00:00
|
|
|
MIID_QUIT,
|
2008-10-21 16:05:46 +00:00
|
|
|
};
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Image Viewer Menu", NULL,
|
2009-06-16 04:25:21 +00:00
|
|
|
"Return", "Toggle Slideshow Mode",
|
|
|
|
"Change Slideshow Time",
|
2010-02-12 14:41:52 +00:00
|
|
|
#ifdef USE_PLUG_BUF
|
2009-06-16 04:25:21 +00:00
|
|
|
"Show Playback Menu",
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2009-06-16 04:25:21 +00:00
|
|
|
"Display Options",
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2009-06-16 04:25:21 +00:00
|
|
|
"Quit");
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
static const struct opt_items slideshow[2] = {
|
|
|
|
{ "Disable", -1 },
|
|
|
|
{ "Enable", -1 },
|
|
|
|
};
|
|
|
|
|
2009-06-16 04:25:21 +00:00
|
|
|
result=rb->do_menu(&menu, NULL, NULL, false);
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
switch (result)
|
|
|
|
{
|
2009-06-16 04:25:21 +00:00
|
|
|
case MIID_RETURN:
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
case MIID_TOGGLE_SS_MODE:
|
2010-11-21 13:47:56 +00:00
|
|
|
rb->set_option("Toggle Slideshow", &iv_api.slideshow_enabled, BOOL,
|
2008-10-21 16:05:46 +00:00
|
|
|
slideshow , 2, NULL);
|
|
|
|
break;
|
|
|
|
case MIID_CHANGE_SS_MODE:
|
|
|
|
rb->set_int("Slideshow Time", "s", UNIT_SEC,
|
2010-01-18 12:46:19 +00:00
|
|
|
&settings.ss_timeout, NULL, 1,
|
2008-10-21 16:05:46 +00:00
|
|
|
SS_MIN_TIMEOUT, SS_MAX_TIMEOUT, NULL);
|
|
|
|
break;
|
|
|
|
|
2010-02-12 14:41:52 +00:00
|
|
|
#ifdef USE_PLUG_BUF
|
2008-10-21 16:05:46 +00:00
|
|
|
case MIID_SHOW_PLAYBACK_MENU:
|
2010-11-21 13:47:56 +00:00
|
|
|
if (iv_api.plug_buf)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2009-01-16 10:34:40 +00:00
|
|
|
playback_control(NULL);
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->splash(HZ, "Cannot restart playback");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2008-10-21 16:05:46 +00:00
|
|
|
case MIID_DISPLAY_OPTIONS:
|
|
|
|
display_options();
|
|
|
|
break;
|
|
|
|
#endif
|
2009-06-16 04:25:21 +00:00
|
|
|
case MIID_QUIT:
|
|
|
|
return 1;
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#ifdef DISK_SPINDOWN
|
2008-10-21 16:05:46 +00:00
|
|
|
/* change ata spindown time based on slideshow time setting */
|
2010-11-21 13:47:56 +00:00
|
|
|
iv_api.immediate_ata_off = false;
|
2008-11-01 16:14:28 +00:00
|
|
|
rb->storage_spindown(rb->global_settings->disk_spindown);
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
if (iv_api.slideshow_enabled)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
if(settings.ss_timeout < 10)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
/* slideshow times < 10s keep disk spinning */
|
2008-11-01 16:14:28 +00:00
|
|
|
rb->storage_spindown(0);
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
else if (!rb->mp3_is_playing())
|
|
|
|
{
|
|
|
|
/* slideshow times > 10s and not playing: ata_off after load */
|
2010-11-21 13:47:56 +00:00
|
|
|
iv_api.immediate_ata_off = true;
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
rb->lcd_set_foreground(LCD_WHITE);
|
|
|
|
rb->lcd_set_background(LCD_BLACK);
|
|
|
|
#endif
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-23 08:05:25 +00:00
|
|
|
|
2010-02-12 14:41:52 +00:00
|
|
|
#ifdef USE_PLUG_BUF
|
|
|
|
static int ask_and_get_audio_buffer(const char *filename)
|
|
|
|
{
|
2011-01-17 13:47:57 +00:00
|
|
|
int button;
|
|
|
|
int lastbutton = BUTTON_NONE;
|
2010-02-12 14:41:52 +00:00
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1);
|
|
|
|
rb->lcd_puts(0, 1, "Not enough plugin memory!");
|
|
|
|
rb->lcd_puts(0, 2, "Zoom In: Stop playback.");
|
|
|
|
if(entries > 1)
|
|
|
|
rb->lcd_puts(0, 3, "Left/Right: Skip File.");
|
|
|
|
rb->lcd_puts(0, 4, "Show Menu: Quit.");
|
|
|
|
rb->lcd_update();
|
|
|
|
rb->lcd_setfont(FONT_UI);
|
|
|
|
|
|
|
|
rb->button_clear_queue();
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2011-01-17 13:47:57 +00:00
|
|
|
if (iv_api.slideshow_enabled)
|
|
|
|
button = rb->button_get_w_tmo(settings.ss_timeout * HZ);
|
|
|
|
else
|
|
|
|
button = rb->button_get(true);
|
|
|
|
|
2010-02-12 14:41:52 +00:00
|
|
|
switch(button)
|
|
|
|
{
|
|
|
|
case IMGVIEW_ZOOM_IN:
|
2011-01-17 13:47:57 +00:00
|
|
|
#ifdef IMGVIEW_ZOOM_PRE
|
|
|
|
if (lastbutton != IMGVIEW_ZOOM_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2010-11-21 13:47:56 +00:00
|
|
|
iv_api.plug_buf = false;
|
2010-05-07 19:35:09 +00:00
|
|
|
buf = rb->plugin_get_audio_buffer(&buf_size);
|
2010-02-12 14:41:52 +00:00
|
|
|
/*try again this file, now using the audio buffer */
|
|
|
|
return PLUGIN_OTHER;
|
|
|
|
#ifdef IMGVIEW_RC_MENU
|
|
|
|
case IMGVIEW_RC_MENU:
|
2010-02-25 11:11:41 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IMGVIEW_QUIT
|
|
|
|
case IMGVIEW_QUIT:
|
2010-02-12 14:41:52 +00:00
|
|
|
#endif
|
|
|
|
case IMGVIEW_MENU:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
|
|
|
|
case IMGVIEW_LEFT:
|
|
|
|
if(entries>1)
|
|
|
|
{
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
return change_filename(DIR_PREV);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMGVIEW_RIGHT:
|
|
|
|
if(entries>1)
|
|
|
|
{
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
return change_filename(DIR_NEXT);
|
|
|
|
}
|
|
|
|
break;
|
2011-01-17 13:47:57 +00:00
|
|
|
case BUTTON_NONE:
|
|
|
|
if(entries>1)
|
|
|
|
{
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
return change_filename(direction);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-02-12 14:41:52 +00:00
|
|
|
default:
|
|
|
|
if(rb->default_event_handler_ex(button, cleanup, NULL)
|
|
|
|
== SYS_USB_CONNECTED)
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
}
|
2011-01-17 13:47:57 +00:00
|
|
|
|
|
|
|
if (button != BUTTON_NONE)
|
|
|
|
lastbutton = button;
|
2010-02-12 14:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USE_PLUG_BUF */
|
|
|
|
|
|
|
|
/* callback updating a progress meter while image decoding */
|
2010-11-21 13:47:56 +00:00
|
|
|
static void cb_progress(int current, int total)
|
2010-02-12 14:41:52 +00:00
|
|
|
{
|
|
|
|
rb->yield(); /* be nice to the other threads */
|
|
|
|
#ifndef USEGSLIB
|
|
|
|
/* in slideshow mode, keep gui interference to a minimum */
|
2010-11-21 13:47:56 +00:00
|
|
|
const int size = (!iv_api.running_slideshow ? 8 : 4);
|
2010-02-12 14:41:52 +00:00
|
|
|
#else
|
|
|
|
const int size = 8;
|
2010-11-21 13:47:56 +00:00
|
|
|
if(!iv_api.running_slideshow)
|
2010-02-12 14:41:52 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
|
|
|
|
0, LCD_HEIGHT-size, LCD_WIDTH, size,
|
|
|
|
total, 0, current, HORIZONTAL);
|
|
|
|
rb->lcd_update_rect(0, LCD_HEIGHT-size, LCD_WIDTH, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VSCROLL (LCD_HEIGHT/8)
|
|
|
|
#define HSCROLL (LCD_WIDTH/10)
|
|
|
|
|
2008-10-23 08:05:25 +00:00
|
|
|
/* Pan the viewing window right - move image to the left and fill in
|
|
|
|
the right-hand side */
|
2010-01-18 12:46:19 +00:00
|
|
|
static void pan_view_right(struct image_info *info)
|
2008-10-23 08:05:25 +00:00
|
|
|
{
|
|
|
|
int move;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
move = MIN(HSCROLL, info->width - info->x - LCD_WIDTH);
|
2008-10-23 08:05:25 +00:00
|
|
|
if (move > 0)
|
|
|
|
{
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_scroll_left(move); /* scroll left */
|
2010-01-18 12:46:19 +00:00
|
|
|
info->x += move;
|
2010-11-21 13:47:56 +00:00
|
|
|
imgdec->draw_image_rect(info, LCD_WIDTH - move, 0,
|
|
|
|
move, info->height-info->y);
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_update();
|
2008-10-23 08:05:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pan the viewing window left - move image to the right and fill in
|
|
|
|
the left-hand side */
|
2010-01-18 12:46:19 +00:00
|
|
|
static void pan_view_left(struct image_info *info)
|
2008-10-23 08:05:25 +00:00
|
|
|
{
|
|
|
|
int move;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
move = MIN(HSCROLL, info->x);
|
2008-10-23 08:05:25 +00:00
|
|
|
if (move > 0)
|
|
|
|
{
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_scroll_right(move); /* scroll right */
|
2010-01-18 12:46:19 +00:00
|
|
|
info->x -= move;
|
2010-11-21 13:47:56 +00:00
|
|
|
imgdec->draw_image_rect(info, 0, 0, move, info->height-info->y);
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_update();
|
2008-10-23 08:05:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pan the viewing window up - move image down and fill in
|
|
|
|
the top */
|
2010-01-18 12:46:19 +00:00
|
|
|
static void pan_view_up(struct image_info *info)
|
2008-10-23 08:05:25 +00:00
|
|
|
{
|
|
|
|
int move;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
move = MIN(VSCROLL, info->y);
|
2008-10-23 08:05:25 +00:00
|
|
|
if (move > 0)
|
|
|
|
{
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_scroll_down(move); /* scroll down */
|
2010-01-18 12:46:19 +00:00
|
|
|
info->y -= move;
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
if (image_type == IMAGE_JPEG
|
|
|
|
&& settings.jpeg_dither_mode == DITHER_DIFFUSION)
|
2008-10-23 08:05:25 +00:00
|
|
|
{
|
|
|
|
/* Draw over the band at the top of the last update
|
|
|
|
caused by lack of error history on line zero. */
|
2010-01-18 12:46:19 +00:00
|
|
|
move = MIN(move + 1, info->y + info->height);
|
2008-10-23 08:05:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-11-21 13:47:56 +00:00
|
|
|
imgdec->draw_image_rect(info, 0, 0, info->width-info->x, move);
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_update();
|
2008-10-23 08:05:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pan the viewing window down - move image up and fill in
|
|
|
|
the bottom */
|
2010-01-18 12:46:19 +00:00
|
|
|
static void pan_view_down(struct image_info *info)
|
2008-10-23 08:05:25 +00:00
|
|
|
{
|
|
|
|
int move;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
move = MIN(VSCROLL, info->height - info->y - LCD_HEIGHT);
|
2008-10-23 08:05:25 +00:00
|
|
|
if (move > 0)
|
|
|
|
{
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_scroll_up(move); /* scroll up */
|
2010-01-18 12:46:19 +00:00
|
|
|
info->y += move;
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
if (image_type == IMAGE_JPEG
|
|
|
|
&& settings.jpeg_dither_mode == DITHER_DIFFUSION)
|
2008-10-23 08:05:25 +00:00
|
|
|
{
|
|
|
|
/* Save the line that was on the last line of the display
|
|
|
|
and draw one extra line above then recover the line with
|
|
|
|
image data that had an error history when it was drawn.
|
|
|
|
*/
|
2010-01-18 12:46:19 +00:00
|
|
|
move++, info->y--;
|
2008-10-23 08:05:25 +00:00
|
|
|
rb->memcpy(rgb_linebuf,
|
2009-12-18 13:06:21 +00:00
|
|
|
rb->lcd_framebuffer + (LCD_HEIGHT - move)*LCD_WIDTH,
|
|
|
|
LCD_WIDTH*sizeof (fb_data));
|
2008-10-23 08:05:25 +00:00
|
|
|
}
|
2009-11-15 14:03:57 +00:00
|
|
|
#endif
|
2008-10-23 08:05:25 +00:00
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
imgdec->draw_image_rect(info, 0, LCD_HEIGHT - move,
|
|
|
|
info->width-info->x, move);
|
2008-10-23 08:05:25 +00:00
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
if (image_type == IMAGE_JPEG
|
|
|
|
&& settings.jpeg_dither_mode == DITHER_DIFFUSION)
|
2008-10-23 08:05:25 +00:00
|
|
|
{
|
|
|
|
/* Cover the first row drawn with previous image data. */
|
|
|
|
rb->memcpy(rb->lcd_framebuffer + (LCD_HEIGHT - move)*LCD_WIDTH,
|
2009-12-18 13:06:21 +00:00
|
|
|
rgb_linebuf, LCD_WIDTH*sizeof (fb_data));
|
2010-01-18 12:46:19 +00:00
|
|
|
info->y++;
|
2008-10-23 08:05:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_update();
|
2008-10-23 08:05:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
/* interactively scroll around the image */
|
2010-01-18 12:46:19 +00:00
|
|
|
static int scroll_bmp(struct image_info *info)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2008-10-23 08:05:25 +00:00
|
|
|
int button;
|
2010-02-12 14:41:52 +00:00
|
|
|
int lastbutton = BUTTON_NONE;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
2010-11-21 13:47:56 +00:00
|
|
|
if (iv_api.slideshow_enabled)
|
2010-01-18 12:46:19 +00:00
|
|
|
button = rb->button_get_w_tmo(settings.ss_timeout * HZ);
|
2009-12-18 13:06:21 +00:00
|
|
|
else
|
|
|
|
button = rb->button_get(true);
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
iv_api.running_slideshow = false;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
switch(button)
|
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_LEFT:
|
|
|
|
if (entries > 1 && info->width <= LCD_WIDTH
|
|
|
|
&& info->height <= LCD_HEIGHT)
|
2008-10-21 16:05:46 +00:00
|
|
|
return change_filename(DIR_PREV);
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_LEFT | BUTTON_REPEAT:
|
|
|
|
pan_view_left(info);
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_RIGHT:
|
|
|
|
if (entries > 1 && info->width <= LCD_WIDTH
|
|
|
|
&& info->height <= LCD_HEIGHT)
|
2008-10-21 16:05:46 +00:00
|
|
|
return change_filename(DIR_NEXT);
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_RIGHT | BUTTON_REPEAT:
|
|
|
|
pan_view_right(info);
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_UP:
|
|
|
|
case IMGVIEW_UP | BUTTON_REPEAT:
|
|
|
|
pan_view_up(info);
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_DOWN:
|
|
|
|
case IMGVIEW_DOWN | BUTTON_REPEAT:
|
|
|
|
pan_view_down(info);
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
2008-10-23 08:05:25 +00:00
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
case BUTTON_NONE:
|
2010-11-21 13:47:56 +00:00
|
|
|
if (iv_api.slideshow_enabled && entries > 1)
|
2010-02-12 14:41:52 +00:00
|
|
|
{
|
2010-11-21 13:47:56 +00:00
|
|
|
iv_api.running_slideshow = true;
|
2008-10-21 16:05:46 +00:00
|
|
|
return change_filename(DIR_NEXT);
|
2010-02-12 14:41:52 +00:00
|
|
|
}
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#ifdef IMGVIEW_SLIDE_SHOW
|
|
|
|
case IMGVIEW_SLIDE_SHOW:
|
2010-11-21 13:47:56 +00:00
|
|
|
iv_api.slideshow_enabled = !iv_api.slideshow_enabled;
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#ifdef IMGVIEW_NEXT_REPEAT
|
|
|
|
case IMGVIEW_NEXT_REPEAT:
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_NEXT:
|
2009-11-18 13:54:14 +00:00
|
|
|
if (entries > 1)
|
2008-10-21 16:05:46 +00:00
|
|
|
return change_filename(DIR_NEXT);
|
|
|
|
break;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#ifdef IMGVIEW_PREVIOUS_REPEAT
|
|
|
|
case IMGVIEW_PREVIOUS_REPEAT:
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_PREVIOUS:
|
2009-11-18 13:54:14 +00:00
|
|
|
if (entries > 1)
|
2008-10-21 16:05:46 +00:00
|
|
|
return change_filename(DIR_PREV);
|
|
|
|
break;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_ZOOM_IN:
|
|
|
|
#ifdef IMGVIEW_ZOOM_PRE
|
|
|
|
if (lastbutton != IMGVIEW_ZOOM_PRE)
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
return ZOOM_IN;
|
|
|
|
break;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_ZOOM_OUT:
|
|
|
|
#ifdef IMGVIEW_ZOOM_PRE
|
|
|
|
if (lastbutton != IMGVIEW_ZOOM_PRE)
|
2008-10-21 16:05:46 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
return ZOOM_OUT;
|
|
|
|
break;
|
2010-02-12 14:41:52 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#ifdef IMGVIEW_RC_MENU
|
|
|
|
case IMGVIEW_RC_MENU:
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_MENU:
|
2010-02-25 11:11:41 +00:00
|
|
|
#ifdef IMGVIEW_MENU_PRE
|
|
|
|
if (lastbutton != IMGVIEW_MENU_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
2008-10-21 16:05:46 +00:00
|
|
|
#ifdef USEGSLIB
|
|
|
|
grey_show(false); /* switch off greyscale overlay */
|
|
|
|
#endif
|
|
|
|
if (show_menu() == 1)
|
|
|
|
return PLUGIN_OK;
|
|
|
|
|
|
|
|
#ifdef USEGSLIB
|
|
|
|
grey_show(true); /* switch on greyscale overlay */
|
|
|
|
#else
|
2010-11-21 13:47:56 +00:00
|
|
|
imgdec->draw_image_rect(info, 0, 0,
|
2010-01-18 12:46:19 +00:00
|
|
|
info->width-info->x, info->height-info->y);
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_update();
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
|
|
|
break;
|
2010-02-12 14:41:52 +00:00
|
|
|
|
2010-02-25 11:11:41 +00:00
|
|
|
#ifdef IMGVIEW_QUIT
|
|
|
|
case IMGVIEW_QUIT:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
default:
|
|
|
|
if (rb->default_event_handler_ex(button, cleanup, NULL)
|
|
|
|
== SYS_USB_CONNECTED)
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
} /* switch */
|
|
|
|
|
|
|
|
if (button != BUTTON_NONE)
|
|
|
|
lastbutton = button;
|
|
|
|
} /* while (true) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************* main function *************************/
|
|
|
|
|
|
|
|
/* how far can we zoom in without running out of memory */
|
2010-01-18 12:46:19 +00:00
|
|
|
static int min_downscale(int bufsize)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
int downscale = 8;
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
if (imgdec->img_mem(8) > bufsize)
|
2008-10-21 16:05:46 +00:00
|
|
|
return 0; /* error, too large, even 1:8 doesn't fit */
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
while (downscale > 1 && imgdec->img_mem(downscale/2) <= bufsize)
|
2008-10-21 16:05:46 +00:00
|
|
|
downscale /= 2;
|
|
|
|
|
|
|
|
return downscale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* how far can we zoom out, to fit image into the LCD */
|
2010-01-18 12:46:19 +00:00
|
|
|
static int max_downscale(struct image_info *info)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
int downscale = 1;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
while (downscale < 8 && (info->x_size/downscale > LCD_WIDTH
|
|
|
|
|| info->y_size/downscale > LCD_HEIGHT))
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
downscale *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return downscale;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the view to the given center point, limit if necessary */
|
2010-01-18 12:46:19 +00:00
|
|
|
static void set_view(struct image_info *info, int cx, int cy)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* plain center to available width/height */
|
2010-01-18 12:46:19 +00:00
|
|
|
x = cx - MIN(LCD_WIDTH, info->width) / 2;
|
|
|
|
y = cy - MIN(LCD_HEIGHT, info->height) / 2;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
/* limit against upper image size */
|
2010-01-18 12:46:19 +00:00
|
|
|
x = MIN(info->width - LCD_WIDTH, x);
|
|
|
|
y = MIN(info->height - LCD_HEIGHT, y);
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
/* limit against negative side */
|
|
|
|
x = MAX(0, x);
|
|
|
|
y = MAX(0, y);
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
info->x = x; /* set the values */
|
|
|
|
info->y = y;
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate the view center based on the bitmap position */
|
2010-01-18 12:46:19 +00:00
|
|
|
static void get_view(struct image_info *info, int *p_cx, int *p_cy)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
*p_cx = info->x + MIN(LCD_WIDTH, info->width) / 2;
|
|
|
|
*p_cy = info->y + MIN(LCD_HEIGHT, info->height) / 2;
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load, decode, display the image */
|
2010-01-18 12:46:19 +00:00
|
|
|
static int load_and_show(char* filename, struct image_info *info)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
int status;
|
2010-01-18 12:46:19 +00:00
|
|
|
int cx, cy;
|
|
|
|
ssize_t remaining;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2009-12-18 13:06:21 +00:00
|
|
|
rb->lcd_clear_display();
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2011-01-22 13:41:53 +00:00
|
|
|
/* suppress warning while running slideshow */
|
|
|
|
status = get_image_type(filename, iv_api.running_slideshow);
|
|
|
|
if (status == IMAGE_UNKNOWN) {
|
|
|
|
/* file isn't supported image file, skip this. */
|
|
|
|
file_pt[curfile] = NULL;
|
|
|
|
return change_filename(direction);
|
|
|
|
}
|
2010-11-21 13:47:56 +00:00
|
|
|
if (image_type != status) /* type of image is changed, load decoder. */
|
|
|
|
{
|
|
|
|
struct loader_info loader_info = {
|
|
|
|
status, &iv_api, decoder_buf, decoder_buf_size,
|
|
|
|
};
|
|
|
|
image_type = status;
|
|
|
|
imgdec = load_decoder(&loader_info);
|
|
|
|
if (imgdec == NULL)
|
|
|
|
{
|
|
|
|
/* something is wrong */
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
#ifdef USE_PLUG_BUF
|
|
|
|
if(iv_api.plug_buf)
|
|
|
|
{
|
|
|
|
buf = loader_info.buffer;
|
|
|
|
buf_size = loader_info.size;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2010-01-18 12:46:19 +00:00
|
|
|
rb->memset(info, 0, sizeof(*info));
|
|
|
|
remaining = buf_size;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
if (rb->button_get(false) == IMGVIEW_MENU)
|
2009-12-18 13:06:21 +00:00
|
|
|
status = PLUGIN_ABORT;
|
|
|
|
else
|
2010-11-21 13:47:56 +00:00
|
|
|
status = imgdec->load_image(filename, info, buf, &remaining);
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2009-12-18 13:06:21 +00:00
|
|
|
if (status == PLUGIN_OUTOFMEM)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-02-12 14:41:52 +00:00
|
|
|
#ifdef USE_PLUG_BUF
|
2010-11-21 13:47:56 +00:00
|
|
|
if(iv_api.plug_buf)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-02-12 14:41:52 +00:00
|
|
|
return ask_and_get_audio_buffer(filename);
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
rb->splash(HZ, "Out of Memory");
|
2009-12-18 13:06:21 +00:00
|
|
|
file_pt[curfile] = NULL;
|
|
|
|
return change_filename(direction);
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-18 13:06:21 +00:00
|
|
|
else if (status == PLUGIN_ERROR)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2009-11-15 16:14:45 +00:00
|
|
|
file_pt[curfile] = NULL;
|
2008-10-21 16:05:46 +00:00
|
|
|
return change_filename(direction);
|
|
|
|
}
|
2009-12-18 13:06:21 +00:00
|
|
|
else if (status == PLUGIN_ABORT) {
|
2011-01-17 13:47:57 +00:00
|
|
|
rb->splash(HZ, "Aborted");
|
2009-12-18 13:06:21 +00:00
|
|
|
return PLUGIN_OK;
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
2009-12-18 13:06:21 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
ds_max = max_downscale(info); /* check display constraint */
|
|
|
|
ds_min = min_downscale(remaining); /* check memory constraint */
|
2008-10-21 16:05:46 +00:00
|
|
|
if (ds_min == 0)
|
|
|
|
{
|
2010-11-21 13:47:56 +00:00
|
|
|
if (imgdec->unscaled_avail)
|
|
|
|
{
|
|
|
|
/* Can not resize the image but original one is available, so use it. */
|
|
|
|
ds_min = ds_max = 1;
|
|
|
|
}
|
|
|
|
else
|
2010-02-12 14:41:52 +00:00
|
|
|
#ifdef USE_PLUG_BUF
|
2010-11-21 13:47:56 +00:00
|
|
|
if (iv_api.plug_buf)
|
2010-02-12 14:41:52 +00:00
|
|
|
{
|
|
|
|
return ask_and_get_audio_buffer(filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2011-01-17 13:47:57 +00:00
|
|
|
rb->splash(HZ, "Too large");
|
2010-02-12 14:41:52 +00:00
|
|
|
file_pt[curfile] = NULL;
|
|
|
|
return change_filename(direction);
|
|
|
|
}
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
2009-12-18 13:06:21 +00:00
|
|
|
else if (ds_max < ds_min)
|
|
|
|
ds_max = ds_min;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2009-11-15 14:03:57 +00:00
|
|
|
ds = ds_max; /* initialize setting */
|
2010-01-18 12:46:19 +00:00
|
|
|
cx = info->x_size/ds/2; /* center the view */
|
|
|
|
cy = info->y_size/ds/2;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
do /* loop the image prepare and decoding when zoomed */
|
|
|
|
{
|
2010-11-21 13:47:56 +00:00
|
|
|
status = imgdec->get_image(info, ds); /* decode or fetch from cache */
|
2010-01-18 12:46:19 +00:00
|
|
|
if (status == PLUGIN_ERROR)
|
2009-11-18 13:54:14 +00:00
|
|
|
{
|
|
|
|
file_pt[curfile] = NULL;
|
2008-10-21 16:05:46 +00:00
|
|
|
return change_filename(direction);
|
2009-11-18 13:54:14 +00:00
|
|
|
}
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
set_view(info, cx, cy);
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
if(!iv_api.running_slideshow)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsf(0, 3, "showing %dx%d", info->width, info->height);
|
2008-10-21 16:05:46 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
}
|
2009-11-15 14:03:57 +00:00
|
|
|
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_clear_display();
|
2010-11-21 13:47:56 +00:00
|
|
|
imgdec->draw_image_rect(info, 0, 0,
|
2010-01-18 12:46:19 +00:00
|
|
|
info->width-info->x, info->height-info->y);
|
2010-06-04 13:22:50 +00:00
|
|
|
mylcd_ub_update();
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
#ifdef USEGSLIB
|
|
|
|
grey_show(true); /* switch on greyscale overlay */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* drawing is now finished, play around with scrolling
|
|
|
|
* until you press OFF or connect USB
|
|
|
|
*/
|
|
|
|
while (1)
|
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
status = scroll_bmp(info);
|
2008-10-21 16:05:46 +00:00
|
|
|
if (status == ZOOM_IN)
|
|
|
|
{
|
2010-11-21 13:47:56 +00:00
|
|
|
if (ds > ds_min || (imgdec->unscaled_avail && ds > 1))
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
/* if 1/1 is always available, jump ds from ds_min to 1. */
|
|
|
|
int zoom = (ds == ds_min)? ds_min: 2;
|
|
|
|
ds /= zoom; /* reduce downscaling to zoom in */
|
|
|
|
get_view(info, &cx, &cy);
|
|
|
|
cx *= zoom; /* prepare the position in the new image */
|
|
|
|
cy *= zoom;
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == ZOOM_OUT)
|
|
|
|
{
|
|
|
|
if (ds < ds_max)
|
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
/* if ds is 1 and ds_min is > 1, jump ds to ds_min. */
|
|
|
|
int zoom = (ds < ds_min)? ds_min: 2;
|
|
|
|
ds *= zoom; /* increase downscaling to zoom out */
|
|
|
|
get_view(info, &cx, &cy);
|
|
|
|
cx /= zoom; /* prepare the position in the new image */
|
|
|
|
cy /= zoom;
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USEGSLIB
|
|
|
|
grey_show(false); /* switch off overlay */
|
|
|
|
#endif
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
}
|
2010-02-25 11:11:41 +00:00
|
|
|
while (status > PLUGIN_OTHER);
|
2008-10-21 16:05:46 +00:00
|
|
|
#ifdef USEGSLIB
|
|
|
|
rb->lcd_update();
|
|
|
|
#endif
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************** Plugin entry point *********************/
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
int condition;
|
|
|
|
#ifdef USEGSLIB
|
|
|
|
long greysize; /* helper */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!parameter) return PLUGIN_ERROR;
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
rb->strcpy(np_file, parameter);
|
2011-01-22 13:41:53 +00:00
|
|
|
if (get_image_type(np_file, false) == IMAGE_UNKNOWN)
|
2010-11-21 13:47:56 +00:00
|
|
|
{
|
|
|
|
rb->splash(HZ*2, "Unsupported file");
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-02-12 14:41:52 +00:00
|
|
|
#ifdef USE_PLUG_BUF
|
2010-05-07 19:35:09 +00:00
|
|
|
buf = rb->plugin_get_buffer(&buf_size);
|
2009-11-15 16:14:45 +00:00
|
|
|
#else
|
2010-11-21 13:47:56 +00:00
|
|
|
decoder_buf = rb->plugin_get_buffer(&decoder_buf_size);
|
2010-05-07 19:35:09 +00:00
|
|
|
buf = rb->plugin_get_audio_buffer(&buf_size);
|
2009-11-15 16:14:45 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
get_pic_list();
|
|
|
|
|
|
|
|
if(!entries) return PLUGIN_ERROR;
|
|
|
|
|
|
|
|
#ifdef USEGSLIB
|
2009-01-16 10:34:40 +00:00
|
|
|
if (!grey_init(buf, buf_size, GREY_ON_COP,
|
2008-10-21 16:05:46 +00:00
|
|
|
LCD_WIDTH, LCD_HEIGHT, &greysize))
|
|
|
|
{
|
|
|
|
rb->splash(HZ, "grey buf error");
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
buf += greysize;
|
|
|
|
buf_size -= greysize;
|
|
|
|
#endif
|
|
|
|
|
2010-11-21 13:47:56 +00:00
|
|
|
#ifdef USE_PLUG_BUF
|
|
|
|
decoder_buf = buf;
|
|
|
|
decoder_buf_size = buf_size;
|
|
|
|
if(!rb->audio_status())
|
|
|
|
{
|
|
|
|
iv_api.plug_buf = false;
|
|
|
|
buf = rb->plugin_get_audio_buffer(&buf_size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-23 08:05:25 +00:00
|
|
|
/* should be ok to just load settings since the plugin itself has
|
|
|
|
just been loaded from disk and the drive should be spinning */
|
2010-01-18 12:46:19 +00:00
|
|
|
configfile_load(IMGVIEW_CONFIGFILE, config,
|
|
|
|
ARRAYLEN(config), IMGVIEW_SETTINGS_MINVERSION);
|
|
|
|
rb->memcpy(&old_settings, &settings, sizeof (settings));
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
/* Turn off backlight timeout */
|
2009-01-16 10:34:40 +00:00
|
|
|
backlight_force_on(); /* backlight control in lib/helper.c */
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-02-12 14:41:52 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
rb->lcd_set_foreground(LCD_WHITE);
|
|
|
|
rb->lcd_set_background(LCD_BLACK);
|
|
|
|
#endif
|
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
do
|
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
condition = load_and_show(np_file, &image_info);
|
2010-02-25 11:11:41 +00:00
|
|
|
} while (condition >= PLUGIN_OTHER);
|
2010-11-21 13:47:56 +00:00
|
|
|
release_decoder();
|
2008-10-21 16:05:46 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
if (rb->memcmp(&settings, &old_settings, sizeof (settings)))
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
/* Just in case drive has to spin, keep it from looking locked */
|
|
|
|
rb->splash(0, "Saving Settings");
|
2010-01-18 12:46:19 +00:00
|
|
|
configfile_save(IMGVIEW_CONFIGFILE, config,
|
|
|
|
ARRAYLEN(config), IMGVIEW_SETTINGS_VERSION);
|
2008-10-21 16:05:46 +00:00
|
|
|
}
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#ifdef DISK_SPINDOWN
|
2008-10-21 16:05:46 +00:00
|
|
|
/* set back ata spindown time in case we changed it */
|
2008-11-01 16:14:28 +00:00
|
|
|
rb->storage_spindown(rb->global_settings->disk_spindown);
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Turn on backlight timeout (revert to settings) */
|
2009-01-16 10:34:40 +00:00
|
|
|
backlight_use_settings(); /* backlight control in lib/helper.c */
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
#ifdef USEGSLIB
|
|
|
|
grey_release(); /* deinitialize */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return condition;
|
|
|
|
}
|