summaryrefslogtreecommitdiff
path: root/apps/plugins/png/png.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/png/png.c')
-rw-r--r--apps/plugins/png/png.c70
1 files changed, 31 insertions, 39 deletions
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() */
1330static int compare(const void* p1, const void* p2)
1331{
1332 return rb->strcasecmp(*((char **)p1), *((char **)p2));
1333}
1334
1335bool png_ext(const char ext[]) 1329bool png_ext(const char ext[])
1336{ 1330{
1337 if (!ext) 1331 if (!ext)
@@ -1346,34 +1340,32 @@ bool png_ext(const char ext[])
1346void get_pic_list(void) 1340void 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
1379int change_filename(int direct) 1371int 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