summaryrefslogtreecommitdiff
path: root/apps/plugins/jpeg/jpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/jpeg/jpeg.c')
-rw-r--r--apps/plugins/jpeg/jpeg.c74
1 files changed, 31 insertions, 43 deletions
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;
185 185
186/************************* Implementation ***************************/ 186/************************* Implementation ***************************/
187 187
188/* support function for qsort() */
189static int compare(const void* p1, const void* p2)
190{
191 return rb->strcasecmp(*((char **)p1), *((char **)p2));
192}
193
194bool jpg_ext(const char ext[]) 188bool jpg_ext(const char ext[])
195{ 189{
196 if(!ext) 190 if(!ext)
@@ -207,34 +201,32 @@ bool jpg_ext(const char ext[])
207void get_pic_list(void) 201void get_pic_list(void)
208{ 202{
209 int i; 203 int i;
210 long int str_len = 0; 204 struct entry *dircache;
211 char *pname; 205 char *pname;
212 tree = rb->tree_get_context(); 206 tree = rb->tree_get_context();
207 dircache = tree->dircache;
213 208
214#if PLUGIN_BUFFER_SIZE >= MIN_MEM 209 file_pt = (char **) buf;
215 file_pt = rb->plugin_get_buffer((size_t *)&buf_size);
216#else
217 file_pt = rb->plugin_get_audio_buffer((size_t *)&buf_size);
218#endif
219
220 for(i = 0; i < tree->filesindir; i++)
221 {
222 if(jpg_ext(rb->strrchr(&tree->name_buffer[str_len],'.')))
223 file_pt[entries++] = &tree->name_buffer[str_len];
224
225 str_len += rb->strlen(&tree->name_buffer[str_len]) + 1;
226 }
227
228 rb->qsort(file_pt, entries, sizeof(char**), compare);
229 210
230 /* Remove path and leave only the name.*/ 211 /* Remove path and leave only the name.*/
231 pname = rb->strrchr(np_file,'/'); 212 pname = rb->strrchr(np_file,'/');
232 pname++; 213 pname++;
233 214
234 /* Find Selected File. */ 215 for (i = 0; i < tree->filesindir; i++)
235 for(i = 0; i < entries; i++) 216 {
236 if(!rb->strcmp(file_pt[i], pname)) 217 if (!(dircache[i].attr & ATTR_DIRECTORY)
237 curfile = i; 218 && jpg_ext(rb->strrchr(dircache[i].name,'.')))
219 {
220 file_pt[entries] = dircache[i].name;
221 /* Set Selected File. */
222 if (!rb->strcmp(file_pt[entries], pname))
223 curfile = entries;
224 entries++;
225 }
226 }
227
228 buf += (entries * sizeof(char**));
229 buf_size -= (entries * sizeof(char**));
238} 230}
239 231
240int change_filename(int direct) 232int change_filename(int direct)
@@ -251,7 +243,7 @@ int change_filename(int direct)
251 curfile = entries - 1; 243 curfile = entries - 1;
252 else 244 else
253 curfile--; 245 curfile--;
254 }while(file_pt[curfile] == '\0' && count < entries); 246 }while(file_pt[curfile] == NULL && count < entries);
255 /* we "erase" the file name if we encounter 247 /* we "erase" the file name if we encounter
256 * a non-supported file, so skip it now */ 248 * a non-supported file, so skip it now */
257 } 249 }
@@ -264,10 +256,10 @@ int change_filename(int direct)
264 curfile = 0; 256 curfile = 0;
265 else 257 else
266 curfile++; 258 curfile++;
267 }while(file_pt[curfile] == '\0' && count < entries); 259 }while(file_pt[curfile] == NULL && count < entries);
268 } 260 }
269 261
270 if(count == entries && file_pt[curfile] == '\0') 262 if(count == entries)
271 { 263 {
272 rb->splash(HZ, "No supported files"); 264 rb->splash(HZ, "No supported files");
273 return PLUGIN_ERROR; 265 return PLUGIN_ERROR;
@@ -830,7 +822,7 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds)
830 if (status) 822 if (status)
831 { 823 {
832 rb->splashf(HZ, "decode error %d", status); 824 rb->splashf(HZ, "decode error %d", status);
833 file_pt[curfile] = '\0'; 825 file_pt[curfile] = NULL;
834 return NULL; 826 return NULL;
835 } 827 }
836 time = *rb->current_tick - time; 828 time = *rb->current_tick - time;
@@ -907,10 +899,10 @@ int load_and_show(char* filename)
907 899
908 if (buf_size <= 0) 900 if (buf_size <= 0)
909 { 901 {
902 rb->close(fd);
910#if PLUGIN_BUFFER_SIZE >= MIN_MEM 903#if PLUGIN_BUFFER_SIZE >= MIN_MEM
911 if(plug_buf) 904 if(plug_buf)
912 { 905 {
913 rb->close(fd);
914 rb->lcd_setfont(FONT_SYSFIXED); 906 rb->lcd_setfont(FONT_SYSFIXED);
915 rb->lcd_clear_display(); 907 rb->lcd_clear_display();
916 rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1); 908 rb->snprintf(print,sizeof(print),"%s:",rb->strrchr(filename,'/')+1);
@@ -969,7 +961,6 @@ int load_and_show(char* filename)
969#endif 961#endif
970 { 962 {
971 rb->splash(HZ, "Out of Memory"); 963 rb->splash(HZ, "Out of Memory");
972 rb->close(fd);
973 return PLUGIN_ERROR; 964 return PLUGIN_ERROR;
974 } 965 }
975 } 966 }
@@ -1016,7 +1007,7 @@ int load_and_show(char* filename)
1016 if (status < 0 || (status & (DQT | SOF0)) != (DQT | SOF0)) 1007 if (status < 0 || (status & (DQT | SOF0)) != (DQT | SOF0))
1017 { /* bad format or minimum components not contained */ 1008 { /* bad format or minimum components not contained */
1018 rb->splashf(HZ, "unsupported %d", status); 1009 rb->splashf(HZ, "unsupported %d", status);
1019 file_pt[curfile] = '\0'; 1010 file_pt[curfile] = NULL;
1020 return change_filename(direction); 1011 return change_filename(direction);
1021 } 1012 }
1022 1013
@@ -1035,7 +1026,7 @@ int load_and_show(char* filename)
1035 if (ds_min == 0) 1026 if (ds_min == 0)
1036 { 1027 {
1037 rb->splash(HZ, "too large"); 1028 rb->splash(HZ, "too large");
1038 file_pt[curfile] = '\0'; 1029 file_pt[curfile] = NULL;
1039 return change_filename(direction); 1030 return change_filename(direction);
1040 } 1031 }
1041 1032
@@ -1129,6 +1120,12 @@ enum plugin_status plugin_start(const void* parameter)
1129 1120
1130 if(!parameter) return PLUGIN_ERROR; 1121 if(!parameter) return PLUGIN_ERROR;
1131 1122
1123#if PLUGIN_BUFFER_SIZE >= MIN_MEM
1124 buf = rb->plugin_get_buffer((size_t *)&buf_size);
1125#else
1126 buf = rb->plugin_get_audio_buffer((size_t *)&buf_size);
1127#endif
1128
1132 rb->strcpy(np_file, parameter); 1129 rb->strcpy(np_file, parameter);
1133 get_pic_list(); 1130 get_pic_list();
1134 1131
@@ -1136,18 +1133,9 @@ enum plugin_status plugin_start(const void* parameter)
1136 1133
1137#if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR) 1134#if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR)
1138 if(rb->audio_status()) 1135 if(rb->audio_status())
1139 {
1140 buf = rb->plugin_get_buffer((size_t *)&buf_size) +
1141 (entries * sizeof(char**));
1142 buf_size -= (entries * sizeof(char**));
1143 plug_buf = true; 1136 plug_buf = true;
1144 }
1145 else 1137 else
1146 buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); 1138 buf = rb->plugin_get_audio_buffer((size_t *)&buf_size);
1147#else
1148 buf = rb->plugin_get_audio_buffer(&buf_size) +
1149 (entries * sizeof(char**));
1150 buf_size -= (entries * sizeof(char**));
1151#endif 1139#endif
1152 1140
1153#ifdef USEGSLIB 1141#ifdef USEGSLIB