2008-10-21 16:05:46 +00:00
|
|
|
/***************************************************************************
|
2010-01-18 12:46:19 +00:00
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* user intereface of image viewers (jpeg, png, etc.)
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
#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"
|
2008-10-21 16:05:46 +00:00
|
|
|
|
|
|
|
PLUGIN_HEADER
|
|
|
|
|
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 ***********************************/
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
bool slideshow_enabled = false; /* run slideshow */
|
|
|
|
bool running_slideshow = false; /* loading image because of slideshw */
|
|
|
|
#ifdef DISK_SPINDOWN
|
|
|
|
bool immediate_ata_off = false; /* power down disk after loading */
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2010-01-18 12:46:19 +00:00
|
|
|
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
|
|
|
|
/* are we using the plugin buffer or the audio buffer? */
|
|
|
|
bool plug_buf = true;
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 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-01-18 12:46:19 +00:00
|
|
|
/* jpeg use this */
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
#if LCD_DEPTH > 1
|
2008-10-22 08:50:13 +00:00
|
|
|
static fb_data* old_backdrop;
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**************** begin Application ********************/
|
|
|
|
|
|
|
|
|
|
|
|
/************************* Globals ***************************/
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER)
|
|
|
|
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
|
|
|
|
|
|
|
/* my memory pool (from the mp3 buffer) */
|
2008-10-22 08:50:13 +00:00
|
|
|
static char print[32]; /* use a common snprintf() buffer */
|
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;
|
|
|
|
static ssize_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
|
|
|
|
|
|
|
static struct tree_context *tree;
|
|
|
|
|
|
|
|
/* the current full file name */
|
|
|
|
static char np_file[MAX_PATH];
|
2008-10-22 08:50:13 +00:00
|
|
|
static int curfile = 0, direction = DIR_NONE, 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
|
|
|
|
|
|
|
/************************* Implementation ***************************/
|
|
|
|
|
|
|
|
/*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
|
|
|
{
|
|
|
|
int i;
|
2009-11-15 16:14:45 +00:00
|
|
|
struct entry *dircache;
|
2008-10-21 16:05:46 +00:00
|
|
|
char *pname;
|
|
|
|
tree = rb->tree_get_context();
|
2009-11-15 16:14:45 +00:00
|
|
|
dircache = tree->dircache;
|
2008-10-21 16:05:46 +00:00
|
|
|
|
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++;
|
|
|
|
|
2009-11-15 16:14:45 +00:00
|
|
|
for (i = 0; i < tree->filesindir; i++)
|
|
|
|
{
|
|
|
|
if (!(dircache[i].attr & ATTR_DIRECTORY)
|
2010-01-18 12:46:19 +00:00
|
|
|
&& img_ext(rb->strrchr(dircache[i].name,'.')))
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buf += (entries * sizeof(char**));
|
|
|
|
buf_size -= (entries * sizeof(char**));
|
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
|
|
|
|
|
|
|
if (rb->strlen(tree->currdir) > 1)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
rb->strcpy(np_file, tree->currdir);
|
|
|
|
rb->strcat(np_file, "/");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rb->strcpy(np_file, tree->currdir);
|
|
|
|
|
|
|
|
rb->strcat(np_file, file_pt[curfile]);
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VSCROLL (LCD_HEIGHT/8)
|
|
|
|
#define HSCROLL (LCD_WIDTH/10)
|
|
|
|
|
|
|
|
#define ZOOM_IN 100 /* return codes for below function */
|
|
|
|
#define ZOOM_OUT 101
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER)
|
|
|
|
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;
|
2008-10-21 16:05:46 +00:00
|
|
|
rb->set_bool("Grayscale", &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-01-18 12:46:19 +00:00
|
|
|
rb->set_option("Dithering", &settings.jpeg_dither_mode, INT,
|
2008-10-21 16:05:46 +00:00
|
|
|
dithering, DITHER_NUM_MODES, NULL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-16 04:25:21 +00:00
|
|
|
MENUITEM_FUNCTION(grayscale_item, 0, "Greyscale",
|
|
|
|
set_option_grayscale, NULL, NULL, Icon_NOICON);
|
|
|
|
MENUITEM_FUNCTION(dithering_item, 0, "Dithering",
|
|
|
|
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-01-18 12:46:19 +00:00
|
|
|
#endif /* defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER) */
|
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
|
|
|
{
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(old_backdrop);
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
rb->lcd_set_foreground(rb->global_settings->fg_color);
|
|
|
|
rb->lcd_set_background(rb->global_settings->bg_color);
|
|
|
|
#else
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
rb->lcd_set_background(LCD_WHITE);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
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,
|
|
|
|
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
|
|
|
|
MIID_SHOW_PLAYBACK_MENU,
|
|
|
|
#endif
|
2010-01-18 12:46:19 +00:00
|
|
|
#if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER)
|
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-01-18 12:46:19 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, MENU_TITLE, NULL,
|
2009-06-16 04:25:21 +00:00
|
|
|
"Return", "Toggle Slideshow Mode",
|
|
|
|
"Change Slideshow Time",
|
2008-10-21 16:05:46 +00:00
|
|
|
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
|
2009-06-16 04:25:21 +00:00
|
|
|
"Show Playback Menu",
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
2010-01-18 12:46:19 +00:00
|
|
|
#if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER)
|
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:
|
|
|
|
rb->set_option("Toggle Slideshow", &slideshow_enabled, INT,
|
|
|
|
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;
|
|
|
|
|
|
|
|
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
|
|
|
|
case MIID_SHOW_PLAYBACK_MENU:
|
|
|
|
if (plug_buf)
|
|
|
|
{
|
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-01-18 12:46:19 +00:00
|
|
|
#if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER)
|
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 */
|
|
|
|
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
|
|
|
|
|
|
|
if (slideshow_enabled)
|
|
|
|
{
|
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 */
|
|
|
|
immediate_ata_off = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
MYXLCD(scroll_left)(move); /* scroll left */
|
2010-01-18 12:46:19 +00:00
|
|
|
info->x += move;
|
|
|
|
draw_image_rect(info, LCD_WIDTH - move, 0, move, info->height-info->y);
|
2008-10-23 08:05:25 +00:00
|
|
|
MYLCD_UPDATE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
MYXLCD(scroll_right)(move); /* scroll right */
|
2010-01-18 12:46:19 +00:00
|
|
|
info->x -= move;
|
|
|
|
draw_image_rect(info, 0, 0, move, info->height-info->y);
|
2008-10-23 08:05:25 +00:00
|
|
|
MYLCD_UPDATE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
MYXLCD(scroll_down)(move); /* scroll down */
|
2010-01-18 12:46:19 +00:00
|
|
|
info->y -= move;
|
|
|
|
#if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER)
|
|
|
|
if (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-01-18 12:46:19 +00:00
|
|
|
draw_image_rect(info, 0, 0, info->width-info->x, move);
|
2008-10-23 08:05:25 +00:00
|
|
|
MYLCD_UPDATE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
MYXLCD(scroll_up)(move); /* scroll up */
|
2010-01-18 12:46:19 +00:00
|
|
|
info->y += move;
|
|
|
|
#if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER)
|
|
|
|
if (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-01-18 12:46:19 +00:00
|
|
|
draw_image_rect(info, 0, LCD_HEIGHT - move, info->width-info->x, move);
|
2008-10-23 08:05:25 +00:00
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#if defined(HAVE_LCD_COLOR) && defined(JPEG_VIEWER)
|
|
|
|
if (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
|
|
|
|
MYLCD_UPDATE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2008-10-21 16:05:46 +00:00
|
|
|
int lastbutton = 0;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (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
|
|
|
|
|
|
|
running_slideshow = false;
|
|
|
|
|
|
|
|
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:
|
|
|
|
if (!slideshow_enabled)
|
|
|
|
break;
|
|
|
|
running_slideshow = true;
|
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_SLIDE_SHOW
|
|
|
|
case IMGVIEW_SLIDE_SHOW:
|
2008-10-21 16:05:46 +00:00
|
|
|
slideshow_enabled = !slideshow_enabled;
|
|
|
|
running_slideshow = slideshow_enabled;
|
|
|
|
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-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:
|
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-01-18 12:46:19 +00:00
|
|
|
draw_image_rect(info, 0, 0,
|
|
|
|
info->width-info->x, info->height-info->y);
|
2008-10-21 16:05:46 +00:00
|
|
|
MYLCD_UPDATE();
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
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 *************************/
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
/* callback updating a progress meter while image decoding */
|
2009-11-18 13:54:14 +00:00
|
|
|
void cb_progress(int current, int total)
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
|
|
|
rb->yield(); /* be nice to the other threads */
|
|
|
|
if(!running_slideshow)
|
|
|
|
{
|
2009-11-18 13:54:14 +00:00
|
|
|
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
|
|
|
|
0, LCD_HEIGHT-8, LCD_WIDTH, 8,
|
|
|
|
total, 0, current, HORIZONTAL);
|
2008-10-21 16:05:46 +00:00
|
|
|
rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
|
|
|
|
}
|
|
|
|
#ifndef USEGSLIB
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* in slideshow mode, keep gui interference to a minimum */
|
2009-11-18 13:54:14 +00:00
|
|
|
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
|
|
|
|
0, LCD_HEIGHT-4, LCD_WIDTH, 4,
|
|
|
|
total, 0, current, HORIZONTAL);
|
2008-10-21 16:05:46 +00:00
|
|
|
rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-01-18 12:46:19 +00:00
|
|
|
if (img_mem(8) > bufsize)
|
2008-10-21 16:05:46 +00:00
|
|
|
return 0; /* error, too large, even 1:8 doesn't fit */
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
while (downscale > 1 && 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
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_foreground(LCD_WHITE);
|
|
|
|
rb->lcd_set_background(LCD_BLACK);
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
#endif
|
|
|
|
rb->lcd_clear_display();
|
2008-10-21 16:05:46 +00:00
|
|
|
|
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-01-18 12:46:19 +00:00
|
|
|
status = 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
|
|
|
{
|
|
|
|
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
|
|
|
|
if(plug_buf)
|
|
|
|
{
|
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1);
|
|
|
|
rb->lcd_puts(0,0,print);
|
|
|
|
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.");
|
2009-12-21 15:20:33 +00:00
|
|
|
rb->lcd_puts(0,4,"Show Menu: Quit.");
|
2008-10-21 16:05:46 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
rb->lcd_setfont(FONT_UI);
|
|
|
|
|
|
|
|
rb->button_clear_queue();
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int button = rb->button_get(true);
|
|
|
|
switch(button)
|
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_ZOOM_IN:
|
2008-10-21 16:05:46 +00:00
|
|
|
plug_buf = false;
|
2009-11-17 15:15:29 +00:00
|
|
|
buf = rb->plugin_get_audio_buffer((size_t *)&buf_size);
|
2008-10-21 16:05:46 +00:00
|
|
|
/*try again this file, now using the audio buffer */
|
|
|
|
return PLUGIN_OTHER;
|
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:
|
2008-10-21 16:05:46 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_LEFT:
|
2008-10-21 16:05:46 +00:00
|
|
|
if(entries>1)
|
|
|
|
{
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
return change_filename(DIR_PREV);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
case IMGVIEW_RIGHT:
|
2008-10-21 16:05:46 +00:00
|
|
|
if(entries>1)
|
|
|
|
{
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
return change_filename(DIR_NEXT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2009-12-18 13:06:21 +00:00
|
|
|
if(rb->default_event_handler_ex(button, cleanup, NULL)
|
2008-10-21 16:05:46 +00:00
|
|
|
== SYS_USB_CONNECTED)
|
2009-12-18 13:06:21 +00:00
|
|
|
return PLUGIN_USB_CONNECTED;
|
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) {
|
|
|
|
rb->splash(HZ, "aborted");
|
|
|
|
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-01-18 12:46:19 +00:00
|
|
|
#if UNSCALED_IS_AVAILABLE
|
|
|
|
/* Can not resize the image but original one is available, so use it. */
|
|
|
|
ds_min = ds_max = 1;
|
|
|
|
#else
|
|
|
|
/* not enough memory to decode image. */
|
2008-10-21 16:05:46 +00:00
|
|
|
rb->splash(HZ, "too large");
|
2009-11-15 16:14:45 +00:00
|
|
|
file_pt[curfile] = NULL;
|
2008-10-21 16:05:46 +00:00
|
|
|
return change_filename(direction);
|
2010-01-18 12:46:19 +00:00
|
|
|
#endif
|
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-01-18 12:46:19 +00:00
|
|
|
status = get_image(info, ds); /* decode or fetch from cache */
|
|
|
|
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
|
|
|
|
|
|
|
if(!running_slideshow)
|
|
|
|
{
|
|
|
|
rb->snprintf(print, sizeof(print), "showing %dx%d",
|
2010-01-18 12:46:19 +00:00
|
|
|
info->width, info->height);
|
2008-10-21 16:05:46 +00:00
|
|
|
rb->lcd_puts(0, 3, print);
|
|
|
|
rb->lcd_update();
|
|
|
|
}
|
2009-11-15 14:03:57 +00:00
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
MYLCD(clear_display)();
|
2010-01-18 12:46:19 +00:00
|
|
|
draw_image_rect(info, 0, 0,
|
|
|
|
info->width-info->x, info->height-info->y);
|
2008-10-21 16:05:46 +00:00
|
|
|
MYLCD_UPDATE();
|
|
|
|
|
|
|
|
#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-01-18 12:46:19 +00:00
|
|
|
#if UNSCALED_IS_AVAILABLE
|
|
|
|
if (ds > 1)
|
|
|
|
#else
|
2008-10-21 16:05:46 +00:00
|
|
|
if (ds > ds_min)
|
2010-01-18 12:46:19 +00:00
|
|
|
#endif
|
2008-10-21 16:05:46 +00:00
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
#if UNSCALED_IS_AVAILABLE
|
|
|
|
/* if 1/1 is always available, jump ds from ds_min to 1. */
|
|
|
|
int zoom = (ds == ds_min)? ds_min: 2;
|
|
|
|
#else
|
|
|
|
const int zoom = 2;
|
|
|
|
#endif
|
|
|
|
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 UNSCALED_IS_AVAILABLE
|
|
|
|
/* if ds is 1 and ds_min is > 1, jump ds to ds_min. */
|
|
|
|
int zoom = (ds < ds_min)? ds_min: 2;
|
|
|
|
#else
|
|
|
|
const int zoom = 2;
|
|
|
|
#endif
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
while (status != PLUGIN_OK && status != PLUGIN_USB_CONNECTED
|
2009-12-18 13:06:21 +00:00
|
|
|
&& 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 LCD_DEPTH > 1
|
|
|
|
old_backdrop = rb->lcd_get_backdrop();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!parameter) return PLUGIN_ERROR;
|
|
|
|
|
2009-11-15 16:14:45 +00:00
|
|
|
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
|
|
|
|
buf = rb->plugin_get_buffer((size_t *)&buf_size);
|
|
|
|
#else
|
|
|
|
buf = rb->plugin_get_audio_buffer((size_t *)&buf_size);
|
|
|
|
#endif
|
|
|
|
|
2008-10-21 16:05:46 +00:00
|
|
|
rb->strcpy(np_file, parameter);
|
|
|
|
get_pic_list();
|
|
|
|
|
|
|
|
if(!entries) return PLUGIN_ERROR;
|
|
|
|
|
2010-01-18 12:46:19 +00:00
|
|
|
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
|
2009-12-21 15:20:33 +00:00
|
|
|
if(!rb->audio_status())
|
|
|
|
{
|
|
|
|
plug_buf = false;
|
2008-10-21 16:05:46 +00:00
|
|
|
buf = rb->plugin_get_audio_buffer((size_t *)&buf_size);
|
2009-12-21 15:20:33 +00:00
|
|
|
}
|
2008-10-21 16:05:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
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
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2010-01-18 12:46:19 +00:00
|
|
|
condition = load_and_show(np_file, &image_info);
|
2009-12-18 13:06:21 +00:00
|
|
|
} while (condition != PLUGIN_OK && condition != PLUGIN_USB_CONNECTED
|
|
|
|
&& condition != PLUGIN_ERROR);
|
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;
|
|
|
|
}
|