summaryrefslogtreecommitdiff
path: root/apps/plugins/jpeg/jpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/jpeg/jpeg.c')
-rw-r--r--apps/plugins/jpeg/jpeg.c48
1 files changed, 23 insertions, 25 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) */
160static char print[32]; /* use a common snprintf() buffer */ 160static char print[32]; /* use a common snprintf() buffer */
161static 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 */
164static unsigned char* buf_images; 162static unsigned char* buf;
163static ssize_t buf_size;
165 164
166static 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 */
168static unsigned char* buf_root; 166static unsigned char* buf_root;
169static int root_size; 167static int root_size;
170 168
169/* up to here currently used by image(s) */
170static unsigned char* buf_images;
171static ssize_t buf_images_size;
172
171static int ds, ds_min, ds_max; /* downscaling and limits */ 173static int ds, ds_min, ds_max; /* downscaling and limits */
172static struct jpeg jpg; /* too large for stack */ 174static 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