jpeg/png: refactor use of buf.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23655 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
d66b9be85d
commit
d1a3060ddd
2 changed files with 32 additions and 46 deletions
|
@ -158,16 +158,18 @@ static struct t_disp disp[9];
|
|||
|
||||
/* my memory pool (from the mp3 buffer) */
|
||||
static char print[32]; /* use a common snprintf() buffer */
|
||||
static unsigned char* buf; /* up to here currently used by image(s) */
|
||||
|
||||
/* the remaining free part of the buffer for compressed+uncompressed images */
|
||||
static unsigned char* buf_images;
|
||||
static unsigned char* buf;
|
||||
static ssize_t buf_size;
|
||||
|
||||
static ssize_t buf_size, buf_images_size;
|
||||
/* the root of the images, hereafter are decompresed ones */
|
||||
static unsigned char* buf_root;
|
||||
static int root_size;
|
||||
|
||||
/* up to here currently used by image(s) */
|
||||
static unsigned char* buf_images;
|
||||
static ssize_t buf_images_size;
|
||||
|
||||
static int ds, ds_min, ds_max; /* downscaling and limits */
|
||||
static struct jpeg jpg; /* too large for stack */
|
||||
|
||||
|
@ -760,13 +762,13 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds)
|
|||
|
||||
/* physical size needed for decoding */
|
||||
size = jpegmem(p_jpg, ds);
|
||||
if (buf_size <= size)
|
||||
if (buf_images_size <= size)
|
||||
{ /* have to discard the current */
|
||||
int i;
|
||||
for (i=1; i<=8; i++)
|
||||
disp[i].bitmap[0] = NULL; /* invalidate all bitmaps */
|
||||
buf = buf_root; /* start again from the beginning of the buffer */
|
||||
buf_size = root_size;
|
||||
buf_images = buf_root; /* start again from the beginning of the buffer */
|
||||
buf_images_size = root_size;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LCD_COLOR
|
||||
|
@ -778,9 +780,9 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds)
|
|||
{
|
||||
size = (p_jpg->x_phys / ds / p_jpg->subsample_x[i])
|
||||
* (p_jpg->y_phys / ds / p_jpg->subsample_y[i]);
|
||||
p_disp->bitmap[i] = buf;
|
||||
buf += size;
|
||||
buf_size -= size;
|
||||
p_disp->bitmap[i] = buf_images;
|
||||
buf_images += size;
|
||||
buf_images_size -= size;
|
||||
}
|
||||
p_disp->csub_x = p_jpg->subsample_x[1];
|
||||
p_disp->csub_y = p_jpg->subsample_y[1];
|
||||
|
@ -788,14 +790,14 @@ struct t_disp* get_image(struct jpeg* p_jpg, int ds)
|
|||
else
|
||||
{
|
||||
p_disp->csub_x = p_disp->csub_y = 0;
|
||||
p_disp->bitmap[1] = p_disp->bitmap[2] = buf;
|
||||
p_disp->bitmap[1] = p_disp->bitmap[2] = buf_images;
|
||||
}
|
||||
#endif
|
||||
/* size may be less when decoded (if height is not block aligned) */
|
||||
size = (p_jpg->x_phys/ds) * (p_jpg->y_size / ds);
|
||||
p_disp->bitmap[0] = buf;
|
||||
buf += size;
|
||||
buf_size -= size;
|
||||
p_disp->bitmap[0] = buf_images;
|
||||
buf_images += size;
|
||||
buf_images_size -= size;
|
||||
|
||||
if(!running_slideshow)
|
||||
{
|
||||
|
@ -889,15 +891,14 @@ int load_and_show(char* filename)
|
|||
filesize = rb->filesize(fd);
|
||||
rb->memset(&disp, 0, sizeof(disp));
|
||||
|
||||
buf = buf_images + filesize;
|
||||
buf_size = buf_images_size - filesize;
|
||||
/* allocate JPEG buffer */
|
||||
buf_jpeg = buf_images;
|
||||
buf_jpeg = buf;
|
||||
|
||||
buf_root = buf; /* we can start the decompressed images behind it */
|
||||
root_size = buf_size;
|
||||
/* we can start the decompressed images behind it */
|
||||
buf_images = buf_root = buf + filesize;
|
||||
buf_images_size = root_size = buf_size - filesize;
|
||||
|
||||
if (buf_size <= 0)
|
||||
if (buf_images_size <= 0)
|
||||
{
|
||||
rb->close(fd);
|
||||
#if PLUGIN_BUFFER_SIZE >= MIN_MEM
|
||||
|
@ -924,8 +925,7 @@ int load_and_show(char* filename)
|
|||
{
|
||||
case JPEG_ZOOM_IN:
|
||||
plug_buf = false;
|
||||
buf_images = rb->plugin_get_audio_buffer(
|
||||
(size_t *)&buf_images_size);
|
||||
buf = rb->plugin_get_audio_buffer((size_t *)&buf_size);
|
||||
/*try again this file, now using the audio buffer */
|
||||
return PLUGIN_OTHER;
|
||||
#ifdef JPEG_RC_MENU
|
||||
|
@ -1022,7 +1022,7 @@ int load_and_show(char* filename)
|
|||
rb->lcd_update();
|
||||
}
|
||||
ds_max = max_downscale(&jpg); /* check display constraint */
|
||||
ds_min = min_downscale(&jpg, buf_size); /* check memory constraint */
|
||||
ds_min = min_downscale(&jpg, buf_images_size); /* check memory constraint */
|
||||
if (ds_min == 0)
|
||||
{
|
||||
rb->splash(HZ, "too large");
|
||||
|
@ -1155,8 +1155,6 @@ enum plugin_status plugin_start(const void* parameter)
|
|||
ARRAYLEN(jpeg_config), JPEG_SETTINGS_MINVERSION);
|
||||
old_settings = jpeg_settings;
|
||||
|
||||
buf_images = buf; buf_images_size = buf_size;
|
||||
|
||||
/* Turn off backlight timeout */
|
||||
backlight_force_on(); /* backlight control in lib/helper.c */
|
||||
|
||||
|
|
|
@ -152,9 +152,8 @@ typedef struct LodePNG_Decoder
|
|||
|
||||
/* decompressed image in the possible sizes (1,2,4,8), wasting the other */
|
||||
static fb_data *disp[9];
|
||||
static fb_data *previous_disp;
|
||||
static size_t size[9];
|
||||
static size_t previous_size;
|
||||
/* up to here currently used by image(s) */
|
||||
static fb_data *disp_buf;
|
||||
|
||||
/* my memory pool (from the mp3 buffer) */
|
||||
static char print[128]; /* use a common snprintf() buffer */
|
||||
|
@ -1800,13 +1799,6 @@ fb_data *get_image(struct LodePNG_Decoder* decoder)
|
|||
return p_disp; /* we still have it */
|
||||
}
|
||||
|
||||
if (previous_disp == NULL) {
|
||||
previous_disp = converted_image;
|
||||
previous_size = converted_image_size;
|
||||
}
|
||||
|
||||
size[ds] = (decoder->infoPng.width/ds) * (decoder->infoPng.height/ds);
|
||||
|
||||
/* assign image buffer */
|
||||
if (ds > 1) {
|
||||
if (!running_slideshow)
|
||||
|
@ -1818,9 +1810,10 @@ fb_data *get_image(struct LodePNG_Decoder* decoder)
|
|||
}
|
||||
static struct bitmap bmp_src, bmp_dst;
|
||||
|
||||
disp[ds] = (fb_data *)((intptr_t)(previous_disp + previous_size + 3) & ~3);
|
||||
int size = (decoder->infoPng.width/ds) * (decoder->infoPng.height/ds);
|
||||
disp[ds] = disp_buf;
|
||||
|
||||
if ((unsigned char *)(disp[ds] + size[ds]) >= memory_max) {
|
||||
if ((unsigned char *)(disp[ds] + size) >= memory_max) {
|
||||
//rb->splash(HZ, "Out of Memory");
|
||||
// Still display the original image which is already decoded in RAM
|
||||
disp[ds] = converted_image;
|
||||
|
@ -1841,18 +1834,15 @@ fb_data *get_image(struct LodePNG_Decoder* decoder)
|
|||
#else
|
||||
smooth_resize_bitmap(&bmp_src, &bmp_dst);
|
||||
#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
|
||||
|
||||
disp_buf = (fb_data *)((intptr_t)(disp[ds] + size + 3) & ~3);
|
||||
}
|
||||
} else {
|
||||
disp[ds] = converted_image;
|
||||
return converted_image;
|
||||
}
|
||||
|
||||
previous_disp = disp[ds];
|
||||
previous_size = size[ds];
|
||||
|
||||
return disp[ds];
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* load, decode, display the image */
|
||||
|
@ -1877,8 +1867,6 @@ int load_and_show(char* filename)
|
|||
}
|
||||
image_size = rb->filesize(fd);
|
||||
memset(&disp, 0, sizeof(disp));
|
||||
previous_disp = NULL;
|
||||
previous_size = 0;
|
||||
|
||||
DEBUGF("reading file '%s'\n", filename);
|
||||
|
||||
|
@ -1966,7 +1954,8 @@ int load_and_show(char* filename)
|
|||
LodePNG_decode(&decoder, image, image_size, cb_progress);
|
||||
#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
|
||||
|
||||
ds_min = min_downscale(&decoder, memory_max - (unsigned char*)(converted_image + converted_image_size)); /* check memory constraint */
|
||||
disp_buf = (fb_data *)((intptr_t)(converted_image + converted_image_size + 3) & ~3);
|
||||
ds_min = min_downscale(&decoder, memory_max - (unsigned char*)disp_buf); /* check memory constraint */
|
||||
|
||||
if (ds_min == 0) {
|
||||
// Could not resize the image
|
||||
|
@ -1976,7 +1965,6 @@ int load_and_show(char* filename)
|
|||
}
|
||||
|
||||
if (decoder.error == PLUGIN_ABORT || decoder.error == FILE_TOO_LARGE) {
|
||||
rb->close(fd);
|
||||
#ifndef SIMULATOR
|
||||
if (immediate_ata_off) {
|
||||
/* running slideshow and time is long enough: power down disk */
|
||||
|
|
Loading…
Reference in a new issue