summaryrefslogtreecommitdiff
path: root/apps/plugins/imageviewer/png/png.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/imageviewer/png/png.c')
-rw-r--r--apps/plugins/imageviewer/png/png.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/apps/plugins/imageviewer/png/png.c b/apps/plugins/imageviewer/png/png.c
index d04b0850f4..958793b37d 100644
--- a/apps/plugins/imageviewer/png/png.c
+++ b/apps/plugins/imageviewer/png/png.c
@@ -144,7 +144,7 @@ static fb_data *disp[9];
144static fb_data *disp_buf; 144static fb_data *disp_buf;
145 145
146/* my memory pool (from the mp3 buffer) */ 146/* my memory pool (from the mp3 buffer) */
147static char print[128]; /* use a common snprintf() buffer */ 147static char print[32]; /* use a common snprintf() buffer */
148 148
149unsigned char *memory, *memory_max; /* inffast.c needs memory_max */ 149unsigned char *memory, *memory_max; /* inffast.c needs memory_max */
150static size_t memory_size; 150static size_t memory_size;
@@ -204,7 +204,6 @@ static unsigned LodePNG_decompress(unsigned char* out, size_t* outsize, const un
204 if (stream.msg != Z_NULL) 204 if (stream.msg != Z_NULL)
205 rb->strcpy(error_msg, stream.msg); 205 rb->strcpy(error_msg, stream.msg);
206 return err; 206 return err;
207
208} 207}
209 208
210/* ////////////////////////////////////////////////////////////////////////// */ 209/* ////////////////////////////////////////////////////////////////////////// */
@@ -469,8 +468,7 @@ unsigned LodePNG_convert(fb_data* out, const unsigned char* in, LodePNG_InfoColo
469 468
470 if (!running_slideshow) 469 if (!running_slideshow)
471 { 470 {
472 rb->snprintf(print, sizeof(print), "color conversion in progress"); 471 rb->lcd_puts(0, 3, "color conversion in progress");
473 rb->lcd_puts(0, 3, print);
474 rb->lcd_update(); 472 rb->lcd_update();
475 } 473 }
476 474
@@ -1201,8 +1199,7 @@ static void decodeGeneric(LodePNG_Decoder* decoder, unsigned char* in, size_t si
1201 memset(decoded_image, 0, decoded_image_size * sizeof(unsigned char)); 1199 memset(decoded_image, 0, decoded_image_size * sizeof(unsigned char));
1202 if (!running_slideshow) 1200 if (!running_slideshow)
1203 { 1201 {
1204 rb->snprintf(print, sizeof(print), "unfiltering scanlines"); 1202 rb->lcd_puts(0, 3, "unfiltering scanlines");
1205 rb->lcd_puts(0, 3, print);
1206 rb->lcd_update(); 1203 rb->lcd_update();
1207 } 1204 }
1208 decoder->error = postProcessScanlines(decoded_image, scanlines, decoder); 1205 decoder->error = postProcessScanlines(decoded_image, scanlines, decoder);
@@ -1217,7 +1214,7 @@ void LodePNG_decode(LodePNG_Decoder* decoder, unsigned char* in, size_t insize,
1217 1214
1218 /*TODO: check if this works according to the statement in the documentation: "The converter can convert from greyscale input color type, to 8-bit greyscale or greyscale with alpha"*/ 1215 /*TODO: check if this works according to the statement in the documentation: "The converter can convert from greyscale input color type, to 8-bit greyscale or greyscale with alpha"*/
1219 if (!(decoder->infoRaw.color.colorType == 2 || decoder->infoRaw.color.colorType == 6) && !(decoder->infoRaw.color.bitDepth == 8)) { decoder->error = 56; return; } 1216 if (!(decoder->infoRaw.color.colorType == 2 || decoder->infoRaw.color.colorType == 6) && !(decoder->infoRaw.color.bitDepth == 8)) { decoder->error = 56; return; }
1220 converted_image = (fb_data *)((intptr_t)(memory + 3) & ~3); 1217 converted_image = (fb_data *)memory;
1221 converted_image_size = decoder->infoPng.width*decoder->infoPng.height; 1218 converted_image_size = decoder->infoPng.width*decoder->infoPng.height;
1222 if ((unsigned char *)(converted_image + converted_image_size) >= decoded_image) { decoder->error = OUT_OF_MEMORY; } 1219 if ((unsigned char *)(converted_image + converted_image_size) >= decoded_image) { decoder->error = OUT_OF_MEMORY; }
1223 if (!decoder->error) decoder->error = LodePNG_convert(converted_image, decoded_image, &decoder->infoRaw.color, &decoder->infoPng.color, decoder->infoPng.width, decoder->infoPng.height); 1220 if (!decoder->error) decoder->error = LodePNG_convert(converted_image, decoded_image, &decoder->infoRaw.color, &decoder->infoPng.color, decoder->infoPng.width, decoder->infoPng.height);
@@ -1333,9 +1330,10 @@ int load_image(char *filename, struct image_info *info,
1333 memset(&disp, 0, sizeof(disp)); 1330 memset(&disp, 0, sizeof(disp));
1334 LodePNG_Decoder_init(decoder); 1331 LodePNG_Decoder_init(decoder);
1335 1332
1336 memory = buf; 1333 /* align buffer */
1337 memory_size = *buf_size; 1334 memory = (unsigned char *)((intptr_t)(buf + 3) & ~3);
1338 memory_max = memory + memory_size; 1335 memory_max = (unsigned char *)((intptr_t)(memory + *buf_size) & ~3);
1336 memory_size = memory_max - memory;
1339 1337
1340 fd = rb->open(filename, O_RDONLY); 1338 fd = rb->open(filename, O_RDONLY);
1341 if (fd < 0) 1339 if (fd < 0)
@@ -1348,8 +1346,7 @@ int load_image(char *filename, struct image_info *info,
1348 DEBUGF("reading file '%s'\n", filename); 1346 DEBUGF("reading file '%s'\n", filename);
1349 1347
1350 if (!running_slideshow) { 1348 if (!running_slideshow) {
1351 rb->snprintf(print, sizeof(print), "%s:", rb->strrchr(filename,'/')+1); 1349 rb->lcd_puts(0, 0, rb->strrchr(filename,'/')+1);
1352 rb->lcd_puts(0, 0, print);
1353 rb->lcd_update(); 1350 rb->lcd_update();
1354 } 1351 }
1355 1352
@@ -1369,8 +1366,7 @@ int load_image(char *filename, struct image_info *info,
1369 rb->close(fd); 1366 rb->close(fd);
1370 1367
1371 if (!running_slideshow) { 1368 if (!running_slideshow) {
1372 rb->snprintf(print, sizeof(print), "decoding image"); 1369 rb->lcd_puts(0, 2, "decoding image");
1373 rb->lcd_puts(0, 2, print);
1374 rb->lcd_update(); 1370 rb->lcd_update();
1375 } 1371 }
1376#ifdef DISK_SPINDOWN 1372#ifdef DISK_SPINDOWN
@@ -1409,11 +1405,10 @@ int load_image(char *filename, struct image_info *info,
1409#else 1405#else
1410 LodePNG_decode(decoder, image, image_size, cb_progress); 1406 LodePNG_decode(decoder, image, image_size, cb_progress);
1411#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/ 1407#endif /*HAVE_ADJUSTABLE_CPU_FREQ*/
1408 time = *rb->current_tick - time;
1412 } 1409 }
1413 } 1410 }
1414 1411
1415 time = *rb->current_tick - time;
1416
1417 if (!running_slideshow && !decoder->error) 1412 if (!running_slideshow && !decoder->error)
1418 { 1413 {
1419 rb->snprintf(print, sizeof(print), " %ld.%02ld sec ", time/HZ, time%HZ); 1414 rb->snprintf(print, sizeof(print), " %ld.%02ld sec ", time/HZ, time%HZ);
@@ -1423,7 +1418,7 @@ int load_image(char *filename, struct image_info *info,
1423 } 1418 }
1424 1419
1425 if (decoder->error) { 1420 if (decoder->error) {
1426#if PLUGIN_BUFFER_SIZE >= MIN_MEM 1421#ifdef USE_PLUG_BUF
1427 if (plug_buf && (decoder->error == FILE_TOO_LARGE 1422 if (plug_buf && (decoder->error == FILE_TOO_LARGE
1428 || decoder->error == OUT_OF_MEMORY || decoder->error == Z_MEM_ERROR)) 1423 || decoder->error == OUT_OF_MEMORY || decoder->error == Z_MEM_ERROR))
1429 return PLUGIN_OUTOFMEM; 1424 return PLUGIN_OUTOFMEM;
@@ -1457,7 +1452,7 @@ int load_image(char *filename, struct image_info *info,
1457 return PLUGIN_ERROR; 1452 return PLUGIN_ERROR;
1458 } 1453 }
1459 1454
1460 disp_buf = (fb_data *)((intptr_t)(converted_image + converted_image_size + 3) & ~3); 1455 disp_buf = converted_image + converted_image_size;
1461 info->x_size = decoder->infoPng.width; 1456 info->x_size = decoder->infoPng.width;
1462 info->y_size = decoder->infoPng.height; 1457 info->y_size = decoder->infoPng.height;
1463 *buf_size = memory_max - (unsigned char*)disp_buf; 1458 *buf_size = memory_max - (unsigned char*)disp_buf;
@@ -1498,11 +1493,11 @@ int get_image(struct image_info *info, int ds)
1498 for (i=1; i<=8; i++) 1493 for (i=1; i<=8; i++)
1499 disp[i] = NULL; /* invalidate all bitmaps */ 1494 disp[i] = NULL; /* invalidate all bitmaps */
1500 /* start again from the beginning of the buffer */ 1495 /* start again from the beginning of the buffer */
1501 disp_buf = (fb_data *)((intptr_t)(converted_image + converted_image_size + 3) & ~3); 1496 disp_buf = converted_image + converted_image_size;
1502 } 1497 }
1503 1498
1504 *p_disp = disp_buf; 1499 *p_disp = disp_buf;
1505 disp_buf = (fb_data *)((intptr_t)(disp_buf + size + 3) & ~3); 1500 disp_buf += size;
1506 1501
1507 bmp_src.width = decoder->infoPng.width; 1502 bmp_src.width = decoder->infoPng.width;
1508 bmp_src.height = decoder->infoPng.height; 1503 bmp_src.height = decoder->infoPng.height;