summaryrefslogtreecommitdiff
path: root/tjbench.c
diff options
context:
space:
mode:
authorJonathan Wright <jonathan.wright@arm.com>2020-08-05 11:42:22 +0100
committerJonathan Wright <jonathan.wright@arm.com>2020-08-07 17:04:34 +0100
commitdb870dfef8ab97950b4bdf22c66dd6c18326460b (patch)
tree9862c1aa45d014815ec798992ecb43eff1bc8d42 /tjbench.c
parent341272d909285da90e44015ca41f956fd00b9dd8 (diff)
Update libjpeg-turbo to v2.0.5
Update Chromium's copy of libjpeg-turbo to the latest stable upstream release (v2.0.5) and reapply our local changes documented in README.chromium. This update addresses three CVEs - CVE-2018-19664, CVE-2018-20330, CVE-2018-20330 - that do not affect Chromium. The fixes do, however, satisfy UBSan - allowing Chromium's libjpeg-turbo to be used in AOSP. Cherry-pick one additional change[1] from upstream to prevent AArch64 Windows builds from failing. [1] https://github.com/libjpeg-turbo/libjpeg-turbo/commit/6ee5d5f568fda1a7c6a49dd8995f2d89866ee42d Bug: 922430 Bug: https://issuetracker.google.com/135180511 Change-Id: I146fe82f7a016ce393eb0d37aebe0b7c2492a9da
Diffstat (limited to 'tjbench.c')
-rw-r--r--tjbench.c215
1 files changed, 114 insertions, 101 deletions
diff --git a/tjbench.c b/tjbench.c
index f555fae..e098f3b 100644
--- a/tjbench.c
+++ b/tjbench.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C)2009-2018 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2009-2019 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:
@@ -32,28 +32,29 @@
#include <ctype.h>
#include <math.h>
#include <errno.h>
+#include <limits.h>
#include <cdjpeg.h>
#include "./tjutil.h"
#include "./turbojpeg.h"
-#define _throw(op, err) { \
+#define THROW(op, err) { \
fprintf(stderr, "ERROR in line %d while %s:\n%s\n", __LINE__, op, err); \
retval = -1; goto bailout; \
}
-#define _throwunix(m) _throw(m, strerror(errno))
+#define THROW_UNIX(m) THROW(m, strerror(errno))
static char tjErrorStr[JMSG_LENGTH_MAX] = "\0",
tjErrorMsg[JMSG_LENGTH_MAX] = "\0";
static int tjErrorLine = -1, tjErrorCode = -1;
-#define _throwtjg(m) { \
+#define THROW_TJG(m) { \
fprintf(stderr, "ERROR in line %d while %s:\n%s\n", __LINE__, m, \
tjGetErrorStr2(NULL)); \
retval = -1; goto bailout; \
}
-#define _throwtj(m) { \
+#define THROW_TJ(m) { \
int _tjErrorCode = tjGetErrorCode(handle); \
char *_tjErrorStr = tjGetErrorStr2(handle); \
\
@@ -143,7 +144,7 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
int subsamp, int jpegQual, char *fileName, int tilew,
int tileh)
{
- char tempStr[1024], sizeStr[20] = "\0", qualStr[6] = "\0", *ptr;
+ char tempStr[1024], sizeStr[24] = "\0", qualStr[13] = "\0", *ptr;
FILE *file = NULL;
tjhandle handle = NULL;
int row, col, iter = 0, dstBufAlloc = 0, retval = 0;
@@ -156,29 +157,34 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
if (jpegQual > 0) {
- snprintf(qualStr, 6, "_Q%d", jpegQual);
- qualStr[5] = 0;
+ snprintf(qualStr, 13, "_Q%d", jpegQual);
+ qualStr[12] = 0;
}
if ((handle = tjInitDecompress()) == NULL)
- _throwtj("executing tjInitDecompress()");
+ THROW_TJ("executing tjInitDecompress()");
if (dstBuf == NULL) {
- if ((dstBuf = (unsigned char *)malloc(pitch * scaledh)) == NULL)
- _throwunix("allocating destination buffer");
+ if ((unsigned long long)pitch * (unsigned long long)scaledh >
+ (unsigned long long)((size_t)-1))
+ THROW("allocating destination buffer", "Image is too large");
+ if ((dstBuf = (unsigned char *)malloc((size_t)pitch * scaledh)) == NULL)
+ THROW_UNIX("allocating destination buffer");
dstBufAlloc = 1;
}
/* Set the destination buffer to gray so we know whether the decompressor
attempted to write to it */
- memset(dstBuf, 127, pitch * scaledh);
+ memset(dstBuf, 127, (size_t)pitch * scaledh);
if (doYUV) {
int width = doTile ? tilew : scaledw;
int height = doTile ? tileh : scaledh;
- int yuvSize = tjBufSizeYUV2(width, yuvPad, height, subsamp);
+ unsigned long yuvSize = tjBufSizeYUV2(width, yuvPad, height, subsamp);
+ if (yuvSize == (unsigned long)-1)
+ THROW_TJ("allocating YUV buffer");
if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
- _throwunix("allocating YUV buffer");
+ THROW_UNIX("allocating YUV buffer");
memset(yuvBuf, 127, yuvSize);
}
@@ -190,7 +196,7 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
double start = getTime();
for (row = 0, dstPtr = dstBuf; row < ntilesh;
- row++, dstPtr += pitch * tileh) {
+ row++, dstPtr += (size_t)pitch * tileh) {
for (col = 0, dstPtr2 = dstPtr; col < ntilesw;
col++, tile++, dstPtr2 += ps * tilew) {
int width = doTile ? min(tilew, w - col * tilew) : scaledw;
@@ -201,16 +207,16 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
if (tjDecompressToYUV2(handle, jpegBuf[tile], jpegSize[tile], yuvBuf,
width, yuvPad, height, flags) == -1)
- _throwtj("executing tjDecompressToYUV2()");
+ THROW_TJ("executing tjDecompressToYUV2()");
startDecode = getTime();
if (tjDecodeYUV(handle, yuvBuf, yuvPad, subsamp, dstPtr2, width,
pitch, height, pf, flags) == -1)
- _throwtj("executing tjDecodeYUV()");
+ THROW_TJ("executing tjDecodeYUV()");
if (iter >= 0) elapsedDecode += getTime() - startDecode;
} else if (tjDecompress2(handle, jpegBuf[tile], jpegSize[tile],
dstPtr2, width, pitch, height, pf,
flags) == -1)
- _throwtj("executing tjDecompress2()");
+ THROW_TJ("executing tjDecompress2()");
}
}
elapsed += getTime() - start;
@@ -224,14 +230,14 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
}
if (doYUV) elapsed -= elapsedDecode;
- if (tjDestroy(handle) == -1) _throwtj("executing tjDestroy()");
+ if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
handle = NULL;
if (quiet) {
fprintf(stderr, "%-6s%s",
sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
tempStr, 1024),
- quiet == 2 ? "\n" : " ");
+ quiet == 2 ? "\n" : " ");
if (doYUV)
fprintf(stderr, "%s\n",
sigfig((double)(w * h) / 1000000. * (double)iter / elapsedDecode,
@@ -248,17 +254,17 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
(double)iter / elapsedDecode);
fprintf(stderr,
" Throughput: %f Megapixels/sec\n",
- (double)(w * h) / 1000000. * (double)iter / elapsedDecode);
+ (double)(w * h) / 1000000. * (double)iter / elapsedDecode);
}
}
if (!doWrite) goto bailout;
if (sf.num != 1 || sf.denom != 1)
- snprintf(sizeStr, 20, "%d_%d", sf.num, sf.denom);
+ snprintf(sizeStr, 24, "%d_%d", sf.num, sf.denom);
else if (tilew != w || tileh != h)
- snprintf(sizeStr, 20, "%dx%d", tilew, tileh);
- else snprintf(sizeStr, 20, "full");
+ snprintf(sizeStr, 24, "%dx%d", tilew, tileh);
+ else snprintf(sizeStr, 24, "full");
if (decompOnly)
snprintf(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
else
@@ -266,19 +272,19 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
qualStr, sizeStr, ext);
if (tjSaveImage(tempStr, dstBuf, scaledw, 0, scaledh, pf, flags) == -1)
- _throwtjg("saving bitmap");
+ THROW_TJG("saving bitmap");
ptr = strrchr(tempStr, '.');
snprintf(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
if (srcBuf && sf.num == 1 && sf.denom == 1) {
if (!quiet) fprintf(stderr, "Compression error written to %s.\n", tempStr);
if (subsamp == TJ_GRAYSCALE) {
- int index, index2;
+ unsigned long index, index2;
for (row = 0, index = 0; row < h; row++, index += pitch) {
for (col = 0, index2 = index; col < w; col++, index2 += ps) {
- int rindex = index2 + tjRedOffset[pf];
- int gindex = index2 + tjGreenOffset[pf];
- int bindex = index2 + tjBlueOffset[pf];
+ unsigned long rindex = index2 + tjRedOffset[pf];
+ unsigned long gindex = index2 + tjGreenOffset[pf];
+ unsigned long bindex = index2 + tjBlueOffset[pf];
int y = (int)((double)srcBuf[rindex] * 0.299 +
(double)srcBuf[gindex] * 0.587 +
(double)srcBuf[bindex] * 0.114 + 0.5);
@@ -297,14 +303,14 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
abs(dstBuf[pitch * row + col] - srcBuf[pitch * row + col]);
}
if (tjSaveImage(tempStr, dstBuf, w, 0, h, pf, flags) == -1)
- _throwtjg("saving bitmap");
+ THROW_TJG("saving bitmap");
}
bailout:
if (file) fclose(file);
if (handle) tjDestroy(handle);
- if (dstBuf && dstBufAlloc) free(dstBuf);
- if (yuvBuf) free(yuvBuf);
+ if (dstBufAlloc) free(dstBuf);
+ free(yuvBuf);
return retval;
}
@@ -319,14 +325,17 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
*srcPtr2;
double start, elapsed, elapsedEncode;
int totalJpegSize = 0, row, col, i, tilew = w, tileh = h, retval = 0;
- int iter, yuvSize = 0;
- unsigned long *jpegSize = NULL;
+ int iter;
+ unsigned long *jpegSize = NULL, yuvSize = 0;
int ps = tjPixelSize[pf];
int ntilesw = 1, ntilesh = 1, pitch = w * ps;
const char *pfStr = pixFormatStr[pf];
- if ((tmpBuf = (unsigned char *)malloc(pitch * h)) == NULL)
- _throwunix("allocating temporary image buffer");
+ if ((unsigned long long)pitch * (unsigned long long)h >
+ (unsigned long long)((size_t)-1))
+ THROW("allocating temporary image buffer", "Image is too large");
+ if ((tmpBuf = (unsigned char *)malloc((size_t)pitch * h)) == NULL)
+ THROW_UNIX("allocating temporary image buffer");
if (!quiet)
fprintf(stderr, ">>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", pfStr,
@@ -342,18 +351,20 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
ntilesw * ntilesh)) == NULL)
- _throwunix("allocating JPEG tile array");
+ THROW_UNIX("allocating JPEG tile array");
memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
ntilesw * ntilesh)) == NULL)
- _throwunix("allocating JPEG size array");
+ THROW_UNIX("allocating JPEG size array");
memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
if ((flags & TJFLAG_NOREALLOC) != 0)
for (i = 0; i < ntilesw * ntilesh; i++) {
+ if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
+ THROW("getting buffer size", "Image is too large");
if ((jpegBuf[i] = (unsigned char *)
tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
- _throwunix("allocating JPEG tiles");
+ THROW_UNIX("allocating JPEG tiles");
}
/* Compression test */
@@ -364,12 +375,14 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
for (i = 0; i < h; i++)
memcpy(&tmpBuf[pitch * i], &srcBuf[w * ps * i], w * ps);
if ((handle = tjInitCompress()) == NULL)
- _throwtj("executing tjInitCompress()");
+ THROW_TJ("executing tjInitCompress()");
if (doYUV) {
yuvSize = tjBufSizeYUV2(tilew, yuvPad, tileh, subsamp);
+ if (yuvSize == (unsigned long)-1)
+ THROW_TJ("allocating YUV buffer");
if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
- _throwunix("allocating YUV buffer");
+ THROW_UNIX("allocating YUV buffer");
memset(yuvBuf, 127, yuvSize);
}
@@ -393,17 +406,17 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
if (tjEncodeYUV3(handle, srcPtr2, width, pitch, height, pf, yuvBuf,
yuvPad, subsamp, flags) == -1)
- _throwtj("executing tjEncodeYUV3()");
+ THROW_TJ("executing tjEncodeYUV3()");
if (iter >= 0) elapsedEncode += getTime() - startEncode;
if (tjCompressFromYUV(handle, yuvBuf, width, yuvPad, height,
subsamp, &jpegBuf[tile], &jpegSize[tile],
jpegQual, flags) == -1)
- _throwtj("executing tjCompressFromYUV()");
+ THROW_TJ("executing tjCompressFromYUV()");
} else {
if (tjCompress2(handle, srcPtr2, width, pitch, height, pf,
&jpegBuf[tile], &jpegSize[tile], subsamp, jpegQual,
flags) == -1)
- _throwtj("executing tjCompress2()");
+ THROW_TJ("executing tjCompress2()");
}
totalJpegSize += jpegSize[tile];
}
@@ -419,7 +432,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
}
if (doYUV) elapsed -= elapsedEncode;
- if (tjDestroy(handle) == -1) _throwtj("executing tjDestroy()");
+ if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
handle = NULL;
if (quiet == 1) fprintf(stderr, "%-5d %-5d ", tilew, tileh);
@@ -430,9 +443,9 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
(double)iter / elapsedEncode, 4, tempStr, 1024),
quiet == 2 ? "\n" : " ");
fprintf(stderr, "%-6s%s",
- sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
- tempStr, 1024),
- quiet == 2 ? "\n" : " ");
+ sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
+ tempStr, 1024),
+ quiet == 2 ? "\n" : " ");
fprintf(stderr, "%-6s%s",
sigfig((double)(w * h * ps) / (double)totalJpegSize, 4, tempStr2,
80),
@@ -443,7 +456,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
if (doYUV) {
fprintf(stderr, "Encode YUV --> Frame rate: %f fps\n",
(double)iter / elapsedEncode);
- fprintf(stderr, " Output image size: %d bytes\n",
+ fprintf(stderr, " Output image size: %lu bytes\n",
yuvSize);
fprintf(stderr, " Compression ratio: %f:1\n",
(double)(w * h * ps) / (double)yuvSize);
@@ -452,8 +465,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
(double)(w * h) / 1000000. * (double)iter / elapsedEncode);
fprintf(stderr,
" Output bit stream: %f Megabits/sec\n",
- (double)yuvSize * 8. / 1000000. * (double)iter / elapsedEncode
- );
+ (double)yuvSize * 8. / 1000000. * (double)iter / elapsedEncode);
}
fprintf(stderr, "%s --> Frame rate: %f fps\n",
doYUV ? "Comp from YUV" : "Compress ",
@@ -473,9 +485,9 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
snprintf(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
jpegQual);
if ((file = fopen(tempStr, "wb")) == NULL)
- _throwunix("opening reference image");
+ THROW_UNIX("opening reference image");
if (fwrite(jpegBuf[0], jpegSize[0], 1, file) != 1)
- _throwunix("writing reference image");
+ THROW_UNIX("writing reference image");
fclose(file); file = NULL;
if (!quiet) fprintf(stderr, "Reference image written to %s\n", tempStr);
}
@@ -485,10 +497,10 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
if (decomp(srcBuf, jpegBuf, jpegSize, tmpBuf, w, h, subsamp, jpegQual,
fileName, tilew, tileh) == -1)
goto bailout;
- }
+ } else if (quiet == 1) fprintf(stderr, "N/A\n");
for (i = 0; i < ntilesw * ntilesh; i++) {
- if (jpegBuf[i]) tjFree(jpegBuf[i]);
+ tjFree(jpegBuf[i]);
jpegBuf[i] = NULL;
}
free(jpegBuf); jpegBuf = NULL;
@@ -501,18 +513,16 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
}
bailout:
- if (file) { fclose(file); file = NULL; }
+ if (file) fclose(file);
if (jpegBuf) {
- for (i = 0; i < ntilesw * ntilesh; i++) {
- if (jpegBuf[i]) tjFree(jpegBuf[i]);
- jpegBuf[i] = NULL;
- }
- free(jpegBuf); jpegBuf = NULL;
+ for (i = 0; i < ntilesw * ntilesh; i++)
+ tjFree(jpegBuf[i]);
}
- if (yuvBuf) { free(yuvBuf); yuvBuf = NULL; }
- if (jpegSize) { free(jpegSize); jpegSize = NULL; }
- if (tmpBuf) { free(tmpBuf); tmpBuf = NULL; }
- if (handle) { tjDestroy(handle); handle = NULL; }
+ free(jpegBuf);
+ free(yuvBuf);
+ free(jpegSize);
+ free(tmpBuf);
+ if (handle) tjDestroy(handle);
return retval;
}
@@ -534,26 +544,28 @@ static int decompTest(char *fileName)
int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
if ((file = fopen(fileName, "rb")) == NULL)
- _throwunix("opening file");
+ THROW_UNIX("opening file");
if (fseek(file, 0, SEEK_END) < 0 ||
(srcSize = ftell(file)) == (unsigned long)-1)
- _throwunix("determining file size");
+ THROW_UNIX("determining file size");
if ((srcBuf = (unsigned char *)malloc(srcSize)) == NULL)
- _throwunix("allocating memory");
+ THROW_UNIX("allocating memory");
if (fseek(file, 0, SEEK_SET) < 0)
- _throwunix("setting file position");
+ THROW_UNIX("setting file position");
if (fread(srcBuf, srcSize, 1, file) < 1)
- _throwunix("reading JPEG data");
+ THROW_UNIX("reading JPEG data");
fclose(file); file = NULL;
temp = strrchr(fileName, '.');
if (temp != NULL) *temp = '\0';
if ((handle = tjInitTransform()) == NULL)
- _throwtj("executing tjInitTransform()");
+ THROW_TJ("executing tjInitTransform()");
if (tjDecompressHeader3(handle, srcBuf, srcSize, &w, &h, &subsamp,
&cs) == -1)
- _throwtj("executing tjDecompressHeader3()");
+ THROW_TJ("executing tjDecompressHeader3()");
+ if (w < 1 || h < 1)
+ THROW("reading JPEG header", "Invalid image dimensions");
if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
pf = TJPF_CMYK; ps = tjPixelSize[pf];
}
@@ -583,18 +595,21 @@ static int decompTest(char *fileName)
if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
ntilesw * ntilesh)) == NULL)
- _throwunix("allocating JPEG tile array");
+ THROW_UNIX("allocating JPEG tile array");
memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
ntilesw * ntilesh)) == NULL)
- _throwunix("allocating JPEG size array");
+ THROW_UNIX("allocating JPEG size array");
memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
- if ((flags & TJFLAG_NOREALLOC) != 0 || !doTile)
+ if ((flags & TJFLAG_NOREALLOC) != 0 &&
+ (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter))
for (i = 0; i < ntilesw * ntilesh; i++) {
+ if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
+ THROW("getting buffer size", "Image is too large");
if ((jpegBuf[i] = (unsigned char *)
tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
- _throwunix("allocating JPEG tiles");
+ THROW_UNIX("allocating JPEG tiles");
}
tw = w; th = h; ttilew = tilew; ttileh = tileh;
@@ -615,7 +630,7 @@ static int decompTest(char *fileName)
if (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter) {
if ((t = (tjtransform *)malloc(sizeof(tjtransform) * ntilesw *
ntilesh)) == NULL)
- _throwunix("allocating image transform array");
+ THROW_UNIX("allocating image transform array");
if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
@@ -661,7 +676,7 @@ static int decompTest(char *fileName)
start = getTime();
if (tjTransform(handle, srcBuf, srcSize, tntilesw * tntilesh, jpegBuf,
jpegSize, t, flags) == -1)
- _throwtj("executing tjTransform()");
+ THROW_TJ("executing tjTransform()");
elapsed += getTime() - start;
if (iter >= 0) {
iter++;
@@ -715,26 +730,25 @@ static int decompTest(char *fileName)
} else if (quiet == 1) fprintf(stderr, "N/A\n");
for (i = 0; i < ntilesw * ntilesh; i++) {
- tjFree(jpegBuf[i]); jpegBuf[i] = NULL;
+ tjFree(jpegBuf[i]);
+ jpegBuf[i] = NULL;
}
free(jpegBuf); jpegBuf = NULL;
- if (jpegSize) { free(jpegSize); jpegSize = NULL; }
+ free(jpegSize); jpegSize = NULL;
if (tilew == w && tileh == h) break;
}
bailout:
- if (file) { fclose(file); file = NULL; }
+ if (file) fclose(file);
if (jpegBuf) {
- for (i = 0; i < ntilesw * ntilesh; i++) {
- if (jpegBuf[i]) tjFree(jpegBuf[i]);
- jpegBuf[i] = NULL;
- }
- free(jpegBuf); jpegBuf = NULL;
+ for (i = 0; i < ntilesw * ntilesh; i++)
+ tjFree(jpegBuf[i]);
}
- if (jpegSize) { free(jpegSize); jpegSize = NULL; }
- if (srcBuf) { free(srcBuf); srcBuf = NULL; }
- if (t) { free(t); t = NULL; }
+ free(jpegBuf);
+ free(jpegSize);
+ free(srcBuf);
+ free(t);
if (handle) { tjDestroy(handle); handle = NULL; }
return retval;
}
@@ -810,7 +824,6 @@ static void usage(char *progName)
exit(1);
}
-
#ifndef GTEST
int main(int argc, char *argv[])
#else
@@ -823,7 +836,7 @@ int tjbench(int argc, char *argv[])
int minArg = 2, retval = 0, subsamp = -1;
if ((scalingFactors = tjGetScalingFactors(&nsf)) == NULL || nsf == 0)
- _throw("executing tjGetScalingFactors()", tjGetErrorStr());
+ THROW("executing tjGetScalingFactors()", tjGetErrorStr());
if (argc < minArg) usage(argv[0]);
@@ -922,14 +935,14 @@ int tjbench(int argc, char *argv[])
else if (!strcasecmp(argv[i], "-copynone"))
xformOpt |= TJXOPT_COPYNONE;
else if (!strcasecmp(argv[i], "-benchtime") && i < argc - 1) {
- double temp = atof(argv[++i]);
+ double tempd = atof(argv[++i]);
- if (temp > 0.0) benchTime = temp;
+ if (tempd > 0.0) benchTime = tempd;
else usage(argv[0]);
} else if (!strcasecmp(argv[i], "-warmup") && i < argc - 1) {
- double temp = atof(argv[++i]);
+ double tempd = atof(argv[++i]);
- if (temp >= 0.0) warmup = temp;
+ if (tempd >= 0.0) warmup = tempd;
else usage(argv[0]);
fprintf(stderr, "Warmup time = %.1f seconds\n\n", warmup);
} else if (!strcasecmp(argv[i], "-alloc"))
@@ -940,16 +953,16 @@ int tjbench(int argc, char *argv[])
fprintf(stderr, "Testing YUV planar encoding/decoding\n\n");
doYUV = 1;
} else if (!strcasecmp(argv[i], "-yuvpad") && i < argc - 1) {
- int temp = atoi(argv[++i]);
+ int tempi = atoi(argv[++i]);
- if (temp >= 1) yuvPad = temp;
+ if (tempi >= 1) yuvPad = tempi;
} else if (!strcasecmp(argv[i], "-subsamp") && i < argc - 1) {
i++;
if (toupper(argv[i][0]) == 'G') subsamp = TJSAMP_GRAY;
else {
- int temp = atoi(argv[i]);
+ int tempi = atoi(argv[i]);
- switch (temp) {
+ switch (tempi) {
case 444: subsamp = TJSAMP_444; break;
case 422: subsamp = TJSAMP_422; break;
case 440: subsamp = TJSAMP_440; break;
@@ -981,7 +994,7 @@ int tjbench(int argc, char *argv[])
if (!decompOnly) {
if ((srcBuf = tjLoadImage(argv[1], &w, 1, &h, &pf, flags)) == NULL)
- _throwtjg("loading bitmap");
+ THROW_TJG("loading bitmap");
temp = strrchr(argv[1], '.');
if (temp != NULL) *temp = '\0';
}
@@ -1028,6 +1041,6 @@ int tjbench(int argc, char *argv[])
}
bailout:
- if (srcBuf) tjFree(srcBuf);
+ tjFree(srcBuf);
return retval;
}