diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/jpeg/jpeg.c | 74 | ||||
-rw-r--r-- | apps/plugins/png/png.c | 70 |
2 files changed, 62 insertions, 82 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() */ | ||
189 | static int compare(const void* p1, const void* p2) | ||
190 | { | ||
191 | return rb->strcasecmp(*((char **)p1), *((char **)p2)); | ||
192 | } | ||
193 | |||
194 | bool jpg_ext(const char ext[]) | 188 | bool jpg_ext(const char ext[]) |
195 | { | 189 | { |
196 | if(!ext) | 190 | if(!ext) |
@@ -207,34 +201,32 @@ bool jpg_ext(const char ext[]) | |||
207 | void get_pic_list(void) | 201 | void 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 | ||
240 | int change_filename(int direct) | 232 | int 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 |
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) | |||
1326 | LodePNG_InfoPng_cleanup(&decoder->infoPng); | 1326 | LodePNG_InfoPng_cleanup(&decoder->infoPng); |
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | /* support function for qsort() */ | ||
1330 | static int compare(const void* p1, const void* p2) | ||
1331 | { | ||
1332 | return rb->strcasecmp(*((char **)p1), *((char **)p2)); | ||
1333 | } | ||
1334 | |||
1335 | bool png_ext(const char ext[]) | 1329 | bool png_ext(const char ext[]) |
1336 | { | 1330 | { |
1337 | if (!ext) | 1331 | if (!ext) |
@@ -1346,34 +1340,32 @@ bool png_ext(const char ext[]) | |||
1346 | void get_pic_list(void) | 1340 | void get_pic_list(void) |
1347 | { | 1341 | { |
1348 | int i; | 1342 | int i; |
1349 | long int str_len = 0; | 1343 | struct entry *dircache; |
1350 | char *pname; | 1344 | char *pname; |
1351 | tree = rb->tree_get_context(); | 1345 | tree = rb->tree_get_context(); |
1346 | dircache = tree->dircache; | ||
1352 | 1347 | ||
1353 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 1348 | file_pt = (char **) memory; |
1354 | file_pt = rb->plugin_get_buffer((size_t *)&image_size); | ||
1355 | #else | ||
1356 | file_pt = rb->plugin_get_audio_buffer((size_t *)&image_size); | ||
1357 | #endif | ||
1358 | |||
1359 | for (i = 0; i < tree->filesindir; i++) | ||
1360 | { | ||
1361 | if (png_ext(rb->strrchr(&tree->name_buffer[str_len],'.'))) | ||
1362 | file_pt[entries++] = &tree->name_buffer[str_len]; | ||
1363 | |||
1364 | str_len += rb->strlen(&tree->name_buffer[str_len]) + 1; | ||
1365 | } | ||
1366 | |||
1367 | rb->qsort(file_pt, entries, sizeof(char**), compare); | ||
1368 | 1349 | ||
1369 | /* Remove path and leave only the name.*/ | 1350 | /* Remove path and leave only the name.*/ |
1370 | pname = rb->strrchr(np_file,'/'); | 1351 | pname = rb->strrchr(np_file,'/'); |
1371 | pname++; | 1352 | pname++; |
1372 | 1353 | ||
1373 | /* Find Selected File. */ | 1354 | for (i = 0; i < tree->filesindir; i++) |
1374 | for (i = 0; i < entries; i++) | 1355 | { |
1375 | if (!rb->strcmp(file_pt[i], pname)) | 1356 | if (!(dircache[i].attr & ATTR_DIRECTORY) |
1376 | curfile = i; | 1357 | && png_ext(rb->strrchr(dircache[i].name, '.'))) |
1358 | { | ||
1359 | file_pt[entries] = dircache[i].name; | ||
1360 | /* Set Selected File. */ | ||
1361 | if (!rb->strcmp(file_pt[entries], pname)) | ||
1362 | curfile = entries; | ||
1363 | entries++; | ||
1364 | } | ||
1365 | } | ||
1366 | |||
1367 | memory += (entries * sizeof(char**)); | ||
1368 | memory_size -= (entries * sizeof(char**)); | ||
1377 | } | 1369 | } |
1378 | 1370 | ||
1379 | int change_filename(int direct) | 1371 | int change_filename(int direct) |
@@ -1390,7 +1382,7 @@ int change_filename(int direct) | |||
1390 | curfile = entries - 1; | 1382 | curfile = entries - 1; |
1391 | else | 1383 | else |
1392 | curfile--; | 1384 | curfile--; |
1393 | }while (file_pt[curfile] == '\0' && count < entries); | 1385 | }while (file_pt[curfile] == NULL && count < entries); |
1394 | /* we "erase" the file name if we encounter | 1386 | /* we "erase" the file name if we encounter |
1395 | * a non-supported file, so skip it now */ | 1387 | * a non-supported file, so skip it now */ |
1396 | } | 1388 | } |
@@ -1403,14 +1395,15 @@ int change_filename(int direct) | |||
1403 | curfile = 0; | 1395 | curfile = 0; |
1404 | else | 1396 | else |
1405 | curfile++; | 1397 | curfile++; |
1406 | }while (file_pt[curfile] == '\0' && count < entries); | 1398 | }while (file_pt[curfile] == NULL && count < entries); |
1407 | } | 1399 | } |
1408 | 1400 | ||
1409 | if (count == entries && file_pt[curfile] == '\0') | 1401 | if (count == entries) |
1410 | { | 1402 | { |
1411 | rb->splash(HZ, "No supported files"); | 1403 | rb->splash(HZ, "No supported files"); |
1412 | return PLUGIN_ERROR; | 1404 | return PLUGIN_ERROR; |
1413 | } | 1405 | } |
1406 | |||
1414 | if (rb->strlen(tree->currdir) > 1) | 1407 | if (rb->strlen(tree->currdir) > 1) |
1415 | { | 1408 | { |
1416 | rb->strcpy(np_file, tree->currdir); | 1409 | rb->strcpy(np_file, tree->currdir); |
@@ -1549,7 +1542,7 @@ static void pan_view_right(struct LodePNG_Decoder* decoder) | |||
1549 | { | 1542 | { |
1550 | int move; | 1543 | int move; |
1551 | 1544 | ||
1552 | move = MIN(HSCROLL, decoder->infoPng.width/ds - decoder->x - LCD_WIDTH); | 1545 | move = MIN(HSCROLL, (int)(decoder->infoPng.width/ds) - decoder->x - LCD_WIDTH); |
1553 | if (move > 0) | 1546 | if (move > 0) |
1554 | { | 1547 | { |
1555 | decoder->x += move; | 1548 | decoder->x += move; |
@@ -1595,7 +1588,7 @@ static void pan_view_down(struct LodePNG_Decoder* decoder) | |||
1595 | { | 1588 | { |
1596 | int move; | 1589 | int move; |
1597 | 1590 | ||
1598 | move = MIN(VSCROLL, decoder->infoPng.height/ds - decoder->y - LCD_HEIGHT); | 1591 | move = MIN(VSCROLL, (int)(decoder->infoPng.height/ds) - decoder->y - LCD_HEIGHT); |
1599 | if (move > 0) | 1592 | if (move > 0) |
1600 | { | 1593 | { |
1601 | decoder->y += move; | 1594 | decoder->y += move; |
@@ -2028,8 +2021,6 @@ int load_and_show(char* filename) | |||
2028 | plug_buf = false; | 2021 | plug_buf = false; |
2029 | memory = rb->plugin_get_audio_buffer( | 2022 | memory = rb->plugin_get_audio_buffer( |
2030 | (size_t *)&memory_size); | 2023 | (size_t *)&memory_size); |
2031 | memory += (entries * sizeof(char**)); | ||
2032 | memory_size -= (entries * sizeof(char**)); | ||
2033 | memory_max = memory + memory_size - 1; | 2024 | memory_max = memory + memory_size - 1; |
2034 | /*try again this file, now using the audio buffer */ | 2025 | /*try again this file, now using the audio buffer */ |
2035 | return PLUGIN_OTHER; | 2026 | return PLUGIN_OTHER; |
@@ -2141,7 +2132,7 @@ int load_and_show(char* filename) | |||
2141 | } else if (decoder.error == OUT_OF_MEMORY && entries == 1) { | 2132 | } else if (decoder.error == OUT_OF_MEMORY && entries == 1) { |
2142 | return PLUGIN_ERROR; | 2133 | return PLUGIN_ERROR; |
2143 | } else { | 2134 | } else { |
2144 | file_pt[curfile] = '\0'; | 2135 | file_pt[curfile] = NULL; |
2145 | return change_filename(direction); | 2136 | return change_filename(direction); |
2146 | } | 2137 | } |
2147 | } | 2138 | } |
@@ -2226,6 +2217,12 @@ enum plugin_status plugin_start(const void* parameter) | |||
2226 | 2217 | ||
2227 | if (!parameter) return PLUGIN_ERROR; | 2218 | if (!parameter) return PLUGIN_ERROR; |
2228 | 2219 | ||
2220 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | ||
2221 | memory = rb->plugin_get_buffer((size_t *)&memory_size); | ||
2222 | #else | ||
2223 | memory = rb->plugin_get_audio_buffer((size_t *)&memory_size); | ||
2224 | #endif | ||
2225 | |||
2229 | rb->strcpy(np_file, parameter); | 2226 | rb->strcpy(np_file, parameter); |
2230 | get_pic_list(); | 2227 | get_pic_list(); |
2231 | 2228 | ||
@@ -2233,17 +2230,12 @@ enum plugin_status plugin_start(const void* parameter) | |||
2233 | 2230 | ||
2234 | #if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR) | 2231 | #if (PLUGIN_BUFFER_SIZE >= MIN_MEM) && !defined(SIMULATOR) |
2235 | if (rb->audio_status()) { | 2232 | if (rb->audio_status()) { |
2236 | memory = (unsigned char *)rb->plugin_get_buffer((size_t *)&memory_size); | ||
2237 | plug_buf = true; | 2233 | plug_buf = true; |
2238 | } else { | 2234 | } else { |
2239 | memory = (unsigned char *)rb->plugin_get_audio_buffer((size_t *)&memory_size); | 2235 | memory = (unsigned char *)rb->plugin_get_audio_buffer((size_t *)&memory_size); |
2240 | } | 2236 | } |
2241 | #else | ||
2242 | memory = (unsigned char *)rb->plugin_get_audio_buffer((size_t *)&memory_size); | ||
2243 | #endif | 2237 | #endif |
2244 | 2238 | ||
2245 | memory += (entries * sizeof(char**)); | ||
2246 | memory_size -= (entries * sizeof(char**)); | ||
2247 | memory_max = memory + memory_size - 1; | 2239 | memory_max = memory + memory_size - 1; |
2248 | 2240 | ||
2249 | /* should be ok to just load settings since the plugin itself has | 2241 | /* should be ok to just load settings since the plugin itself has |