When tjDecodeYUV() is used with a "fresh" decompressor instance (one that hasn't been previously used to decompress a JPEG image), then it needs comps_in_scan, data_precision, and the quantization tables to be defined. This patch also extends TJUnitTest to check for this error.
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1143 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
10
tjunittest.c
10
tjunittest.c
@@ -414,14 +414,17 @@ void compTest(tjhandle handle, unsigned char **dstBuf,
|
|||||||
{
|
{
|
||||||
unsigned long yuvSize=tjBufSizeYUV2(w, pad, h, subsamp);
|
unsigned long yuvSize=tjBufSizeYUV2(w, pad, h, subsamp);
|
||||||
tjscalingfactor sf={1, 1};
|
tjscalingfactor sf={1, 1};
|
||||||
|
tjhandle handle2=tjInitCompress();
|
||||||
|
if(!handle2) _throwtj();
|
||||||
|
|
||||||
if((yuvBuf=(unsigned char *)malloc(yuvSize))==NULL)
|
if((yuvBuf=(unsigned char *)malloc(yuvSize))==NULL)
|
||||||
_throw("Memory allocation failure");
|
_throw("Memory allocation failure");
|
||||||
memset(yuvBuf, 0, yuvSize);
|
memset(yuvBuf, 0, yuvSize);
|
||||||
|
|
||||||
printf("%s %s -> YUV %s ... ", pfStr, buStrLong, subNameLong[subsamp]);
|
printf("%s %s -> YUV %s ... ", pfStr, buStrLong, subNameLong[subsamp]);
|
||||||
_tj(tjEncodeYUV3(handle, srcBuf, w, 0, h, pf, yuvBuf, pad, subsamp,
|
_tj(tjEncodeYUV3(handle2, srcBuf, w, 0, h, pf, yuvBuf, pad, subsamp,
|
||||||
flags));
|
flags));
|
||||||
|
tjDestroy(handle2);
|
||||||
snprintf(tempStr, 1024, "%s_enc_%s_%s_%s.yuv", basename, pfStr, buStr,
|
snprintf(tempStr, 1024, "%s_enc_%s_%s_%s.yuv", basename, pfStr, buStr,
|
||||||
subName[subsamp]);
|
subName[subsamp]);
|
||||||
writeJPEG(yuvBuf, yuvSize, tempStr);
|
writeJPEG(yuvBuf, yuvSize, tempStr);
|
||||||
@@ -476,6 +479,8 @@ void _decompTest(tjhandle handle, unsigned char *jpegBuf,
|
|||||||
{
|
{
|
||||||
unsigned long yuvSize=tjBufSizeYUV2(scaledWidth, pad, scaledHeight,
|
unsigned long yuvSize=tjBufSizeYUV2(scaledWidth, pad, scaledHeight,
|
||||||
subsamp);
|
subsamp);
|
||||||
|
tjhandle handle2=tjInitDecompress();
|
||||||
|
if(!handle2) _throwtj();
|
||||||
|
|
||||||
if((yuvBuf=(unsigned char *)malloc(yuvSize))==NULL)
|
if((yuvBuf=(unsigned char *)malloc(yuvSize))==NULL)
|
||||||
_throw("Memory allocation failure");
|
_throw("Memory allocation failure");
|
||||||
@@ -493,8 +498,9 @@ void _decompTest(tjhandle handle, unsigned char *jpegBuf,
|
|||||||
|
|
||||||
printf("YUV %s -> %s %s ... ", subNameLong[subsamp], pixFormatStr[pf],
|
printf("YUV %s -> %s %s ... ", subNameLong[subsamp], pixFormatStr[pf],
|
||||||
(flags&TJFLAG_BOTTOMUP)? "Bottom-Up":"Top-Down ");
|
(flags&TJFLAG_BOTTOMUP)? "Bottom-Up":"Top-Down ");
|
||||||
_tj(tjDecodeYUV(handle, yuvBuf, pad, subsamp, dstBuf, scaledWidth, 0,
|
_tj(tjDecodeYUV(handle2, yuvBuf, pad, subsamp, dstBuf, scaledWidth, 0,
|
||||||
scaledHeight, pf, flags));
|
scaledHeight, pf, flags));
|
||||||
|
tjDestroy(handle2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
10
turbojpeg.c
10
turbojpeg.c
@@ -1242,12 +1242,12 @@ static int setDecodeDefaults(struct jpeg_decompress_struct *dinfo,
|
|||||||
|
|
||||||
if(subsamp==TJSAMP_GRAY)
|
if(subsamp==TJSAMP_GRAY)
|
||||||
{
|
{
|
||||||
dinfo->num_components=1;
|
dinfo->num_components=dinfo->comps_in_scan=1;
|
||||||
dinfo->jpeg_color_space=JCS_GRAYSCALE;
|
dinfo->jpeg_color_space=JCS_GRAYSCALE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dinfo->num_components=3;
|
dinfo->num_components=dinfo->comps_in_scan=3;
|
||||||
dinfo->jpeg_color_space=JCS_YCbCr;
|
dinfo->jpeg_color_space=JCS_YCbCr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1265,6 +1265,12 @@ static int setDecodeDefaults(struct jpeg_decompress_struct *dinfo,
|
|||||||
(i==0)? 0:1;
|
(i==0)? 0:1;
|
||||||
dinfo->cur_comp_info[i]=compptr;
|
dinfo->cur_comp_info[i]=compptr;
|
||||||
}
|
}
|
||||||
|
dinfo->data_precision=8;
|
||||||
|
for(i=0; i<2; i++)
|
||||||
|
{
|
||||||
|
if(dinfo->quant_tbl_ptrs[i]==NULL)
|
||||||
|
dinfo->quant_tbl_ptrs[i]=jpeg_alloc_quant_table((j_common_ptr)dinfo);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user