summaryrefslogtreecommitdiff
path: root/src/lib/emile
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-03-17 08:50:21 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-17 09:58:18 +0100
commit1a8384cd3c1b75eef39a3c03f6e3879b2e78f947 (patch)
tree50e7eb42ce21a66499aaa4f9d85da2f79408f3ba /src/lib/emile
parent1ab8cc75c4b85d3421ebfd34d04f2f4c01e99468 (diff)
emile: simplify error handling for jpeg data decoding.
Diffstat (limited to 'src/lib/emile')
-rw-r--r--src/lib/emile/emile_image.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/src/lib/emile/emile_image.c b/src/lib/emile/emile_image.c
index 9aa9a75653..ff5cff35e3 100644
--- a/src/lib/emile/emile_image.c
+++ b/src/lib/emile/emile_image.c
@@ -1367,19 +1367,15 @@ _emile_jpeg_data(Emile_Image *image,
1367 jerr.pub.output_message = _JPEGErrorHandler; 1367 jerr.pub.output_message = _JPEGErrorHandler;
1368 if (setjmp(jerr.setjmp_buffer)) 1368 if (setjmp(jerr.setjmp_buffer))
1369 { 1369 {
1370 jpeg_destroy_decompress(&cinfo);
1371 _emile_jpeg_membuf_src_term(&cinfo);
1372 *error = EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE; 1370 *error = EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE;
1373 return EINA_FALSE; 1371 goto on_error;
1374 } 1372 }
1375 jpeg_create_decompress(&cinfo); 1373 jpeg_create_decompress(&cinfo);
1376 1374
1377 if (_emile_jpeg_membuf_src(&cinfo, m, length)) 1375 if (_emile_jpeg_membuf_src(&cinfo, m, length))
1378 { 1376 {
1379 jpeg_destroy_decompress(&cinfo);
1380 _emile_jpeg_membuf_src_term(&cinfo);
1381 *error = EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 1377 *error = EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
1382 return 0; 1378 goto on_error;
1383 } 1379 }
1384 1380
1385 jpeg_read_header(&cinfo, TRUE); 1381 jpeg_read_header(&cinfo, TRUE);
@@ -1467,18 +1463,14 @@ _emile_jpeg_data(Emile_Image *image,
1467 { 1463 {
1468 // race condition, the file could have change from when we call header 1464 // race condition, the file could have change from when we call header
1469 // this test will not solve the problem with region code. 1465 // this test will not solve the problem with region code.
1470 jpeg_destroy_decompress(&cinfo);
1471 _emile_jpeg_membuf_src_term(&cinfo);
1472 *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; 1466 *error = EMILE_IMAGE_LOAD_ERROR_GENERIC;
1473 return EINA_FALSE; 1467 goto on_error;
1474 } 1468 }
1475 if ((region) && 1469 if ((region) &&
1476 ((ie_w != opts_region.w) || (ie_h != opts_region.h))) 1470 ((ie_w != opts_region.w) || (ie_h != opts_region.h)))
1477 { 1471 {
1478 jpeg_destroy_decompress(&cinfo);
1479 _emile_jpeg_membuf_src_term(&cinfo);
1480 *error = EMILE_IMAGE_LOAD_ERROR_GENERIC; 1472 *error = EMILE_IMAGE_LOAD_ERROR_GENERIC;
1481 return EINA_FALSE; 1473 goto on_error;
1482 /* ie_w = opts_region.w; */ 1474 /* ie_w = opts_region.w; */
1483 /* ie_h = opts_region.h; */ 1475 /* ie_h = opts_region.h; */
1484 /* if (change_wh) */ 1476 /* if (change_wh) */
@@ -1497,20 +1489,16 @@ _emile_jpeg_data(Emile_Image *image,
1497 ((cinfo.output_components == 3) || (cinfo.output_components == 1))) || 1489 ((cinfo.output_components == 3) || (cinfo.output_components == 1))) ||
1498 ((cinfo.out_color_space == JCS_CMYK) && (cinfo.output_components == 4)))) 1490 ((cinfo.out_color_space == JCS_CMYK) && (cinfo.output_components == 4))))
1499 { 1491 {
1500 jpeg_destroy_decompress(&cinfo);
1501 _emile_jpeg_membuf_src_term(&cinfo);
1502 *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT; 1492 *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT;
1503 return EINA_FALSE; 1493 goto on_error;
1504 } 1494 }
1505 1495
1506/* end head decoding */ 1496/* end head decoding */
1507/* data decoding */ 1497/* data decoding */
1508 if (cinfo.rec_outbuf_height > 16) 1498 if (cinfo.rec_outbuf_height > 16)
1509 { 1499 {
1510 jpeg_destroy_decompress(&cinfo);
1511 _emile_jpeg_membuf_src_term(&cinfo);
1512 *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT; 1500 *error = EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT;
1513 return EINA_FALSE; 1501 goto on_error;
1514 } 1502 }
1515 data = alloca(w * 16 * cinfo.output_components); 1503 data = alloca(w * 16 * cinfo.output_components);
1516 if ((prop->rotated) && change_wh) 1504 if ((prop->rotated) && change_wh)
@@ -1524,7 +1512,7 @@ _emile_jpeg_data(Emile_Image *image,
1524 if (!ptr2) 1512 if (!ptr2)
1525 { 1513 {
1526 *error = EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; 1514 *error = EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
1527 return EINA_FALSE; 1515 goto on_error;
1528 } 1516 }
1529 1517
1530 /* We handle first CMYK (4 components) */ 1518 /* We handle first CMYK (4 components) */
@@ -1843,10 +1831,8 @@ done:
1843 1831
1844 if (line_done) 1832 if (line_done)
1845 { 1833 {
1846 jpeg_destroy_decompress(&cinfo);
1847 _emile_jpeg_membuf_src_term(&cinfo);
1848 *error = EMILE_IMAGE_LOAD_ERROR_NONE; 1834 *error = EMILE_IMAGE_LOAD_ERROR_NONE;
1849 return EINA_FALSE; 1835 goto on_error;
1850 } 1836 }
1851 /* end data decoding */ 1837 /* end data decoding */
1852 jpeg_finish_decompress(&cinfo); 1838 jpeg_finish_decompress(&cinfo);
@@ -1854,6 +1840,11 @@ done:
1854 _emile_jpeg_membuf_src_term(&cinfo); 1840 _emile_jpeg_membuf_src_term(&cinfo);
1855 *error = EMILE_IMAGE_LOAD_ERROR_NONE; 1841 *error = EMILE_IMAGE_LOAD_ERROR_NONE;
1856 return EINA_TRUE; 1842 return EINA_TRUE;
1843
1844 on_error:
1845 jpeg_destroy_decompress(&cinfo);
1846 _emile_jpeg_membuf_src_term(&cinfo);
1847 return EINA_FALSE;
1857} 1848}
1858 1849
1859static void 1850static void