Fix crashes and bogus output in the CMYK and decode-to-YUV features that occurred if JCS_EXTENSIONS wasn't defined.
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1260 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
36
turbojpeg.c
36
turbojpeg.c
@@ -634,7 +634,7 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf,
|
|||||||
if(pitch==0) pitch=width*tjPixelSize[pixelFormat];
|
if(pitch==0) pitch=width*tjPixelSize[pixelFormat];
|
||||||
|
|
||||||
#ifndef JCS_EXTENSIONS
|
#ifndef JCS_EXTENSIONS
|
||||||
if(pixelFormat!=TJPF_GRAY)
|
if(pixelFormat!=TJPF_GRAY && pixelFormat!=TJPF_CMYK)
|
||||||
{
|
{
|
||||||
rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE);
|
rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE);
|
||||||
if(!rgbBuf) _throw("tjCompress2(): Memory allocation failure");
|
if(!rgbBuf) _throw("tjCompress2(): Memory allocation failure");
|
||||||
@@ -749,7 +749,7 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, unsigned char *srcBuf,
|
|||||||
if(pitch==0) pitch=width*tjPixelSize[pixelFormat];
|
if(pitch==0) pitch=width*tjPixelSize[pixelFormat];
|
||||||
|
|
||||||
#ifndef JCS_EXTENSIONS
|
#ifndef JCS_EXTENSIONS
|
||||||
if(pixelFormat!=TJPF_GRAY)
|
if(pixelFormat!=TJPF_GRAY && pixelFormat!=TJPF_CMYK)
|
||||||
{
|
{
|
||||||
rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE);
|
rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE);
|
||||||
if(!rgbBuf) _throw("tjEncodeYUV3(): Memory allocation failure");
|
if(!rgbBuf) _throw("tjEncodeYUV3(): Memory allocation failure");
|
||||||
@@ -1189,7 +1189,7 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, unsigned char *jpegBuf,
|
|||||||
if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat];
|
if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat];
|
||||||
|
|
||||||
#ifndef JCS_EXTENSIONS
|
#ifndef JCS_EXTENSIONS
|
||||||
if(pixelFormat!=TJPF_GRAY &&
|
if(pixelFormat!=TJPF_GRAY && pixelFormat!=TJPF_CMYK &&
|
||||||
(RGB_RED!=tjRedOffset[pixelFormat] ||
|
(RGB_RED!=tjRedOffset[pixelFormat] ||
|
||||||
RGB_GREEN!=tjGreenOffset[pixelFormat] ||
|
RGB_GREEN!=tjGreenOffset[pixelFormat] ||
|
||||||
RGB_BLUE!=tjBlueOffset[pixelFormat] ||
|
RGB_BLUE!=tjBlueOffset[pixelFormat] ||
|
||||||
@@ -1309,6 +1309,7 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf,
|
|||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
#ifndef JCS_EXTENSIONS
|
#ifndef JCS_EXTENSIONS
|
||||||
unsigned char *rgbBuf=NULL;
|
unsigned char *rgbBuf=NULL;
|
||||||
|
unsigned char *_dstBuf=NULL; int _pitch=0;
|
||||||
#endif
|
#endif
|
||||||
JMETHOD(int, old_read_markers, (j_decompress_ptr));
|
JMETHOD(int, old_read_markers, (j_decompress_ptr));
|
||||||
JMETHOD(void, old_reset_marker_reader, (j_decompress_ptr));
|
JMETHOD(void, old_reset_marker_reader, (j_decompress_ptr));
|
||||||
@@ -1339,17 +1340,6 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf,
|
|||||||
_throw("tjDecodeYUV(): Cannot decode YUV images into CMYK pixels.");
|
_throw("tjDecodeYUV(): Cannot decode YUV images into CMYK pixels.");
|
||||||
|
|
||||||
if(pitch==0) pitch=width*tjPixelSize[pixelFormat];
|
if(pitch==0) pitch=width*tjPixelSize[pixelFormat];
|
||||||
|
|
||||||
#ifndef JCS_EXTENSIONS
|
|
||||||
if(pixelFormat!=TJPF_GRAY)
|
|
||||||
{
|
|
||||||
rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE);
|
|
||||||
if(!rgbBuf) _throw("tjDecodeYUV(): Memory allocation failure");
|
|
||||||
srcBuf=toRGB(srcBuf, width, pitch, height, pixelFormat, rgbBuf);
|
|
||||||
pitch=width*RGB_PIXELSIZE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
dinfo->image_width=width;
|
dinfo->image_width=width;
|
||||||
dinfo->image_height=height;
|
dinfo->image_height=height;
|
||||||
|
|
||||||
@@ -1383,6 +1373,20 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf,
|
|||||||
|
|
||||||
if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat];
|
if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat];
|
||||||
|
|
||||||
|
#ifndef JCS_EXTENSIONS
|
||||||
|
if(pixelFormat!=TJPF_GRAY && pixelFormat!=TJPF_CMYK &&
|
||||||
|
(RGB_RED!=tjRedOffset[pixelFormat] ||
|
||||||
|
RGB_GREEN!=tjGreenOffset[pixelFormat] ||
|
||||||
|
RGB_BLUE!=tjBlueOffset[pixelFormat] ||
|
||||||
|
RGB_PIXELSIZE!=tjPixelSize[pixelFormat]))
|
||||||
|
{
|
||||||
|
rgbBuf=(unsigned char *)malloc(width*height*3);
|
||||||
|
if(!rgbBuf) _throw("tjDecodeYUV(): Memory allocation failure");
|
||||||
|
_pitch=pitch; pitch=width*3;
|
||||||
|
_dstBuf=dstBuf; dstBuf=rgbBuf;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL)
|
if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL)
|
||||||
_throw("tjDecodeYUV(): Memory allocation failure");
|
_throw("tjDecodeYUV(): Memory allocation failure");
|
||||||
for(i=0; i<height; i++)
|
for(i=0; i<height; i++)
|
||||||
@@ -1435,6 +1439,10 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf,
|
|||||||
}
|
}
|
||||||
jpeg_abort_decompress(dinfo);
|
jpeg_abort_decompress(dinfo);
|
||||||
|
|
||||||
|
#ifndef JCS_EXTENSIONS
|
||||||
|
fromRGB(rgbBuf, _dstBuf, width, _pitch, height, pixelFormat);
|
||||||
|
#endif
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo);
|
if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo);
|
||||||
#ifndef JCS_EXTENSIONS
|
#ifndef JCS_EXTENSIONS
|
||||||
|
|||||||
Reference in New Issue
Block a user