jpeg/png: Remove erased file name from list of file when change file.

Change trivial check of entries (entries is always > 0).
Fix bug of r23632 that error message is shown when change file while there is only one file.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23662 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2009-11-18 13:54:14 +00:00
parent 36fc4439c2
commit 3444716203
2 changed files with 72 additions and 83 deletions

View file

@ -55,8 +55,6 @@ GREY_INFO_STRUCT
#define MYXLCD(fn) xlcd_ ## fn #define MYXLCD(fn) xlcd_ ## fn
#endif #endif
#define MAX_X_SIZE LCD_WIDTH*8
/* Min memory allowing us to use the plugin buffer /* Min memory allowing us to use the plugin buffer
* and thus not stopping the music * and thus not stopping the music
* *Very* rough estimation: * *Very* rough estimation:
@ -233,40 +231,34 @@ void get_pic_list(void)
int change_filename(int direct) int change_filename(int direct)
{ {
int count = 0; bool file_erased = (file_pt[curfile] == NULL);
direction = direct; direction = direct;
if(direct == DIR_PREV) curfile += (direct == DIR_PREV? entries - 1: 1);
if (curfile >= entries)
curfile -= entries;
if (file_erased)
{ {
do /* remove 'erased' file names from list. */
int count, i;
for (count = i = 0; i < entries; i++)
{ {
count++; if (curfile == i)
if(curfile == 0) curfile = count;
curfile = entries - 1; if (file_pt[i] != NULL)
else file_pt[count++] = file_pt[i];
curfile--; }
}while(file_pt[curfile] == NULL && count < entries); entries = count;
/* we "erase" the file name if we encounter
* a non-supported file, so skip it now */
}
else /* DIR_NEXT/DIR_NONE */
{
do
{
count++;
if(curfile == entries - 1)
curfile = 0;
else
curfile++;
}while(file_pt[curfile] == NULL && count < entries);
} }
if(count == entries) if (entries == 0)
{ {
rb->splash(HZ, "No supported files"); rb->splash(HZ, "No supported files");
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
if(rb->strlen(tree->currdir) > 1)
if (rb->strlen(tree->currdir) > 1)
{ {
rb->strcpy(np_file, tree->currdir); rb->strcpy(np_file, tree->currdir);
rb->strcat(np_file, "/"); rb->strcat(np_file, "/");
@ -572,14 +564,16 @@ int scroll_bmp(struct t_disp* pdisp)
switch(button) switch(button)
{ {
case JPEG_LEFT: case JPEG_LEFT:
if (!(ds < ds_max) && entries > 0 && jpg.x_size <= MAX_X_SIZE) if (entries > 1 && pdisp->width <= LCD_WIDTH
&& pdisp->height <= LCD_HEIGHT)
return change_filename(DIR_PREV); return change_filename(DIR_PREV);
case JPEG_LEFT | BUTTON_REPEAT: case JPEG_LEFT | BUTTON_REPEAT:
pan_view_left(pdisp); pan_view_left(pdisp);
break; break;
case JPEG_RIGHT: case JPEG_RIGHT:
if (!(ds < ds_max) && entries > 0 && jpg.x_size <= MAX_X_SIZE) if (entries > 1 && pdisp->width <= LCD_WIDTH
&& pdisp->height <= LCD_HEIGHT)
return change_filename(DIR_NEXT); return change_filename(DIR_NEXT);
case JPEG_RIGHT | BUTTON_REPEAT: case JPEG_RIGHT | BUTTON_REPEAT:
pan_view_right(pdisp); pan_view_right(pdisp);
@ -599,7 +593,7 @@ int scroll_bmp(struct t_disp* pdisp)
if (!slideshow_enabled) if (!slideshow_enabled)
break; break;
running_slideshow = true; running_slideshow = true;
if (entries > 0) if (entries > 1)
return change_filename(DIR_NEXT); return change_filename(DIR_NEXT);
break; break;
@ -614,7 +608,7 @@ int scroll_bmp(struct t_disp* pdisp)
case JPEG_NEXT_REPEAT: case JPEG_NEXT_REPEAT:
#endif #endif
case JPEG_NEXT: case JPEG_NEXT:
if (entries > 0) if (entries > 1)
return change_filename(DIR_NEXT); return change_filename(DIR_NEXT);
break; break;
@ -622,7 +616,7 @@ int scroll_bmp(struct t_disp* pdisp)
case JPEG_PREVIOUS_REPEAT: case JPEG_PREVIOUS_REPEAT:
#endif #endif
case JPEG_PREVIOUS: case JPEG_PREVIOUS:
if (entries > 0) if (entries > 1)
return change_filename(DIR_PREV); return change_filename(DIR_PREV);
break; break;
@ -675,21 +669,23 @@ int scroll_bmp(struct t_disp* pdisp)
/********************* main function *************************/ /********************* main function *************************/
/* callback updating a progress meter while JPEG decoding */ /* callback updating a progress meter while JPEG decoding */
void cb_progess(int current, int total) void cb_progress(int current, int total)
{ {
rb->yield(); /* be nice to the other threads */ rb->yield(); /* be nice to the other threads */
if(!running_slideshow) if(!running_slideshow)
{ {
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, LCD_HEIGHT-8, LCD_WIDTH, 8, total, 0, rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
current, HORIZONTAL); 0, LCD_HEIGHT-8, LCD_WIDTH, 8,
total, 0, current, HORIZONTAL);
rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
} }
#ifndef USEGSLIB #ifndef USEGSLIB
else else
{ {
/* in slideshow mode, keep gui interference to a minimum */ /* in slideshow mode, keep gui interference to a minimum */
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, LCD_HEIGHT-4, LCD_WIDTH, 4, total, 0, rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
current, HORIZONTAL); 0, LCD_HEIGHT-4, LCD_WIDTH, 4,
total, 0, current, HORIZONTAL);
rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4); rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4);
} }
#endif #endif
@ -727,14 +723,13 @@ int min_downscale(struct jpeg *p_jpg, int bufsize)
return downscale; return downscale;
} }
/* how far can we zoom out, to fit image into the LCD */ /* how far can we zoom out, to fit image into the LCD */
int max_downscale(struct jpeg *p_jpg) int max_downscale(struct jpeg *p_jpg)
{ {
int downscale = 1; int downscale = 1;
while (downscale < 8 && (p_jpg->x_size > LCD_WIDTH*downscale while (downscale < 8 && (p_jpg->x_size/downscale > LCD_WIDTH
|| p_jpg->y_size > LCD_HEIGHT*downscale)) || p_jpg->y_size/downscale > LCD_HEIGHT))
{ {
downscale *= 2; downscale *= 2;
} }
@ -816,15 +811,14 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds)
time = *rb->current_tick; time = *rb->current_tick;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ #ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(true); rb->cpu_boost(true);
status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progess); status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progress);
rb->cpu_boost(false); rb->cpu_boost(false);
#else #else
status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progess); status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progress);
#endif #endif
if (status) if (status)
{ {
rb->splashf(HZ, "decode error %d", status); rb->splashf(HZ, "decode error %d", status);
file_pt[curfile] = NULL;
return NULL; return NULL;
} }
time = *rb->current_tick - time; time = *rb->current_tick - time;
@ -1038,7 +1032,10 @@ int load_and_show(char* filename)
{ {
p_disp = get_image(&jpg, ds); /* decode or fetch from cache */ p_disp = get_image(&jpg, ds); /* decode or fetch from cache */
if (p_disp == NULL) if (p_disp == NULL)
{
file_pt[curfile] = NULL;
return change_filename(direction); return change_filename(direction);
}
set_view(p_disp, cx, cy); set_view(p_disp, cx, cy);

View file

@ -225,8 +225,6 @@ static struct configdata png_config[] =
static fb_data* old_backdrop; static fb_data* old_backdrop;
#endif #endif
#define MAX_X_SIZE LCD_WIDTH*8
/* Min memory allowing us to use the plugin buffer /* Min memory allowing us to use the plugin buffer
* and thus not stopping the music * and thus not stopping the music
* *Very* rough estimation: * *Very* rough estimation:
@ -1369,35 +1367,28 @@ void get_pic_list(void)
int change_filename(int direct) int change_filename(int direct)
{ {
int count = 0; bool file_erased = (file_pt[curfile] == NULL);
direction = direct; direction = direct;
if (direct == DIR_PREV) curfile += (direct == DIR_PREV? entries - 1: 1);
if (curfile >= entries)
curfile -= entries;
if (file_erased)
{ {
do /* remove 'erased' file names from list. */
int count, i;
for (count = i = 0; i < entries; i++)
{ {
count++; if (curfile == i)
if (curfile == 0) curfile = count;
curfile = entries - 1; if (file_pt[i] != NULL)
else file_pt[count++] = file_pt[i];
curfile--; }
}while (file_pt[curfile] == NULL && count < entries); entries = count;
/* we "erase" the file name if we encounter
* a non-supported file, so skip it now */
}
else /* DIR_NEXT/DIR_NONE */
{
do
{
count++;
if (curfile == entries - 1)
curfile = 0;
else
curfile++;
}while (file_pt[curfile] == NULL && count < entries);
} }
if (count == entries) if (entries == 0)
{ {
rb->splash(HZ, "No supported files"); rb->splash(HZ, "No supported files");
return PLUGIN_ERROR; return PLUGIN_ERROR;
@ -1613,14 +1604,16 @@ int scroll_bmp(struct LodePNG_Decoder* decoder)
switch (button) switch (button)
{ {
case PNG_LEFT: case PNG_LEFT:
if (!(ds < ds_max) && entries > 0 && decoder->infoPng.width <= MAX_X_SIZE) if (entries > 1 && decoder->infoPng.width/ds <= LCD_WIDTH
&& decoder->infoPng.height/ds <= LCD_HEIGHT)
return change_filename(DIR_PREV); return change_filename(DIR_PREV);
case PNG_LEFT | BUTTON_REPEAT: case PNG_LEFT | BUTTON_REPEAT:
pan_view_left(decoder); pan_view_left(decoder);
break; break;
case PNG_RIGHT: case PNG_RIGHT:
if (!(ds < ds_max) && entries > 0 && decoder->infoPng.width <= MAX_X_SIZE) if (entries > 1 && decoder->infoPng.width/ds <= LCD_WIDTH
&& decoder->infoPng.height/ds <= LCD_HEIGHT)
return change_filename(DIR_NEXT); return change_filename(DIR_NEXT);
case PNG_RIGHT | BUTTON_REPEAT: case PNG_RIGHT | BUTTON_REPEAT:
pan_view_right(decoder); pan_view_right(decoder);
@ -1640,7 +1633,7 @@ int scroll_bmp(struct LodePNG_Decoder* decoder)
if (!slideshow_enabled) if (!slideshow_enabled)
break; break;
running_slideshow = true; running_slideshow = true;
if (entries > 0) if (entries > 1)
return change_filename(DIR_NEXT); return change_filename(DIR_NEXT);
break; break;
@ -1655,7 +1648,7 @@ int scroll_bmp(struct LodePNG_Decoder* decoder)
case PNG_NEXT_REPEAT: case PNG_NEXT_REPEAT:
#endif #endif
case PNG_NEXT: case PNG_NEXT:
if (entries > 0) if (entries > 1)
return change_filename(DIR_NEXT); return change_filename(DIR_NEXT);
break; break;
@ -1663,7 +1656,7 @@ int scroll_bmp(struct LodePNG_Decoder* decoder)
case PNG_PREVIOUS_REPEAT: case PNG_PREVIOUS_REPEAT:
#endif #endif
case PNG_PREVIOUS: case PNG_PREVIOUS:
if (entries > 0) if (entries > 1)
return change_filename(DIR_PREV); return change_filename(DIR_PREV);
break; break;
@ -1735,15 +1728,17 @@ void cb_progress(int current, int total)
if (current & 1) rb->yield(); /* be nice to the other threads */ if (current & 1) rb->yield(); /* be nice to the other threads */
if (!running_slideshow) if (!running_slideshow)
{ {
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, LCD_HEIGHT-8, LCD_WIDTH, 8, total, 0, rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
current, HORIZONTAL); 0, LCD_HEIGHT-8, LCD_WIDTH, 8,
total, 0, current, HORIZONTAL);
rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
} }
else else
{ {
/* in slideshow mode, keep gui interference to a minimum */ /* in slideshow mode, keep gui interference to a minimum */
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, LCD_HEIGHT-4, LCD_WIDTH, 4, total, 0, rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
current, HORIZONTAL); 0, LCD_HEIGHT-4, LCD_WIDTH, 4,
total, 0, current, HORIZONTAL);
rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4); rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4);
} }
} }
@ -1772,8 +1767,8 @@ unsigned max_downscale(struct LodePNG_Decoder* decoder)
{ {
unsigned downscale = 1; unsigned downscale = 1;
while (downscale < 8 && (decoder->infoPng.width > LCD_WIDTH*downscale while (downscale < 8 && (decoder->infoPng.width/downscale > LCD_WIDTH
|| decoder->infoPng.height > LCD_HEIGHT*downscale)) || decoder->infoPng.height/downscale > LCD_HEIGHT))
{ {
downscale *= 2; downscale *= 2;
} }
@ -2007,8 +2002,7 @@ int load_and_show(char* filename)
{ {
case PNG_ZOOM_IN: case PNG_ZOOM_IN:
plug_buf = false; plug_buf = false;
memory = rb->plugin_get_audio_buffer( memory = rb->plugin_get_audio_buffer((size_t *)&memory_size);
(size_t *)&memory_size);
memory_max = memory + memory_size - 1; memory_max = memory + memory_size - 1;
/*try again this file, now using the audio buffer */ /*try again this file, now using the audio buffer */
return PLUGIN_OTHER; return PLUGIN_OTHER;
@ -2117,8 +2111,6 @@ int load_and_show(char* filename)
if (decoder.error == PLUGIN_ABORT) { if (decoder.error == PLUGIN_ABORT) {
return PLUGIN_OK; return PLUGIN_OK;
} else if (decoder.error == OUT_OF_MEMORY && entries == 1) {
return PLUGIN_ERROR;
} else { } else {
file_pt[curfile] = NULL; file_pt[curfile] = NULL;
return change_filename(direction); return change_filename(direction);
@ -2220,7 +2212,7 @@ enum plugin_status plugin_start(const void* parameter)
if (rb->audio_status()) { if (rb->audio_status()) {
plug_buf = true; plug_buf = true;
} else { } else {
memory = (unsigned char *)rb->plugin_get_audio_buffer((size_t *)&memory_size); memory = rb->plugin_get_audio_buffer((size_t *)&memory_size);
} }
#endif #endif