in tjunittest.c [475:559]
static void _decompTest(tjhandle handle, unsigned char *jpegBuf,
size_t jpegSize, int w, int h, int pf, char *basename,
int subsamp, tjscalingfactor sf)
{
void *dstBuf = NULL;
unsigned char *yuvBuf = NULL;
int _hdrw = 0, _hdrh = 0, _hdrsubsamp;
int scaledWidth = TJSCALED(w, sf);
int scaledHeight = TJSCALED(h, sf);
size_t dstSize = 0;
int bottomUp = tj3Get(handle, TJPARAM_BOTTOMUP);
TRY_TJ(handle, tj3SetScalingFactor(handle, sf));
TRY_TJ(handle, tj3DecompressHeader(handle, jpegBuf, jpegSize));
_hdrw = tj3Get(handle, TJPARAM_JPEGWIDTH);
_hdrh = tj3Get(handle, TJPARAM_JPEGHEIGHT);
_hdrsubsamp = tj3Get(handle, TJPARAM_SUBSAMP);
if (lossless && subsamp != TJSAMP_444 && subsamp != TJSAMP_GRAY)
subsamp = TJSAMP_444;
if (_hdrw != w || _hdrh != h || _hdrsubsamp != subsamp)
THROW("Incorrect JPEG header");
dstSize = scaledWidth * scaledHeight * tjPixelSize[pf];
if ((dstBuf = malloc(dstSize * sampleSize)) == NULL)
THROW("Memory allocation failure");
memset(dstBuf, 0, dstSize * sampleSize);
if (doYUV) {
size_t yuvSize = tj3YUVBufSize(scaledWidth, yuvAlign, scaledHeight,
subsamp);
tjhandle handle2 = NULL;
if ((handle2 = tj3Init(TJINIT_DECOMPRESS)) == NULL)
THROW_TJ(NULL);
TRY_TJ(handle2, tj3Set(handle2, TJPARAM_BOTTOMUP, bottomUp));
TRY_TJ(handle2, tj3Set(handle2, TJPARAM_SUBSAMP, subsamp));
if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
THROW("Memory allocation failure");
memset(yuvBuf, 0, yuvSize);
printf("JPEG -> YUV %s ", subNameLong[subsamp]);
if (sf.num != 1 || sf.denom != 1)
printf("%d/%d ... ", sf.num, sf.denom);
else printf("... ");
TRY_TJ(handle, tj3DecompressToYUV8(handle, jpegBuf, jpegSize, yuvBuf,
yuvAlign));
if (checkBufYUV(yuvBuf, scaledWidth, scaledHeight, subsamp, sf))
printf("Passed.\n");
else printf("FAILED!\n");
printf("YUV %s -> %s %s ... ", subNameLong[subsamp], pixFormatStr[pf],
bottomUp ? "Bottom-Up" : "Top-Down ");
TRY_TJ(handle2, tj3DecodeYUV8(handle2, yuvBuf, yuvAlign,
(unsigned char *)dstBuf, scaledWidth, 0,
scaledHeight, pf));
tj3Destroy(handle2);
} else {
printf("JPEG -> %s %s ", pixFormatStr[pf],
bottomUp ? "Bottom-Up" : "Top-Down ");
if (sf.num != 1 || sf.denom != 1)
printf("%d/%d ... ", sf.num, sf.denom);
else printf("... ");
if (precision == 8) {
TRY_TJ(handle, tj3Decompress8(handle, jpegBuf, jpegSize,
(unsigned char *)dstBuf, 0, pf));
} else if (precision == 12) {
TRY_TJ(handle, tj3Decompress12(handle, jpegBuf, jpegSize,
(short *)dstBuf, 0, pf));
} else {
TRY_TJ(handle, tj3Decompress16(handle, jpegBuf, jpegSize,
(unsigned short *)dstBuf, 0, pf));
}
}
if (checkBuf(dstBuf, scaledWidth, scaledHeight, pf, subsamp, sf, bottomUp))
printf("Passed.");
else printf("FAILED!");
printf("\n");
bailout:
free(yuvBuf);
free(dstBuf);
}