diff --git a/apps/plugins/jpeg/jpeg.c b/apps/plugins/jpeg/jpeg.c index 807c6c4101..44907e6bd2 100644 --- a/apps/plugins/jpeg/jpeg.c +++ b/apps/plugins/jpeg/jpeg.c @@ -185,12 +185,6 @@ bool plug_buf = false; /************************* 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[]) { if(!ext) @@ -207,34 +201,32 @@ bool jpg_ext(const char ext[]) void get_pic_list(void) { int i; - long int str_len = 0; + struct entry *dircache; char *pname; tree = rb->tree_get_context(); + dircache = tree->dircache; -#if PLUGIN_BUFFER_SIZE >= MIN_MEM - 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); + file_pt = (char **) buf; /* Remove path and leave only the name.*/ pname = rb->strrchr(np_file,'/'); pname++; - /* Find Selected File. */ - for(i = 0; i < entries; i++) - if(!rb->strcmp(file_pt[i], pname)) - curfile = i; + for (i = 0; i < tree->filesindir; i++) + { + if (!(dircache[i].attr & ATTR_DIRECTORY) + && 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) @@ -251,7 +243,7 @@ int change_filename(int direct) curfile = entries - 1; else curfile--; - }while(file_pt[curfile] == '\0' && count < entries); + }while(file_pt[curfile] == NULL && count < entries); /* we "erase" the file name if we encounter * a non-supported file, so skip it now */ } @@ -264,10 +256,10 @@ int change_filename(int direct) curfile = 0; else 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"); return PLUGIN_ERROR; @@ -830,7 +822,7 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds) if (status) { rb->splashf(HZ, "decode error %d", status); - file_pt[curfile] = '\0'; + file_pt[curfile] = NULL; return NULL; } time = *rb->current_tick - time; @@ -907,10 +899,10 @@ int load_and_show(char* filename) if (buf_size <= 0) { + rb->close(fd); #if PLUGIN_BUFFER_SIZE >= MIN_MEM if(plug_buf) { - rb->close(fd); rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_clear_display(); rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1); @@ -969,7 +961,6 @@ int load_and_show(char* filename) #endif { rb->splash(HZ, "Out of Memory"); - rb->close(fd); return PLUGIN_ERROR; } } @@ -1016,7 +1007,7 @@ int load_and_show(char* filename) if (status < 0 || (status & (DQT | SOF0)) != (DQT | SOF0)) { /* bad format or minimum components not contained */ rb->splashf(HZ, "unsupported %d", status); - file_pt[curfile] = '\0'; + file_pt[curfile] = NULL; return change_filename(direction); } @@ -1035,7 +1026,7 @@ int load_and_show(char* filename) if (ds_min == 0) { rb->splash(HZ, "too large"); - file_pt[curfile] = '\0'; + file_pt[curfile] = NULL; return change_filename(direction); } @@ -1129,6 +1120,12 @@ enum plugin_status plugin_start(const void* parameter) 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); get_pic_list(); @@ -1136,18 +1133,9 @@ enum plugin_status plugin_start(const void* parameter) #if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR) if(rb->audio_status()) - { - buf = rb->plugin_get_buffer((size_t *)&buf_size) + - (entries * sizeof(char**)); - buf_size -= (entries * sizeof(char**)); plug_buf = true; - } else 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 #ifdef USEGSLIB diff --git a/apps/plugins/png/png.c b/apps/plugins/png/png.c index 8a5d05be9a..bda727a16d 100644 --- a/apps/plugins/png/png.c +++ b/apps/plugins/png/png.c @@ -1326,12 +1326,6 @@ void LodePNG_Decoder_cleanup(LodePNG_Decoder* decoder) 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[]) { if (!ext) @@ -1346,34 +1340,32 @@ bool png_ext(const char ext[]) void get_pic_list(void) { int i; - long int str_len = 0; + struct entry *dircache; char *pname; tree = rb->tree_get_context(); + dircache = tree->dircache; -#if PLUGIN_BUFFER_SIZE >= MIN_MEM - 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); + file_pt = (char **) memory; /* Remove path and leave only the name.*/ pname = rb->strrchr(np_file,'/'); pname++; - /* Find Selected File. */ - for (i = 0; i < entries; i++) - if (!rb->strcmp(file_pt[i], pname)) - curfile = i; + for (i = 0; i < tree->filesindir; i++) + { + if (!(dircache[i].attr & ATTR_DIRECTORY) + && 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) @@ -1390,7 +1382,7 @@ int change_filename(int direct) curfile = entries - 1; else curfile--; - }while (file_pt[curfile] == '\0' && count < entries); + }while (file_pt[curfile] == NULL && count < entries); /* we "erase" the file name if we encounter * a non-supported file, so skip it now */ } @@ -1403,14 +1395,15 @@ int change_filename(int direct) curfile = 0; else 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"); return PLUGIN_ERROR; } + if (rb->strlen(tree->currdir) > 1) { rb->strcpy(np_file, tree->currdir); @@ -1549,7 +1542,7 @@ static void pan_view_right(struct LodePNG_Decoder* decoder) { 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) { decoder->x += move; @@ -1595,7 +1588,7 @@ static void pan_view_down(struct LodePNG_Decoder* decoder) { 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) { decoder->y += move; @@ -2028,8 +2021,6 @@ int load_and_show(char* filename) plug_buf = false; memory = rb->plugin_get_audio_buffer( (size_t *)&memory_size); - memory += (entries * sizeof(char**)); - memory_size -= (entries * sizeof(char**)); memory_max = memory + memory_size - 1; /*try again this file, now using the audio buffer */ return PLUGIN_OTHER; @@ -2141,7 +2132,7 @@ int load_and_show(char* filename) } else if (decoder.error == OUT_OF_MEMORY && entries == 1) { return PLUGIN_ERROR; } else { - file_pt[curfile] = '\0'; + file_pt[curfile] = NULL; return change_filename(direction); } } @@ -2226,6 +2217,12 @@ enum plugin_status plugin_start(const void* parameter) 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); get_pic_list(); @@ -2233,17 +2230,12 @@ enum plugin_status plugin_start(const void* parameter) #if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR) if (rb->audio_status()) { - memory = (unsigned char *)rb->plugin_get_buffer((size_t *)&memory_size); plug_buf = true; } else { 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 - memory += (entries * sizeof(char**)); - memory_size -= (entries * sizeof(char**)); memory_max = memory + memory_size - 1; /* should be ok to just load settings since the plugin itself has