summaryrefslogtreecommitdiff
path: root/apps/plugins/png/png.c
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2009-11-17 15:15:29 +0000
committerTeruaki Kawashima <teru@rockbox.org>2009-11-17 15:15:29 +0000
commitd1a3060dddac1a1744ed9973f1b87c1b3fe495f9 (patch)
tree57552d550067c6b6e61bfb493749e6f17d290a6e /apps/plugins/png/png.c
parentd66b9be85d3f848e7e69b1e374a2fecfe57e4428 (diff)
downloadrockbox-d1a3060dddac1a1744ed9973f1b87c1b3fe495f9.tar.gz
rockbox-d1a3060dddac1a1744ed9973f1b87c1b3fe495f9.zip
jpeg/png: refactor use of buf.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23655 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/png/png.c')
-rw-r--r--apps/plugins/png/png.c30
1 files changed, 9 insertions, 21 deletions
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 */
154static fb_data *disp[9]; 154static fb_data *disp[9];
155static fb_data *previous_disp; 155/* up to here currently used by image(s) */
156static size_t size[9]; 156static fb_data *disp_buf;
157static size_t previous_size;
158 157
159/* my memory pool (from the mp3 buffer) */ 158/* my memory pool (from the mp3 buffer) */
160static char print[128]; /* use a common snprintf() buffer */ 159static 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 */