diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/jpeg/jpeg.c | 48 | ||||
-rw-r--r-- | apps/plugins/png/png.c | 30 |
2 files changed, 32 insertions, 46 deletions
diff --git a/apps/plugins/jpeg/jpeg.c b/apps/plugins/jpeg/jpeg.c index 44907e6bd2..e3c210b4a5 100644 --- a/apps/plugins/jpeg/jpeg.c +++ b/apps/plugins/jpeg/jpeg.c | |||
@@ -158,16 +158,18 @@ static struct t_disp disp[9]; | |||
158 | 158 | ||
159 | /* my memory pool (from the mp3 buffer) */ | 159 | /* my memory pool (from the mp3 buffer) */ |
160 | static char print[32]; /* use a common snprintf() buffer */ | 160 | static char print[32]; /* use a common snprintf() buffer */ |
161 | static unsigned char* buf; /* up to here currently used by image(s) */ | ||
162 | |||
163 | /* the remaining free part of the buffer for compressed+uncompressed images */ | 161 | /* the remaining free part of the buffer for compressed+uncompressed images */ |
164 | static unsigned char* buf_images; | 162 | static unsigned char* buf; |
163 | static ssize_t buf_size; | ||
165 | 164 | ||
166 | static ssize_t buf_size, buf_images_size; | ||
167 | /* the root of the images, hereafter are decompresed ones */ | 165 | /* the root of the images, hereafter are decompresed ones */ |
168 | static unsigned char* buf_root; | 166 | static unsigned char* buf_root; |
169 | static int root_size; | 167 | static int root_size; |
170 | 168 | ||
169 | /* up to here currently used by image(s) */ | ||
170 | static unsigned char* buf_images; | ||
171 | static ssize_t buf_images_size; | ||
172 | |||
171 | static int ds, ds_min, ds_max; /* downscaling and limits */ | 173 | static int ds, ds_min, ds_max; /* downscaling and limits */ |
172 | static struct jpeg jpg; /* too large for stack */ | 174 | static struct jpeg jpg; /* too large for stack */ |
173 | 175 | ||
@@ -760,13 +762,13 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds) | |||
760 | 762 | ||
761 | /* physical size needed for decoding */ | 763 | /* physical size needed for decoding */ |
762 | size = jpegmem(p_jpg, ds); | 764 | size = jpegmem(p_jpg, ds); |
763 | if (buf_size <= size) | 765 | if (buf_images_size <= size) |
764 | { /* have to discard the current */ | 766 | { /* have to discard the current */ |
765 | int i; | 767 | int i; |
766 | for (i=1; i<=8; i++) | 768 | for (i=1; i<=8; i++) |
767 | disp[i].bitmap[0] = NULL; /* invalidate all bitmaps */ | 769 | disp[i].bitmap[0] = NULL; /* invalidate all bitmaps */ |
768 | buf = buf_root; /* start again from the beginning of the buffer */ | 770 | buf_images = buf_root; /* start again from the beginning of the buffer */ |
769 | buf_size = root_size; | 771 | buf_images_size = root_size; |
770 | } | 772 | } |
771 | 773 | ||
772 | #ifdef HAVE_LCD_COLOR | 774 | #ifdef HAVE_LCD_COLOR |
@@ -778,9 +780,9 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds) | |||
778 | { | 780 | { |
779 | size = (p_jpg->x_phys / ds / p_jpg->subsample_x[i]) | 781 | size = (p_jpg->x_phys / ds / p_jpg->subsample_x[i]) |
780 | * (p_jpg->y_phys / ds / p_jpg->subsample_y[i]); | 782 | * (p_jpg->y_phys / ds / p_jpg->subsample_y[i]); |
781 | p_disp->bitmap[i] = buf; | 783 | p_disp->bitmap[i] = buf_images; |
782 | buf += size; | 784 | buf_images += size; |
783 | buf_size -= size; | 785 | buf_images_size -= size; |
784 | } | 786 | } |
785 | p_disp->csub_x = p_jpg->subsample_x[1]; | 787 | p_disp->csub_x = p_jpg->subsample_x[1]; |
786 | p_disp->csub_y = p_jpg->subsample_y[1]; | 788 | p_disp->csub_y = p_jpg->subsample_y[1]; |
@@ -788,14 +790,14 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds) | |||
788 | else | 790 | else |
789 | { | 791 | { |
790 | p_disp->csub_x = p_disp->csub_y = 0; | 792 | p_disp->csub_x = p_disp->csub_y = 0; |
791 | p_disp->bitmap[1] = p_disp->bitmap[2] = buf; | 793 | p_disp->bitmap[1] = p_disp->bitmap[2] = buf_images; |
792 | } | 794 | } |
793 | #endif | 795 | #endif |
794 | /* size may be less when decoded (if height is not block aligned) */ | 796 | /* size may be less when decoded (if height is not block aligned) */ |
795 | size = (p_jpg->x_phys/ds) * (p_jpg->y_size / ds); | 797 | size = (p_jpg->x_phys/ds) * (p_jpg->y_size / ds); |
796 | p_disp->bitmap[0] = buf; | 798 | p_disp->bitmap[0] = buf_images; |
797 | buf += size; | 799 | buf_images += size; |
798 | buf_size -= size; | 800 | buf_images_size -= size; |
799 | 801 | ||
800 | if(!running_slideshow) | 802 | if(!running_slideshow) |
801 | { | 803 | { |
@@ -889,15 +891,14 @@ int load_and_show(char* filename) | |||
889 | filesize = rb->filesize(fd); | 891 | filesize = rb->filesize(fd); |
890 | rb->memset(&disp, 0, sizeof(disp)); | 892 | rb->memset(&disp, 0, sizeof(disp)); |
891 | 893 | ||
892 | buf = buf_images + filesize; | ||
893 | buf_size = buf_images_size - filesize; | ||
894 | /* allocate JPEG buffer */ | 894 | /* allocate JPEG buffer */ |
895 | buf_jpeg = buf_images; | 895 | buf_jpeg = buf; |
896 | 896 | ||
897 | buf_root = buf; /* we can start the decompressed images behind it */ | 897 | /* we can start the decompressed images behind it */ |
898 | root_size = buf_size; | 898 | buf_images = buf_root = buf + filesize; |
899 | buf_images_size = root_size = buf_size - filesize; | ||
899 | 900 | ||
900 | if (buf_size <= 0) | 901 | if (buf_images_size <= 0) |
901 | { | 902 | { |
902 | rb->close(fd); | 903 | rb->close(fd); |
903 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM | 904 | #if PLUGIN_BUFFER_SIZE >= MIN_MEM |
@@ -924,8 +925,7 @@ int load_and_show(char* filename) | |||
924 | { | 925 | { |
925 | case JPEG_ZOOM_IN: | 926 | case JPEG_ZOOM_IN: |
926 | plug_buf = false; | 927 | plug_buf = false; |
927 | buf_images = rb->plugin_get_audio_buffer( | 928 | buf = rb->plugin_get_audio_buffer((size_t *)&buf_size); |
928 | (size_t *)&buf_images_size); | ||
929 | /*try again this file, now using the audio buffer */ | 929 | /*try again this file, now using the audio buffer */ |
930 | return PLUGIN_OTHER; | 930 | return PLUGIN_OTHER; |
931 | #ifdef JPEG_RC_MENU | 931 | #ifdef JPEG_RC_MENU |
@@ -1022,7 +1022,7 @@ int load_and_show(char* filename) | |||
1022 | rb->lcd_update(); | 1022 | rb->lcd_update(); |
1023 | } | 1023 | } |
1024 | ds_max = max_downscale(&jpg); /* check display constraint */ | 1024 | ds_max = max_downscale(&jpg); /* check display constraint */ |
1025 | ds_min = min_downscale(&jpg, buf_size); /* check memory constraint */ | 1025 | ds_min = min_downscale(&jpg, buf_images_size); /* check memory constraint */ |
1026 | if (ds_min == 0) | 1026 | if (ds_min == 0) |
1027 | { | 1027 | { |
1028 | rb->splash(HZ, "too large"); | 1028 | rb->splash(HZ, "too large"); |
@@ -1155,8 +1155,6 @@ enum plugin_status plugin_start(const void* parameter) | |||
1155 | ARRAYLEN(jpeg_config), JPEG_SETTINGS_MINVERSION); | 1155 | ARRAYLEN(jpeg_config), JPEG_SETTINGS_MINVERSION); |
1156 | old_settings = jpeg_settings; | 1156 | old_settings = jpeg_settings; |
1157 | 1157 | ||
1158 | buf_images = buf; buf_images_size = buf_size; | ||
1159 | |||
1160 | /* Turn off backlight timeout */ | 1158 | /* Turn off backlight timeout */ |
1161 | backlight_force_on(); /* backlight control in lib/helper.c */ | 1159 | backlight_force_on(); /* backlight control in lib/helper.c */ |
1162 | 1160 | ||
diff --git a/apps/plugins/png/png.c b/apps/plugins/png/png.c index bda727a16d..4cbf74c71c 100644 --- a/apps/plugins/png/png.c +++ b/apps/plugins/png/png.c | |||
@@ -152,9 +152,8 @@ typedef struct LodePNG_Decoder | |||
152 | 152 | ||
153 | /* decompressed image in the possible sizes (1,2,4,8), wasting the other */ | 153 | /* decompressed image in the possible sizes (1,2,4,8), wasting the other */ |
154 | static fb_data *disp[9]; | 154 | static fb_data *disp[9]; |
155 | static fb_data *previous_disp; | 155 | /* up to here currently used by image(s) */ |
156 | static size_t size[9]; | 156 | static fb_data *disp_buf; |
157 | static size_t previous_size; | ||
158 | 157 | ||
159 | /* my memory pool (from the mp3 buffer) */ | 158 | /* my memory pool (from the mp3 buffer) */ |
160 | static char print[128]; /* use a common snprintf() buffer */ | 159 | static char print[128]; /* use a common snprintf() buffer */ |
@@ -1800,13 +1799,6 @@ fb_data *get_image(struct LodePNG_Decoder* decoder) | |||
1800 | return p_disp; /* we still have it */ | 1799 | return p_disp; /* we still have it */ |
1801 | } | 1800 | } |
1802 | 1801 | ||
1803 | if (previous_disp == NULL) { | ||
1804 | previous_disp = converted_image; | ||
1805 | previous_size = converted_image_size; | ||
1806 | } | ||
1807 | |||
1808 | size[ds] = (decoder->infoPng.width/ds) * (decoder->infoPng.height/ds); | ||
1809 | |||
1810 | /* assign image buffer */ | 1802 | /* assign image buffer */ |
1811 | if (ds > 1) { | 1803 | if (ds > 1) { |
1812 | if (!running_slideshow) | 1804 | if (!running_slideshow) |
@@ -1818,9 +1810,10 @@ fb_data *get_image(struct LodePNG_Decoder* decoder) | |||
1818 | } | 1810 | } |
1819 | static struct bitmap bmp_src, bmp_dst; | 1811 | static struct bitmap bmp_src, bmp_dst; |
1820 | 1812 | ||
1821 | disp[ds] = (fb_data *)((intptr_t)(previous_disp + previous_size + 3) & ~3); | 1813 | int size = (decoder->infoPng.width/ds) * (decoder->infoPng.height/ds); |
1814 | disp[ds] = disp_buf; | ||
1822 | 1815 | ||
1823 | if ((unsigned char *)(disp[ds] + size[ds]) >= memory_max) { | 1816 | if ((unsigned char *)(disp[ds] + size) >= memory_max) { |
1824 | //rb->splash(HZ, "Out of Memory"); | 1817 | //rb->splash(HZ, "Out of Memory"); |
1825 | // Still display the original image which is already decoded in RAM | 1818 | // Still display the original image which is already decoded in RAM |
1826 | disp[ds] = converted_image; | 1819 | disp[ds] = converted_image; |
@@ -1841,18 +1834,15 @@ fb_data *get_image(struct LodePNG_Decoder* decoder) | |||
1841 | #else | 1834 | #else |
1842 | smooth_resize_bitmap(&bmp_src, &bmp_dst); | 1835 | smooth_resize_bitmap(&bmp_src, &bmp_dst); |
1843 | #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ | 1836 | #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ |
1837 | |||
1838 | disp_buf = (fb_data *)((intptr_t)(disp[ds] + size + 3) & ~3); | ||
1844 | } | 1839 | } |
1845 | } else { | 1840 | } else { |
1846 | disp[ds] = converted_image; | 1841 | disp[ds] = converted_image; |
1847 | return converted_image; | 1842 | return converted_image; |
1848 | } | 1843 | } |
1849 | 1844 | ||
1850 | previous_disp = disp[ds]; | ||
1851 | previous_size = size[ds]; | ||
1852 | |||
1853 | return disp[ds]; | 1845 | return disp[ds]; |
1854 | |||
1855 | |||
1856 | } | 1846 | } |
1857 | 1847 | ||
1858 | /* load, decode, display the image */ | 1848 | /* load, decode, display the image */ |
@@ -1877,8 +1867,6 @@ int load_and_show(char* filename) | |||
1877 | } | 1867 | } |
1878 | image_size = rb->filesize(fd); | 1868 | image_size = rb->filesize(fd); |
1879 | memset(&disp, 0, sizeof(disp)); | 1869 | memset(&disp, 0, sizeof(disp)); |
1880 | previous_disp = NULL; | ||
1881 | previous_size = 0; | ||
1882 | 1870 | ||
1883 | DEBUGF("reading file '%s'\n", filename); | 1871 | DEBUGF("reading file '%s'\n", filename); |
1884 | 1872 | ||
@@ -1966,7 +1954,8 @@ int load_and_show(char* filename) | |||
1966 | LodePNG_decode(&decoder, image, image_size, cb_progress); | 1954 | LodePNG_decode(&decoder, image, image_size, cb_progress); |
1967 | #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ | 1955 | #endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ |
1968 | 1956 | ||
1969 | ds_min = min_downscale(&decoder, memory_max - (unsigned char*)(converted_image + converted_image_size)); /* check memory constraint */ | 1957 | disp_buf = (fb_data *)((intptr_t)(converted_image + converted_image_size + 3) & ~3); |
1958 | ds_min = min_downscale(&decoder, memory_max - (unsigned char*)disp_buf); /* check memory constraint */ | ||
1970 | 1959 | ||
1971 | if (ds_min == 0) { | 1960 | if (ds_min == 0) { |
1972 | // Could not resize the image | 1961 | // Could not resize the image |
@@ -1976,7 +1965,6 @@ int load_and_show(char* filename) | |||
1976 | } | 1965 | } |
1977 | 1966 | ||
1978 | if (decoder.error == PLUGIN_ABORT || decoder.error == FILE_TOO_LARGE) { | 1967 | if (decoder.error == PLUGIN_ABORT || decoder.error == FILE_TOO_LARGE) { |
1979 | rb->close(fd); | ||
1980 | #ifndef SIMULATOR | 1968 | #ifndef SIMULATOR |
1981 | if (immediate_ata_off) { | 1969 | if (immediate_ata_off) { |
1982 | /* running slideshow and time is long enough: power down disk */ | 1970 | /* running slideshow and time is long enough: power down disk */ |