diff options
Diffstat (limited to 'turbojpeg.c')
-rw-r--r-- | turbojpeg.c | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/turbojpeg.c b/turbojpeg.c index 6533b41..662c68f 100644 --- a/turbojpeg.c +++ b/turbojpeg.c @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2016 D. R. Commander. All Rights Reserved. + * Copyright (C)2009-2017 D. R. Commander. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -222,7 +222,7 @@ static int setCompDefaults(struct jpeg_compress_struct *cinfo, #ifndef NO_GETENV if((env=getenv("TJ_OPTIMIZE"))!=NULL && strlen(env)>0 && !strcmp(env, "1")) cinfo->optimize_coding=TRUE; - if((env=getenv("TJ_ARITHMETIC"))!=NULL && strlen(env)>0 && !strcmp(env, "1")) + if((env=getenv("TJ_ARITHMETIC"))!=NULL && strlen(env)>0 && !strcmp(env, "1")) cinfo->arith_code=TRUE; if((env=getenv("TJ_RESTART"))!=NULL && strlen(env)>0) { @@ -772,13 +772,6 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf, || jpegSubsamp<0 || jpegSubsamp>=NUMSUBOPT || jpegQual<0 || jpegQual>100) _throw("tjCompress2(): Invalid argument"); - if(setjmp(this->jerr.setjmp_buffer)) - { - /* If we get here, the JPEG code has signaled an error. */ - retval=-1; - goto bailout; - } - if(pitch==0) pitch=width*tjPixelSize[pixelFormat]; #ifndef JCS_EXTENSIONS @@ -791,6 +784,15 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf, } #endif + if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) + _throw("tjCompress2(): Memory allocation failure"); + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; goto bailout; + } + cinfo->image_width=width; cinfo->image_height=height; @@ -807,8 +809,6 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf, return -1; jpeg_start_compress(cinfo, TRUE); - if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL) - _throw("tjCompress2(): Memory allocation failure"); for(i=0; i<height; i++) { if(flags&TJFLAG_BOTTOMUP) @@ -888,13 +888,6 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, if(subsamp!=TJSAMP_GRAY && (!dstPlanes[1] || !dstPlanes[2])) _throw("tjEncodeYUVPlanes(): Invalid argument"); - if(setjmp(this->jerr.setjmp_buffer)) - { - /* If we get here, the JPEG code has signaled an error. */ - retval=-1; - goto bailout; - } - if(pixelFormat==TJPF_CMYK) _throw("tjEncodeYUVPlanes(): Cannot generate YUV images from CMYK pixels"); @@ -910,6 +903,12 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, } #endif + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; goto bailout; + } + cinfo->image_width=width; cinfo->image_height=height; @@ -986,6 +985,12 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, } } + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; goto bailout; + } + for(row=0; row<ph0; row+=cinfo->max_v_samp_factor) { (*cinfo->cconvert->color_convert)(cinfo, &row_pointer[row], tmpbuf, 0, @@ -1100,8 +1105,7 @@ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle, if(setjmp(this->jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. */ - retval=-1; - goto bailout; + retval=-1; goto bailout; } cinfo->image_width=width; @@ -1160,6 +1164,12 @@ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle, } } + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; goto bailout; + } + for(row=0; row<(int)cinfo->image_height; row+=cinfo->max_v_samp_factor*DCTSIZE) { @@ -1389,8 +1399,7 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, if(setjmp(this->jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. */ - retval=-1; - goto bailout; + retval=-1; goto bailout; } jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); @@ -1438,6 +1447,11 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW) *dinfo->output_height))==NULL) _throw("tjDecompress2(): Memory allocation failure"); + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; goto bailout; + } for(i=0; i<(int)dinfo->output_height; i++) { if(flags&TJFLAG_BOTTOMUP) @@ -1568,8 +1582,7 @@ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle, if(setjmp(this->jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. */ - retval=-1; - goto bailout; + retval=-1; goto bailout; } if(pixelFormat==TJPF_CMYK) @@ -1660,6 +1673,12 @@ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle, } } + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; goto bailout; + } + for(row=0; row<ph0; row+=dinfo->max_v_samp_factor) { JDIMENSION inrow=0, outrow=0; @@ -1761,8 +1780,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, if(setjmp(this->jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. */ - retval=-1; - goto bailout; + retval=-1; goto bailout; } if(!this->headerRead) @@ -1840,6 +1858,12 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, } } + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; goto bailout; + } + if(flags&TJFLAG_FASTUPSAMPLE) dinfo->do_fancy_upsampling=FALSE; if(flags&TJFLAG_FASTDCT) dinfo->dct_method=JDCT_FASTEST; dinfo->raw_data_out=TRUE; @@ -2017,20 +2041,19 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle handle, else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); + if((xinfo=(jpeg_transform_info *)malloc(sizeof(jpeg_transform_info)*n)) + ==NULL) + _throw("tjTransform(): Memory allocation failure"); + MEMZERO(xinfo, sizeof(jpeg_transform_info)*n); + if(setjmp(this->jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. */ - retval=-1; - goto bailout; + retval=-1; goto bailout; } jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - if((xinfo=(jpeg_transform_info *)malloc(sizeof(jpeg_transform_info)*n)) - ==NULL) - _throw("tjTransform(): Memory allocation failure"); - MEMZERO(xinfo, sizeof(jpeg_transform_info)*n); - for(i=0; i<n; i++) { xinfo[i].transform=xformtypes[t[i].op]; |