summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2009-11-18 13:54:14 +0000
committerTeruaki Kawashima <teru@rockbox.org>2009-11-18 13:54:14 +0000
commit34447162033563900c8f93ce3471d54e7205f09a (patch)
tree95c5918cbbde0046ac34d8e5daa739d7567ead14
parent36fc4439c249957f59ffc82ea1ff1649daa14ead (diff)
downloadrockbox-34447162033563900c8f93ce3471d54e7205f09a.tar.gz
rockbox-34447162033563900c8f93ce3471d54e7205f09a.zip
jpeg/png: Remove erased file name from list of file when change file.
Change trivial check of entries (entries is always > 0). Fix bug of r23632 that error message is shown when change file while there is only one file. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23662 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/jpeg/jpeg.c81
-rw-r--r--apps/plugins/png/png.c74
2 files changed, 72 insertions, 83 deletions
diff --git a/apps/plugins/jpeg/jpeg.c b/apps/plugins/jpeg/jpeg.c
index e3c210b4a5..1049e4827e 100644
--- a/apps/plugins/jpeg/jpeg.c
+++ b/apps/plugins/jpeg/jpeg.c
@@ -55,8 +55,6 @@ GREY_INFO_STRUCT
55#define MYXLCD(fn) xlcd_ ## fn 55#define MYXLCD(fn) xlcd_ ## fn
56#endif 56#endif
57 57
58#define MAX_X_SIZE LCD_WIDTH*8
59
60/* Min memory allowing us to use the plugin buffer 58/* Min memory allowing us to use the plugin buffer
61 * and thus not stopping the music 59 * and thus not stopping the music
62 * *Very* rough estimation: 60 * *Very* rough estimation:
@@ -233,40 +231,34 @@ void get_pic_list(void)
233 231
234int change_filename(int direct) 232int change_filename(int direct)
235{ 233{
236 int count = 0; 234 bool file_erased = (file_pt[curfile] == NULL);
237 direction = direct; 235 direction = direct;
238 236
239 if(direct == DIR_PREV) 237 curfile += (direct == DIR_PREV? entries - 1: 1);
240 { 238 if (curfile >= entries)
241 do 239 curfile -= entries;
242 { 240
243 count++; 241 if (file_erased)
244 if(curfile == 0)
245 curfile = entries - 1;
246 else
247 curfile--;
248 }while(file_pt[curfile] == NULL && count < entries);
249 /* we "erase" the file name if we encounter
250 * a non-supported file, so skip it now */
251 }
252 else /* DIR_NEXT/DIR_NONE */
253 { 242 {
254 do 243 /* remove 'erased' file names from list. */
244 int count, i;
245 for (count = i = 0; i < entries; i++)
255 { 246 {
256 count++; 247 if (curfile == i)
257 if(curfile == entries - 1) 248 curfile = count;
258 curfile = 0; 249 if (file_pt[i] != NULL)
259 else 250 file_pt[count++] = file_pt[i];
260 curfile++; 251 }
261 }while(file_pt[curfile] == NULL && count < entries); 252 entries = count;
262 } 253 }
263 254
264 if(count == entries) 255 if (entries == 0)
265 { 256 {
266 rb->splash(HZ, "No supported files"); 257 rb->splash(HZ, "No supported files");
267 return PLUGIN_ERROR; 258 return PLUGIN_ERROR;
268 } 259 }
269 if(rb->strlen(tree->currdir) > 1) 260
261 if (rb->strlen(tree->currdir) > 1)
270 { 262 {
271 rb->strcpy(np_file, tree->currdir); 263 rb->strcpy(np_file, tree->currdir);
272 rb->strcat(np_file, "/"); 264 rb->strcat(np_file, "/");
@@ -572,14 +564,16 @@ int scroll_bmp(struct t_disp* pdisp)
572 switch(button) 564 switch(button)
573 { 565 {
574 case JPEG_LEFT: 566 case JPEG_LEFT:
575 if (!(ds < ds_max) && entries > 0 && jpg.x_size <= MAX_X_SIZE) 567 if (entries > 1 && pdisp->width <= LCD_WIDTH
568 && pdisp->height <= LCD_HEIGHT)
576 return change_filename(DIR_PREV); 569 return change_filename(DIR_PREV);
577 case JPEG_LEFT | BUTTON_REPEAT: 570 case JPEG_LEFT | BUTTON_REPEAT:
578 pan_view_left(pdisp); 571 pan_view_left(pdisp);
579 break; 572 break;
580 573
581 case JPEG_RIGHT: 574 case JPEG_RIGHT:
582 if (!(ds < ds_max) && entries > 0 && jpg.x_size <= MAX_X_SIZE) 575 if (entries > 1 && pdisp->width <= LCD_WIDTH
576 && pdisp->height <= LCD_HEIGHT)
583 return change_filename(DIR_NEXT); 577 return change_filename(DIR_NEXT);
584 case JPEG_RIGHT | BUTTON_REPEAT: 578 case JPEG_RIGHT | BUTTON_REPEAT:
585 pan_view_right(pdisp); 579 pan_view_right(pdisp);
@@ -599,7 +593,7 @@ int scroll_bmp(struct t_disp* pdisp)
599 if (!slideshow_enabled) 593 if (!slideshow_enabled)
600 break; 594 break;
601 running_slideshow = true; 595 running_slideshow = true;
602 if (entries > 0) 596 if (entries > 1)
603 return change_filename(DIR_NEXT); 597 return change_filename(DIR_NEXT);
604 break; 598 break;
605 599
@@ -614,7 +608,7 @@ int scroll_bmp(struct t_disp* pdisp)
614 case JPEG_NEXT_REPEAT: 608 case JPEG_NEXT_REPEAT:
615#endif 609#endif
616 case JPEG_NEXT: 610 case JPEG_NEXT:
617 if (entries > 0) 611 if (entries > 1)
618 return change_filename(DIR_NEXT); 612 return change_filename(DIR_NEXT);
619 break; 613 break;
620 614
@@ -622,7 +616,7 @@ int scroll_bmp(struct t_disp* pdisp)
622 case JPEG_PREVIOUS_REPEAT: 616 case JPEG_PREVIOUS_REPEAT:
623#endif 617#endif
624 case JPEG_PREVIOUS: 618 case JPEG_PREVIOUS:
625 if (entries > 0) 619 if (entries > 1)
626 return change_filename(DIR_PREV); 620 return change_filename(DIR_PREV);
627 break; 621 break;
628 622
@@ -675,21 +669,23 @@ int scroll_bmp(struct t_disp* pdisp)
675/********************* main function *************************/ 669/********************* main function *************************/
676 670
677/* callback updating a progress meter while JPEG decoding */ 671/* callback updating a progress meter while JPEG decoding */
678void cb_progess(int current, int total) 672void cb_progress(int current, int total)
679{ 673{
680 rb->yield(); /* be nice to the other threads */ 674 rb->yield(); /* be nice to the other threads */
681 if(!running_slideshow) 675 if(!running_slideshow)
682 { 676 {
683 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, LCD_HEIGHT-8, LCD_WIDTH, 8, total, 0, 677 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
684 current, HORIZONTAL); 678 0, LCD_HEIGHT-8, LCD_WIDTH, 8,
679 total, 0, current, HORIZONTAL);
685 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); 680 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
686 } 681 }
687#ifndef USEGSLIB 682#ifndef USEGSLIB
688 else 683 else
689 { 684 {
690 /* in slideshow mode, keep gui interference to a minimum */ 685 /* in slideshow mode, keep gui interference to a minimum */
691 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, LCD_HEIGHT-4, LCD_WIDTH, 4, total, 0, 686 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
692 current, HORIZONTAL); 687 0, LCD_HEIGHT-4, LCD_WIDTH, 4,
688 total, 0, current, HORIZONTAL);
693 rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4); 689 rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4);
694 } 690 }
695#endif 691#endif
@@ -727,14 +723,13 @@ int min_downscale(struct jpeg *p_jpg, int bufsize)
727 return downscale; 723 return downscale;
728} 724}
729 725
730
731/* how far can we zoom out, to fit image into the LCD */ 726/* how far can we zoom out, to fit image into the LCD */
732int max_downscale(struct jpeg *p_jpg) 727int max_downscale(struct jpeg *p_jpg)
733{ 728{
734 int downscale = 1; 729 int downscale = 1;
735 730
736 while (downscale < 8 && (p_jpg->x_size > LCD_WIDTH*downscale 731 while (downscale < 8 && (p_jpg->x_size/downscale > LCD_WIDTH
737 || p_jpg->y_size > LCD_HEIGHT*downscale)) 732 || p_jpg->y_size/downscale > LCD_HEIGHT))
738 { 733 {
739 downscale *= 2; 734 downscale *= 2;
740 } 735 }
@@ -816,15 +811,14 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds)
816 time = *rb->current_tick; 811 time = *rb->current_tick;
817#ifdef HAVE_ADJUSTABLE_CPU_FREQ 812#ifdef HAVE_ADJUSTABLE_CPU_FREQ
818 rb->cpu_boost(true); 813 rb->cpu_boost(true);
819 status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progess); 814 status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progress);
820 rb->cpu_boost(false); 815 rb->cpu_boost(false);
821#else 816#else
822 status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progess); 817 status = jpeg_decode(p_jpg, p_disp->bitmap, ds, cb_progress);
823#endif 818#endif
824 if (status) 819 if (status)
825 { 820 {
826 rb->splashf(HZ, "decode error %d", status); 821 rb->splashf(HZ, "decode error %d", status);
827 file_pt[curfile] = NULL;
828 return NULL; 822 return NULL;
829 } 823 }
830 time = *rb->current_tick - time; 824 time = *rb->current_tick - time;
@@ -1038,7 +1032,10 @@ int load_and_show(char* filename)
1038 { 1032 {
1039 p_disp = get_image(&jpg, ds); /* decode or fetch from cache */ 1033 p_disp = get_image(&jpg, ds); /* decode or fetch from cache */
1040 if (p_disp == NULL) 1034 if (p_disp == NULL)
1035 {
1036 file_pt[curfile] = NULL;
1041 return change_filename(direction); 1037 return change_filename(direction);
1038 }
1042 1039
1043 set_view(p_disp, cx, cy); 1040 set_view(p_disp, cx, cy);
1044 1041
diff --git a/apps/plugins/png/png.c b/apps/plugins/png/png.c
index 4cbf74c71c..e50605776c 100644
--- a/apps/plugins/png/png.c
+++ b/apps/plugins/png/png.c
@@ -225,8 +225,6 @@ static struct configdata png_config[] =
225static fb_data* old_backdrop; 225static fb_data* old_backdrop;
226#endif 226#endif
227 227
228#define MAX_X_SIZE LCD_WIDTH*8
229
230/* Min memory allowing us to use the plugin buffer 228/* Min memory allowing us to use the plugin buffer
231 * and thus not stopping the music 229 * and thus not stopping the music
232 * *Very* rough estimation: 230 * *Very* rough estimation:
@@ -1369,35 +1367,28 @@ void get_pic_list(void)
1369 1367
1370int change_filename(int direct) 1368int change_filename(int direct)
1371{ 1369{
1372 int count = 0; 1370 bool file_erased = (file_pt[curfile] == NULL);
1373 direction = direct; 1371 direction = direct;
1374 1372
1375 if (direct == DIR_PREV) 1373 curfile += (direct == DIR_PREV? entries - 1: 1);
1376 { 1374 if (curfile >= entries)
1377 do 1375 curfile -= entries;
1378 { 1376
1379 count++; 1377 if (file_erased)
1380 if (curfile == 0)
1381 curfile = entries - 1;
1382 else
1383 curfile--;
1384 }while (file_pt[curfile] == NULL && count < entries);
1385 /* we "erase" the file name if we encounter
1386 * a non-supported file, so skip it now */
1387 }
1388 else /* DIR_NEXT/DIR_NONE */
1389 { 1378 {
1390 do 1379 /* remove 'erased' file names from list. */
1380 int count, i;
1381 for (count = i = 0; i < entries; i++)
1391 { 1382 {
1392 count++; 1383 if (curfile == i)
1393 if (curfile == entries - 1) 1384 curfile = count;
1394 curfile = 0; 1385 if (file_pt[i] != NULL)
1395 else 1386 file_pt[count++] = file_pt[i];
1396 curfile++; 1387 }
1397 }while (file_pt[curfile] == NULL && count < entries); 1388 entries = count;
1398 } 1389 }
1399 1390
1400 if (count == entries) 1391 if (entries == 0)
1401 { 1392 {
1402 rb->splash(HZ, "No supported files"); 1393 rb->splash(HZ, "No supported files");
1403 return PLUGIN_ERROR; 1394 return PLUGIN_ERROR;
@@ -1613,14 +1604,16 @@ int scroll_bmp(struct LodePNG_Decoder* decoder)
1613 switch (button) 1604 switch (button)
1614 { 1605 {
1615 case PNG_LEFT: 1606 case PNG_LEFT:
1616 if (!(ds < ds_max) && entries > 0 && decoder->infoPng.width <= MAX_X_SIZE) 1607 if (entries > 1 && decoder->infoPng.width/ds <= LCD_WIDTH
1608 && decoder->infoPng.height/ds <= LCD_HEIGHT)
1617 return change_filename(DIR_PREV); 1609 return change_filename(DIR_PREV);
1618 case PNG_LEFT | BUTTON_REPEAT: 1610 case PNG_LEFT | BUTTON_REPEAT:
1619 pan_view_left(decoder); 1611 pan_view_left(decoder);
1620 break; 1612 break;
1621 1613
1622 case PNG_RIGHT: 1614 case PNG_RIGHT:
1623 if (!(ds < ds_max) && entries > 0 && decoder->infoPng.width <= MAX_X_SIZE) 1615 if (entries > 1 && decoder->infoPng.width/ds <= LCD_WIDTH
1616 && decoder->infoPng.height/ds <= LCD_HEIGHT)
1624 return change_filename(DIR_NEXT); 1617 return change_filename(DIR_NEXT);
1625 case PNG_RIGHT | BUTTON_REPEAT: 1618 case PNG_RIGHT | BUTTON_REPEAT:
1626 pan_view_right(decoder); 1619 pan_view_right(decoder);
@@ -1640,7 +1633,7 @@ int scroll_bmp(struct LodePNG_Decoder* decoder)
1640 if (!slideshow_enabled) 1633 if (!slideshow_enabled)
1641 break; 1634 break;
1642 running_slideshow = true; 1635 running_slideshow = true;
1643 if (entries > 0) 1636 if (entries > 1)
1644 return change_filename(DIR_NEXT); 1637 return change_filename(DIR_NEXT);
1645 break; 1638 break;
1646 1639
@@ -1655,7 +1648,7 @@ int scroll_bmp(struct LodePNG_Decoder* decoder)
1655 case PNG_NEXT_REPEAT: 1648 case PNG_NEXT_REPEAT:
1656#endif 1649#endif
1657 case PNG_NEXT: 1650 case PNG_NEXT:
1658 if (entries > 0) 1651 if (entries > 1)
1659 return change_filename(DIR_NEXT); 1652 return change_filename(DIR_NEXT);
1660 break; 1653 break;
1661 1654
@@ -1663,7 +1656,7 @@ int scroll_bmp(struct LodePNG_Decoder* decoder)
1663 case PNG_PREVIOUS_REPEAT: 1656 case PNG_PREVIOUS_REPEAT:
1664#endif 1657#endif
1665 case PNG_PREVIOUS: 1658 case PNG_PREVIOUS:
1666 if (entries > 0) 1659 if (entries > 1)
1667 return change_filename(DIR_PREV); 1660 return change_filename(DIR_PREV);
1668 break; 1661 break;
1669 1662
@@ -1735,15 +1728,17 @@ void cb_progress(int current, int total)
1735 if (current & 1) rb->yield(); /* be nice to the other threads */ 1728 if (current & 1) rb->yield(); /* be nice to the other threads */
1736 if (!running_slideshow) 1729 if (!running_slideshow)
1737 { 1730 {
1738 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, LCD_HEIGHT-8, LCD_WIDTH, 8, total, 0, 1731 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
1739 current, HORIZONTAL); 1732 0, LCD_HEIGHT-8, LCD_WIDTH, 8,
1733 total, 0, current, HORIZONTAL);
1740 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); 1734 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
1741 } 1735 }
1742 else 1736 else
1743 { 1737 {
1744 /* in slideshow mode, keep gui interference to a minimum */ 1738 /* in slideshow mode, keep gui interference to a minimum */
1745 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, LCD_HEIGHT-4, LCD_WIDTH, 4, total, 0, 1739 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
1746 current, HORIZONTAL); 1740 0, LCD_HEIGHT-4, LCD_WIDTH, 4,
1741 total, 0, current, HORIZONTAL);
1747 rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4); 1742 rb->lcd_update_rect(0, LCD_HEIGHT-4, LCD_WIDTH, 4);
1748 } 1743 }
1749} 1744}
@@ -1772,8 +1767,8 @@ unsigned max_downscale(struct LodePNG_Decoder* decoder)
1772{ 1767{
1773 unsigned downscale = 1; 1768 unsigned downscale = 1;
1774 1769
1775 while (downscale < 8 && (decoder->infoPng.width > LCD_WIDTH*downscale 1770 while (downscale < 8 && (decoder->infoPng.width/downscale > LCD_WIDTH
1776 || decoder->infoPng.height > LCD_HEIGHT*downscale)) 1771 || decoder->infoPng.height/downscale > LCD_HEIGHT))
1777 { 1772 {
1778 downscale *= 2; 1773 downscale *= 2;
1779 } 1774 }
@@ -2007,8 +2002,7 @@ int load_and_show(char* filename)
2007 { 2002 {
2008 case PNG_ZOOM_IN: 2003 case PNG_ZOOM_IN:
2009 plug_buf = false; 2004 plug_buf = false;
2010 memory = rb->plugin_get_audio_buffer( 2005 memory = rb->plugin_get_audio_buffer((size_t *)&memory_size);
2011 (size_t *)&memory_size);
2012 memory_max = memory + memory_size - 1; 2006 memory_max = memory + memory_size - 1;
2013 /*try again this file, now using the audio buffer */ 2007 /*try again this file, now using the audio buffer */
2014 return PLUGIN_OTHER; 2008 return PLUGIN_OTHER;
@@ -2117,8 +2111,6 @@ int load_and_show(char* filename)
2117 2111
2118 if (decoder.error == PLUGIN_ABORT) { 2112 if (decoder.error == PLUGIN_ABORT) {
2119 return PLUGIN_OK; 2113 return PLUGIN_OK;
2120 } else if (decoder.error == OUT_OF_MEMORY && entries == 1) {
2121 return PLUGIN_ERROR;
2122 } else { 2114 } else {
2123 file_pt[curfile] = NULL; 2115 file_pt[curfile] = NULL;
2124 return change_filename(direction); 2116 return change_filename(direction);
@@ -2220,7 +2212,7 @@ enum plugin_status plugin_start(const void* parameter)
2220 if (rb->audio_status()) { 2212 if (rb->audio_status()) {
2221 plug_buf = true; 2213 plug_buf = true;
2222 } else { 2214 } else {
2223 memory = (unsigned char *)rb->plugin_get_audio_buffer((size_t *)&memory_size); 2215 memory = rb->plugin_get_audio_buffer((size_t *)&memory_size);
2224 } 2216 }
2225#endif 2217#endif
2226 2218