1
0
Fork 0
forked from len0rd/rockbox

jpeg/png: change file list handling a bit.

* don't sort by plugin, use order of browser.
* skip directories.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23632 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2009-11-15 16:14:45 +00:00
parent 5e31d059aa
commit 09c26581a5
2 changed files with 62 additions and 82 deletions

View file

@ -185,12 +185,6 @@ bool plug_buf = false;
/************************* Implementation ***************************/ /************************* Implementation ***************************/
/* support function for qsort() */
static int compare(const void* p1, const void* p2)
{
return rb->strcasecmp(*((char **)p1), *((char **)p2));
}
bool jpg_ext(const char ext[]) bool jpg_ext(const char ext[])
{ {
if(!ext) if(!ext)
@ -207,34 +201,32 @@ bool jpg_ext(const char ext[])
void get_pic_list(void) void get_pic_list(void)
{ {
int i; int i;
long int str_len = 0; struct entry *dircache;
char *pname; char *pname;
tree = rb->tree_get_context(); tree = rb->tree_get_context();
dircache = tree->dircache;
#if PLUGIN_BUFFER_SIZE >= MIN_MEM file_pt = (char **) buf;
file_pt = rb->plugin_get_buffer((size_t *)&buf_size);
#else
file_pt = rb->plugin_get_audio_buffer((size_t *)&buf_size);
#endif
for(i = 0; i < tree->filesindir; i++)
{
if(jpg_ext(rb->strrchr(&tree->name_buffer[str_len],'.')))
file_pt[entries++] = &tree->name_buffer[str_len];
str_len += rb->strlen(&tree->name_buffer[str_len]) + 1;
}
rb->qsort(file_pt, entries, sizeof(char**), compare);
/* Remove path and leave only the name.*/ /* Remove path and leave only the name.*/
pname = rb->strrchr(np_file,'/'); pname = rb->strrchr(np_file,'/');
pname++; pname++;
/* Find Selected File. */ for (i = 0; i < tree->filesindir; i++)
for(i = 0; i < entries; i++) {
if(!rb->strcmp(file_pt[i], pname)) if (!(dircache[i].attr & ATTR_DIRECTORY)
curfile = i; && jpg_ext(rb->strrchr(dircache[i].name,'.')))
{
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**));
} }
int change_filename(int direct) int change_filename(int direct)
@ -251,7 +243,7 @@ int change_filename(int direct)
curfile = entries - 1; curfile = entries - 1;
else else
curfile--; curfile--;
}while(file_pt[curfile] == '\0' && count < entries); }while(file_pt[curfile] == NULL && count < entries);
/* we "erase" the file name if we encounter /* we "erase" the file name if we encounter
* a non-supported file, so skip it now */ * a non-supported file, so skip it now */
} }
@ -264,10 +256,10 @@ int change_filename(int direct)
curfile = 0; curfile = 0;
else else
curfile++; curfile++;
}while(file_pt[curfile] == '\0' && count < entries); }while(file_pt[curfile] == NULL && count < entries);
} }
if(count == entries && file_pt[curfile] == '\0') if(count == entries)
{ {
rb->splash(HZ, "No supported files"); rb->splash(HZ, "No supported files");
return PLUGIN_ERROR; return PLUGIN_ERROR;
@ -830,7 +822,7 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds)
if (status) if (status)
{ {
rb->splashf(HZ, "decode error %d", status); rb->splashf(HZ, "decode error %d", status);
file_pt[curfile] = '\0'; file_pt[curfile] = NULL;
return NULL; return NULL;
} }
time = *rb->current_tick - time; time = *rb->current_tick - time;
@ -907,10 +899,10 @@ int load_and_show(char* filename)
if (buf_size <= 0) if (buf_size <= 0)
{ {
rb->close(fd);
#if PLUGIN_BUFFER_SIZE >= MIN_MEM #if PLUGIN_BUFFER_SIZE >= MIN_MEM
if(plug_buf) if(plug_buf)
{ {
rb->close(fd);
rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_setfont(FONT_SYSFIXED);
rb->lcd_clear_display(); rb->lcd_clear_display();
rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1); rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1);
@ -969,7 +961,6 @@ int load_and_show(char* filename)
#endif #endif
{ {
rb->splash(HZ, "Out of Memory"); rb->splash(HZ, "Out of Memory");
rb->close(fd);
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
} }
@ -1016,7 +1007,7 @@ int load_and_show(char* filename)
if (status < 0 || (status & (DQT | SOF0)) != (DQT | SOF0)) if (status < 0 || (status & (DQT | SOF0)) != (DQT | SOF0))
{ /* bad format or minimum components not contained */ { /* bad format or minimum components not contained */
rb->splashf(HZ, "unsupported %d", status); rb->splashf(HZ, "unsupported %d", status);
file_pt[curfile] = '\0'; file_pt[curfile] = NULL;
return change_filename(direction); return change_filename(direction);
} }
@ -1035,7 +1026,7 @@ int load_and_show(char* filename)
if (ds_min == 0) if (ds_min == 0)
{ {
rb->splash(HZ, "too large"); rb->splash(HZ, "too large");
file_pt[curfile] = '\0'; file_pt[curfile] = NULL;
return change_filename(direction); return change_filename(direction);
} }
@ -1129,6 +1120,12 @@ enum plugin_status plugin_start(const void* parameter)
if(!parameter) return PLUGIN_ERROR; if(!parameter) return PLUGIN_ERROR;
#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
rb->strcpy(np_file, parameter); rb->strcpy(np_file, parameter);
get_pic_list(); get_pic_list();
@ -1136,18 +1133,9 @@ enum plugin_status plugin_start(const void* parameter)
#if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR) #if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR)
if(rb->audio_status()) if(rb->audio_status())
{
buf = rb->plugin_get_buffer((size_t *)&buf_size) +
(entries * sizeof(char**));
buf_size -= (entries * sizeof(char**));
plug_buf = true; plug_buf = true;
}
else else
buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); buf = rb->plugin_get_audio_buffer((size_t *)&buf_size);
#else
buf = rb->plugin_get_audio_buffer(&buf_size) +
(entries * sizeof(char**));
buf_size -= (entries * sizeof(char**));
#endif #endif
#ifdef USEGSLIB #ifdef USEGSLIB

View file

@ -1326,12 +1326,6 @@ void LodePNG_Decoder_cleanup(LodePNG_Decoder* decoder)
LodePNG_InfoPng_cleanup(&decoder->infoPng); LodePNG_InfoPng_cleanup(&decoder->infoPng);
} }
/* support function for qsort() */
static int compare(const void* p1, const void* p2)
{
return rb->strcasecmp(*((char **)p1), *((char **)p2));
}
bool png_ext(const char ext[]) bool png_ext(const char ext[])
{ {
if (!ext) if (!ext)
@ -1346,34 +1340,32 @@ bool png_ext(const char ext[])
void get_pic_list(void) void get_pic_list(void)
{ {
int i; int i;
long int str_len = 0; struct entry *dircache;
char *pname; char *pname;
tree = rb->tree_get_context(); tree = rb->tree_get_context();
dircache = tree->dircache;
#if PLUGIN_BUFFER_SIZE >= MIN_MEM file_pt = (char **) memory;
file_pt = rb->plugin_get_buffer((size_t *)&image_size);
#else
file_pt = rb->plugin_get_audio_buffer((size_t *)&image_size);
#endif
for (i = 0; i < tree->filesindir; i++)
{
if (png_ext(rb->strrchr(&tree->name_buffer[str_len],'.')))
file_pt[entries++] = &tree->name_buffer[str_len];
str_len += rb->strlen(&tree->name_buffer[str_len]) + 1;
}
rb->qsort(file_pt, entries, sizeof(char**), compare);
/* Remove path and leave only the name.*/ /* Remove path and leave only the name.*/
pname = rb->strrchr(np_file,'/'); pname = rb->strrchr(np_file,'/');
pname++; pname++;
/* Find Selected File. */ for (i = 0; i < tree->filesindir; i++)
for (i = 0; i < entries; i++) {
if (!rb->strcmp(file_pt[i], pname)) if (!(dircache[i].attr & ATTR_DIRECTORY)
curfile = i; && png_ext(rb->strrchr(dircache[i].name, '.')))
{
file_pt[entries] = dircache[i].name;
/* Set Selected File. */
if (!rb->strcmp(file_pt[entries], pname))
curfile = entries;
entries++;
}
}
memory += (entries * sizeof(char**));
memory_size -= (entries * sizeof(char**));
} }
int change_filename(int direct) int change_filename(int direct)
@ -1390,7 +1382,7 @@ int change_filename(int direct)
curfile = entries - 1; curfile = entries - 1;
else else
curfile--; curfile--;
}while (file_pt[curfile] == '\0' && count < entries); }while (file_pt[curfile] == NULL && count < entries);
/* we "erase" the file name if we encounter /* we "erase" the file name if we encounter
* a non-supported file, so skip it now */ * a non-supported file, so skip it now */
} }
@ -1403,14 +1395,15 @@ int change_filename(int direct)
curfile = 0; curfile = 0;
else else
curfile++; curfile++;
}while (file_pt[curfile] == '\0' && count < entries); }while (file_pt[curfile] == NULL && count < entries);
} }
if (count == entries && file_pt[curfile] == '\0') if (count == entries)
{ {
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);
@ -1549,7 +1542,7 @@ static void pan_view_right(struct LodePNG_Decoder* decoder)
{ {
int move; int move;
move = MIN(HSCROLL, decoder->infoPng.width/ds - decoder->x - LCD_WIDTH); move = MIN(HSCROLL, (int)(decoder->infoPng.width/ds) - decoder->x - LCD_WIDTH);
if (move > 0) if (move > 0)
{ {
decoder->x += move; decoder->x += move;
@ -1595,7 +1588,7 @@ static void pan_view_down(struct LodePNG_Decoder* decoder)
{ {
int move; int move;
move = MIN(VSCROLL, decoder->infoPng.height/ds - decoder->y - LCD_HEIGHT); move = MIN(VSCROLL, (int)(decoder->infoPng.height/ds) - decoder->y - LCD_HEIGHT);
if (move > 0) if (move > 0)
{ {
decoder->y += move; decoder->y += move;
@ -2028,8 +2021,6 @@ int load_and_show(char* filename)
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 += (entries * sizeof(char**));
memory_size -= (entries * sizeof(char**));
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;
@ -2141,7 +2132,7 @@ int load_and_show(char* filename)
} else if (decoder.error == OUT_OF_MEMORY && entries == 1) { } else if (decoder.error == OUT_OF_MEMORY && entries == 1) {
return PLUGIN_ERROR; return PLUGIN_ERROR;
} else { } else {
file_pt[curfile] = '\0'; file_pt[curfile] = NULL;
return change_filename(direction); return change_filename(direction);
} }
} }
@ -2226,6 +2217,12 @@ enum plugin_status plugin_start(const void* parameter)
if (!parameter) return PLUGIN_ERROR; if (!parameter) return PLUGIN_ERROR;
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
memory = rb->plugin_get_buffer((size_t *)&memory_size);
#else
memory = rb->plugin_get_audio_buffer((size_t *)&memory_size);
#endif
rb->strcpy(np_file, parameter); rb->strcpy(np_file, parameter);
get_pic_list(); get_pic_list();
@ -2233,17 +2230,12 @@ enum plugin_status plugin_start(const void* parameter)
#if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR) #if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR)
if (rb->audio_status()) { if (rb->audio_status()) {
memory = (unsigned char *)rb->plugin_get_buffer((size_t *)&memory_size);
plug_buf = true; plug_buf = true;
} else { } else {
memory = (unsigned char *)rb->plugin_get_audio_buffer((size_t *)&memory_size); memory = (unsigned char *)rb->plugin_get_audio_buffer((size_t *)&memory_size);
} }
#else
memory = (unsigned char *)rb->plugin_get_audio_buffer((size_t *)&memory_size);
#endif #endif
memory += (entries * sizeof(char**));
memory_size -= (entries * sizeof(char**));
memory_max = memory + memory_size - 1; memory_max = memory + memory_size - 1;
/* should be ok to just load settings since the plugin itself has /* should be ok to just load settings since the plugin itself has