blob: 97475ec90640514caadd96fac72497530711ed71 [file] [log] [blame]
hbono@chromium.org98626972011-08-03 03:13:08 +00001/*
Jonathan Wright24e31052021-04-26 12:10:48 +01002 * Copyright (C)2009-2019, 2021 D. R. Commander. All Rights Reserved.
hbono@chromium.org98626972011-08-03 03:13:08 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of the libjpeg-turbo Project nor the names of its
13 * contributors may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
noel@chromium.org3395bcc2014-04-14 06:56:00 +000032#include <ctype.h>
hbono@chromium.org98626972011-08-03 03:13:08 +000033#include <math.h>
34#include <errno.h>
Jonathan Wrightdb870df2020-08-05 11:42:22 +010035#include <limits.h>
hbono@chromium.org98626972011-08-03 03:13:08 +000036#include <cdjpeg.h>
hbono@chromium.org98626972011-08-03 03:13:08 +000037#include "./tjutil.h"
38#include "./turbojpeg.h"
39
40
Jonathan Wrightdb870df2020-08-05 11:42:22 +010041#define THROW(op, err) { \
Jonathan Wright681ce7f2020-06-12 18:20:50 +010042 fprintf(stderr, "ERROR in line %d while %s:\n%s\n", __LINE__, op, err); \
Chris Blumecca8c4d2019-03-01 01:09:50 -080043 retval = -1; goto bailout; \
44}
Jonathan Wrightdb870df2020-08-05 11:42:22 +010045#define THROW_UNIX(m) THROW(m, strerror(errno))
hbono@chromium.org98626972011-08-03 03:13:08 +000046
Jonathan Wright285aa142020-06-12 15:14:35 +010047static char tjErrorStr[JMSG_LENGTH_MAX] = "\0",
48 tjErrorMsg[JMSG_LENGTH_MAX] = "\0";
49static int tjErrorLine = -1, tjErrorCode = -1;
Chris Blumecca8c4d2019-03-01 01:09:50 -080050
Jonathan Wrightdb870df2020-08-05 11:42:22 +010051#define THROW_TJG(m) { \
Jonathan Wright681ce7f2020-06-12 18:20:50 +010052 fprintf(stderr, "ERROR in line %d while %s:\n%s\n", __LINE__, m, \
53 tjGetErrorStr2(NULL)); \
Chris Blumecca8c4d2019-03-01 01:09:50 -080054 retval = -1; goto bailout; \
55}
56
Jonathan Wrightdb870df2020-08-05 11:42:22 +010057#define THROW_TJ(m) { \
Chris Blumecca8c4d2019-03-01 01:09:50 -080058 int _tjErrorCode = tjGetErrorCode(handle); \
59 char *_tjErrorStr = tjGetErrorStr2(handle); \
60 \
61 if (!(flags & TJFLAG_STOPONWARNING) && _tjErrorCode == TJERR_WARNING) { \
62 if (strncmp(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX) || \
63 strncmp(tjErrorMsg, m, JMSG_LENGTH_MAX) || \
64 tjErrorCode != _tjErrorCode || tjErrorLine != __LINE__) { \
65 strncpy(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX - 1); \
66 strncpy(tjErrorMsg, m, JMSG_LENGTH_MAX - 1); \
67 tjErrorCode = _tjErrorCode; \
68 tjErrorLine = __LINE__; \
Jonathan Wright681ce7f2020-06-12 18:20:50 +010069 fprintf(stderr, "WARNING in line %d while %s:\n%s\n", __LINE__, m, \
70 _tjErrorStr); \
Chris Blumecca8c4d2019-03-01 01:09:50 -080071 } \
72 } else { \
Jonathan Wright681ce7f2020-06-12 18:20:50 +010073 fprintf(stderr, "%s in line %d while %s:\n%s\n", \
74 _tjErrorCode == TJERR_WARNING ? "WARNING" : "ERROR", __LINE__, m, \
75 _tjErrorStr); \
Chris Blumecca8c4d2019-03-01 01:09:50 -080076 retval = -1; goto bailout; \
77 } \
78}
79
Jonathan Wright285aa142020-06-12 15:14:35 +010080static int flags = TJFLAG_NOREALLOC, compOnly = 0, decompOnly = 0, doYUV = 0,
Chris Blumecca8c4d2019-03-01 01:09:50 -080081 quiet = 0, doTile = 0, pf = TJPF_BGR, yuvPad = 1, doWrite = 1;
Jonathan Wright285aa142020-06-12 15:14:35 +010082static char *ext = "ppm";
83static const char *pixFormatStr[TJ_NUMPF] = {
Chris Blumecca8c4d2019-03-01 01:09:50 -080084 "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY", "", "", "", "", "CMYK"
hbono@chromium.org98626972011-08-03 03:13:08 +000085};
Jonathan Wright285aa142020-06-12 15:14:35 +010086static const char *subNameLong[TJ_NUMSAMP] = {
Chris Blumecca8c4d2019-03-01 01:09:50 -080087 "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1"
hbono@chromium.org98626972011-08-03 03:13:08 +000088};
Jonathan Wright285aa142020-06-12 15:14:35 +010089static const char *csName[TJ_NUMCS] = {
Chris Blumecca8c4d2019-03-01 01:09:50 -080090 "RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
Tom Hudson0d47d2d2016-05-04 13:22:56 -040091};
Jonathan Wright285aa142020-06-12 15:14:35 +010092static const char *subName[TJ_NUMSAMP] = {
Chris Blumecca8c4d2019-03-01 01:09:50 -080093 "444", "422", "420", "GRAY", "440", "411"
94};
Jonathan Wright285aa142020-06-12 15:14:35 +010095static tjscalingfactor *scalingFactors = NULL, sf = { 1, 1 };
96static int nsf = 0, xformOp = TJXOP_NONE, xformOpt = 0;
97static int (*customFilter) (short *, tjregion, tjregion, int, int,
98 tjtransform *);
99static double benchTime = 5.0, warmup = 1.0;
hbono@chromium.org98626972011-08-03 03:13:08 +0000100
101
Jonathan Wright285aa142020-06-12 15:14:35 +0100102static char *formatName(int subsamp, int cs, char *buf)
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400103{
Chris Blumecca8c4d2019-03-01 01:09:50 -0800104 if (cs == TJCS_YCbCr)
105 return (char *)subNameLong[subsamp];
106 else if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
107 snprintf(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
108 return buf;
109 } else
110 return (char *)csName[cs];
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400111}
112
113
Jonathan Wright285aa142020-06-12 15:14:35 +0100114static char *sigfig(double val, int figs, char *buf, int len)
hbono@chromium.org98626972011-08-03 03:13:08 +0000115{
Chris Blumecca8c4d2019-03-01 01:09:50 -0800116 char format[80];
117 int digitsAfterDecimal = figs - (int)ceil(log10(fabs(val)));
118
119 if (digitsAfterDecimal < 1)
120 snprintf(format, 80, "%%.0f");
121 else
122 snprintf(format, 80, "%%.%df", digitsAfterDecimal);
123 snprintf(buf, len, format, val);
124 return buf;
hbono@chromium.org98626972011-08-03 03:13:08 +0000125}
126
127
hbono@chromium.orgc6beb742011-11-29 05:16:26 +0000128/* Custom DCT filter which produces a negative of the image */
Jonathan Wright285aa142020-06-12 15:14:35 +0100129static int dummyDCTFilter(short *coeffs, tjregion arrayRegion,
130 tjregion planeRegion, int componentIndex,
131 int transformIndex, tjtransform *transform)
hbono@chromium.orgc6beb742011-11-29 05:16:26 +0000132{
Chris Blumecca8c4d2019-03-01 01:09:50 -0800133 int i;
134
135 for (i = 0; i < arrayRegion.w * arrayRegion.h; i++)
136 coeffs[i] = -coeffs[i];
137 return 0;
hbono@chromium.orgc6beb742011-11-29 05:16:26 +0000138}
139
140
hbono@chromium.org98626972011-08-03 03:13:08 +0000141/* Decompression test */
Jonathan Wright285aa142020-06-12 15:14:35 +0100142static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
143 unsigned long *jpegSize, unsigned char *dstBuf, int w, int h,
144 int subsamp, int jpegQual, char *fileName, int tilew,
145 int tileh)
hbono@chromium.org98626972011-08-03 03:13:08 +0000146{
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100147 char tempStr[1024], sizeStr[24] = "\0", qualStr[13] = "\0", *ptr;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800148 FILE *file = NULL;
149 tjhandle handle = NULL;
150 int row, col, iter = 0, dstBufAlloc = 0, retval = 0;
151 double elapsed, elapsedDecode;
152 int ps = tjPixelSize[pf];
153 int scaledw = TJSCALED(w, sf);
154 int scaledh = TJSCALED(h, sf);
155 int pitch = scaledw * ps;
156 int ntilesw = (w + tilew - 1) / tilew, ntilesh = (h + tileh - 1) / tileh;
157 unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
hbono@chromium.org98626972011-08-03 03:13:08 +0000158
Chris Blumecca8c4d2019-03-01 01:09:50 -0800159 if (jpegQual > 0) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100160 snprintf(qualStr, 13, "_Q%d", jpegQual);
161 qualStr[12] = 0;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800162 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000163
Chris Blumecca8c4d2019-03-01 01:09:50 -0800164 if ((handle = tjInitDecompress()) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100165 THROW_TJ("executing tjInitDecompress()");
hbono@chromium.org98626972011-08-03 03:13:08 +0000166
Chris Blumecca8c4d2019-03-01 01:09:50 -0800167 if (dstBuf == NULL) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100168 if ((unsigned long long)pitch * (unsigned long long)scaledh >
169 (unsigned long long)((size_t)-1))
170 THROW("allocating destination buffer", "Image is too large");
171 if ((dstBuf = (unsigned char *)malloc((size_t)pitch * scaledh)) == NULL)
172 THROW_UNIX("allocating destination buffer");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800173 dstBufAlloc = 1;
174 }
175 /* Set the destination buffer to gray so we know whether the decompressor
176 attempted to write to it */
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100177 memset(dstBuf, 127, (size_t)pitch * scaledh);
hbono@chromium.org98626972011-08-03 03:13:08 +0000178
Chris Blumecca8c4d2019-03-01 01:09:50 -0800179 if (doYUV) {
180 int width = doTile ? tilew : scaledw;
181 int height = doTile ? tileh : scaledh;
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100182 unsigned long yuvSize = tjBufSizeYUV2(width, yuvPad, height, subsamp);
hbono@chromium.org98626972011-08-03 03:13:08 +0000183
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100184 if (yuvSize == (unsigned long)-1)
185 THROW_TJ("allocating YUV buffer");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800186 if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100187 THROW_UNIX("allocating YUV buffer");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800188 memset(yuvBuf, 127, yuvSize);
189 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000190
Chris Blumecca8c4d2019-03-01 01:09:50 -0800191 /* Benchmark */
192 iter = -1;
193 elapsed = elapsedDecode = 0.;
194 while (1) {
195 int tile = 0;
196 double start = getTime();
hbono@chromium.org98626972011-08-03 03:13:08 +0000197
Chris Blumecca8c4d2019-03-01 01:09:50 -0800198 for (row = 0, dstPtr = dstBuf; row < ntilesh;
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100199 row++, dstPtr += (size_t)pitch * tileh) {
Chris Blumecca8c4d2019-03-01 01:09:50 -0800200 for (col = 0, dstPtr2 = dstPtr; col < ntilesw;
201 col++, tile++, dstPtr2 += ps * tilew) {
202 int width = doTile ? min(tilew, w - col * tilew) : scaledw;
203 int height = doTile ? min(tileh, h - row * tileh) : scaledh;
hbono@chromium.org98626972011-08-03 03:13:08 +0000204
Chris Blumecca8c4d2019-03-01 01:09:50 -0800205 if (doYUV) {
206 double startDecode;
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400207
Chris Blumecca8c4d2019-03-01 01:09:50 -0800208 if (tjDecompressToYUV2(handle, jpegBuf[tile], jpegSize[tile], yuvBuf,
209 width, yuvPad, height, flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100210 THROW_TJ("executing tjDecompressToYUV2()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800211 startDecode = getTime();
212 if (tjDecodeYUV(handle, yuvBuf, yuvPad, subsamp, dstPtr2, width,
213 pitch, height, pf, flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100214 THROW_TJ("executing tjDecodeYUV()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800215 if (iter >= 0) elapsedDecode += getTime() - startDecode;
216 } else if (tjDecompress2(handle, jpegBuf[tile], jpegSize[tile],
217 dstPtr2, width, pitch, height, pf,
218 flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100219 THROW_TJ("executing tjDecompress2()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800220 }
221 }
222 elapsed += getTime() - start;
223 if (iter >= 0) {
224 iter++;
225 if (elapsed >= benchTime) break;
226 } else if (elapsed >= warmup) {
227 iter = 0;
228 elapsed = elapsedDecode = 0.;
229 }
230 }
231 if (doYUV) elapsed -= elapsedDecode;
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400232
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100233 if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800234 handle = NULL;
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400235
Chris Blumecca8c4d2019-03-01 01:09:50 -0800236 if (quiet) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100237 fprintf(stderr, "%-6s%s",
238 sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
239 tempStr, 1024),
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100240 quiet == 2 ? "\n" : " ");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800241 if (doYUV)
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100242 fprintf(stderr, "%s\n",
243 sigfig((double)(w * h) / 1000000. * (double)iter / elapsedDecode,
244 4, tempStr, 1024));
245 else if (quiet != 2) fprintf(stderr, "\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800246 } else {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100247 fprintf(stderr, "%s --> Frame rate: %f fps\n",
248 doYUV ? "Decomp to YUV" : "Decompress ", (double)iter / elapsed);
249 fprintf(stderr,
250 " Throughput: %f Megapixels/sec\n",
251 (double)(w * h) / 1000000. * (double)iter / elapsed);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800252 if (doYUV) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100253 fprintf(stderr, "YUV Decode --> Frame rate: %f fps\n",
254 (double)iter / elapsedDecode);
255 fprintf(stderr,
256 " Throughput: %f Megapixels/sec\n",
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100257 (double)(w * h) / 1000000. * (double)iter / elapsedDecode);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800258 }
259 }
260
261 if (!doWrite) goto bailout;
262
263 if (sf.num != 1 || sf.denom != 1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100264 snprintf(sizeStr, 24, "%d_%d", sf.num, sf.denom);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800265 else if (tilew != w || tileh != h)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100266 snprintf(sizeStr, 24, "%dx%d", tilew, tileh);
267 else snprintf(sizeStr, 24, "full");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800268 if (decompOnly)
269 snprintf(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
270 else
271 snprintf(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
272 qualStr, sizeStr, ext);
273
274 if (tjSaveImage(tempStr, dstBuf, scaledw, 0, scaledh, pf, flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100275 THROW_TJG("saving bitmap");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800276 ptr = strrchr(tempStr, '.');
277 snprintf(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
278 if (srcBuf && sf.num == 1 && sf.denom == 1) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100279 if (!quiet) fprintf(stderr, "Compression error written to %s.\n", tempStr);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800280 if (subsamp == TJ_GRAYSCALE) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100281 unsigned long index, index2;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800282
283 for (row = 0, index = 0; row < h; row++, index += pitch) {
284 for (col = 0, index2 = index; col < w; col++, index2 += ps) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100285 unsigned long rindex = index2 + tjRedOffset[pf];
286 unsigned long gindex = index2 + tjGreenOffset[pf];
287 unsigned long bindex = index2 + tjBlueOffset[pf];
Chris Blumecca8c4d2019-03-01 01:09:50 -0800288 int y = (int)((double)srcBuf[rindex] * 0.299 +
289 (double)srcBuf[gindex] * 0.587 +
290 (double)srcBuf[bindex] * 0.114 + 0.5);
291
292 if (y > 255) y = 255;
293 if (y < 0) y = 0;
294 dstBuf[rindex] = abs(dstBuf[rindex] - y);
295 dstBuf[gindex] = abs(dstBuf[gindex] - y);
296 dstBuf[bindex] = abs(dstBuf[bindex] - y);
297 }
298 }
299 } else {
300 for (row = 0; row < h; row++)
301 for (col = 0; col < w * ps; col++)
302 dstBuf[pitch * row + col] =
303 abs(dstBuf[pitch * row + col] - srcBuf[pitch * row + col]);
304 }
305 if (tjSaveImage(tempStr, dstBuf, w, 0, h, pf, flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100306 THROW_TJG("saving bitmap");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800307 }
308
309bailout:
310 if (file) fclose(file);
311 if (handle) tjDestroy(handle);
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100312 if (dstBufAlloc) free(dstBuf);
313 free(yuvBuf);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800314 return retval;
hbono@chromium.org98626972011-08-03 03:13:08 +0000315}
316
317
Jonathan Wright285aa142020-06-12 15:14:35 +0100318static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
319 int jpegQual, char *fileName)
hbono@chromium.org98626972011-08-03 03:13:08 +0000320{
Chris Blumecca8c4d2019-03-01 01:09:50 -0800321 char tempStr[1024], tempStr2[80];
322 FILE *file = NULL;
323 tjhandle handle = NULL;
324 unsigned char **jpegBuf = NULL, *yuvBuf = NULL, *tmpBuf = NULL, *srcPtr,
325 *srcPtr2;
326 double start, elapsed, elapsedEncode;
327 int totalJpegSize = 0, row, col, i, tilew = w, tileh = h, retval = 0;
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100328 int iter;
329 unsigned long *jpegSize = NULL, yuvSize = 0;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800330 int ps = tjPixelSize[pf];
331 int ntilesw = 1, ntilesh = 1, pitch = w * ps;
332 const char *pfStr = pixFormatStr[pf];
hbono@chromium.org98626972011-08-03 03:13:08 +0000333
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100334 if ((unsigned long long)pitch * (unsigned long long)h >
335 (unsigned long long)((size_t)-1))
336 THROW("allocating temporary image buffer", "Image is too large");
337 if ((tmpBuf = (unsigned char *)malloc((size_t)pitch * h)) == NULL)
338 THROW_UNIX("allocating temporary image buffer");
hbono@chromium.org98626972011-08-03 03:13:08 +0000339
Chris Blumecca8c4d2019-03-01 01:09:50 -0800340 if (!quiet)
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100341 fprintf(stderr, ">>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", pfStr,
342 (flags & TJFLAG_BOTTOMUP) ? "Bottom-up" : "Top-down",
343 subNameLong[subsamp], jpegQual);
hbono@chromium.org98626972011-08-03 03:13:08 +0000344
Chris Blumecca8c4d2019-03-01 01:09:50 -0800345 for (tilew = doTile ? 8 : w, tileh = doTile ? 8 : h; ;
346 tilew *= 2, tileh *= 2) {
347 if (tilew > w) tilew = w;
348 if (tileh > h) tileh = h;
349 ntilesw = (w + tilew - 1) / tilew;
350 ntilesh = (h + tileh - 1) / tileh;
hbono@chromium.org98626972011-08-03 03:13:08 +0000351
Chris Blumecca8c4d2019-03-01 01:09:50 -0800352 if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
353 ntilesw * ntilesh)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100354 THROW_UNIX("allocating JPEG tile array");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800355 memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
356 if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
357 ntilesw * ntilesh)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100358 THROW_UNIX("allocating JPEG size array");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800359 memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
hbono@chromium.org98626972011-08-03 03:13:08 +0000360
Chris Blumecca8c4d2019-03-01 01:09:50 -0800361 if ((flags & TJFLAG_NOREALLOC) != 0)
362 for (i = 0; i < ntilesw * ntilesh; i++) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100363 if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
364 THROW("getting buffer size", "Image is too large");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800365 if ((jpegBuf[i] = (unsigned char *)
366 tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100367 THROW_UNIX("allocating JPEG tiles");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800368 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000369
Chris Blumecca8c4d2019-03-01 01:09:50 -0800370 /* Compression test */
371 if (quiet == 1)
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100372 fprintf(stderr, "%-4s (%s) %-5s %-3d ", pfStr,
373 (flags & TJFLAG_BOTTOMUP) ? "BU" : "TD", subNameLong[subsamp],
374 jpegQual);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800375 for (i = 0; i < h; i++)
376 memcpy(&tmpBuf[pitch * i], &srcBuf[w * ps * i], w * ps);
377 if ((handle = tjInitCompress()) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100378 THROW_TJ("executing tjInitCompress()");
hbono@chromium.org98626972011-08-03 03:13:08 +0000379
Chris Blumecca8c4d2019-03-01 01:09:50 -0800380 if (doYUV) {
381 yuvSize = tjBufSizeYUV2(tilew, yuvPad, tileh, subsamp);
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100382 if (yuvSize == (unsigned long)-1)
383 THROW_TJ("allocating YUV buffer");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800384 if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100385 THROW_UNIX("allocating YUV buffer");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800386 memset(yuvBuf, 127, yuvSize);
387 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000388
Chris Blumecca8c4d2019-03-01 01:09:50 -0800389 /* Benchmark */
390 iter = -1;
391 elapsed = elapsedEncode = 0.;
392 while (1) {
393 int tile = 0;
hbono@chromium.org98626972011-08-03 03:13:08 +0000394
Chris Blumecca8c4d2019-03-01 01:09:50 -0800395 totalJpegSize = 0;
396 start = getTime();
397 for (row = 0, srcPtr = srcBuf; row < ntilesh;
398 row++, srcPtr += pitch * tileh) {
399 for (col = 0, srcPtr2 = srcPtr; col < ntilesw;
400 col++, tile++, srcPtr2 += ps * tilew) {
401 int width = min(tilew, w - col * tilew);
402 int height = min(tileh, h - row * tileh);
hbono@chromium.org98626972011-08-03 03:13:08 +0000403
Chris Blumecca8c4d2019-03-01 01:09:50 -0800404 if (doYUV) {
405 double startEncode = getTime();
hbono@chromium.org98626972011-08-03 03:13:08 +0000406
Chris Blumecca8c4d2019-03-01 01:09:50 -0800407 if (tjEncodeYUV3(handle, srcPtr2, width, pitch, height, pf, yuvBuf,
408 yuvPad, subsamp, flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100409 THROW_TJ("executing tjEncodeYUV3()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800410 if (iter >= 0) elapsedEncode += getTime() - startEncode;
411 if (tjCompressFromYUV(handle, yuvBuf, width, yuvPad, height,
412 subsamp, &jpegBuf[tile], &jpegSize[tile],
413 jpegQual, flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100414 THROW_TJ("executing tjCompressFromYUV()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800415 } else {
416 if (tjCompress2(handle, srcPtr2, width, pitch, height, pf,
417 &jpegBuf[tile], &jpegSize[tile], subsamp, jpegQual,
418 flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100419 THROW_TJ("executing tjCompress2()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800420 }
421 totalJpegSize += jpegSize[tile];
422 }
423 }
424 elapsed += getTime() - start;
425 if (iter >= 0) {
426 iter++;
427 if (elapsed >= benchTime) break;
428 } else if (elapsed >= warmup) {
429 iter = 0;
430 elapsed = elapsedEncode = 0.;
431 }
432 }
433 if (doYUV) elapsed -= elapsedEncode;
hbono@chromium.org98626972011-08-03 03:13:08 +0000434
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100435 if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800436 handle = NULL;
hbono@chromium.org98626972011-08-03 03:13:08 +0000437
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100438 if (quiet == 1) fprintf(stderr, "%-5d %-5d ", tilew, tileh);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800439 if (quiet) {
440 if (doYUV)
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100441 fprintf(stderr, "%-6s%s",
442 sigfig((double)(w * h) / 1000000. *
443 (double)iter / elapsedEncode, 4, tempStr, 1024),
444 quiet == 2 ? "\n" : " ");
445 fprintf(stderr, "%-6s%s",
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100446 sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
447 tempStr, 1024),
448 quiet == 2 ? "\n" : " ");
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100449 fprintf(stderr, "%-6s%s",
450 sigfig((double)(w * h * ps) / (double)totalJpegSize, 4, tempStr2,
451 80),
452 quiet == 2 ? "\n" : " ");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800453 } else {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100454 fprintf(stderr, "\n%s size: %d x %d\n", doTile ? "Tile" : "Image", tilew,
455 tileh);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800456 if (doYUV) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100457 fprintf(stderr, "Encode YUV --> Frame rate: %f fps\n",
458 (double)iter / elapsedEncode);
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100459 fprintf(stderr, " Output image size: %lu bytes\n",
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100460 yuvSize);
461 fprintf(stderr, " Compression ratio: %f:1\n",
462 (double)(w * h * ps) / (double)yuvSize);
463 fprintf(stderr,
464 " Throughput: %f Megapixels/sec\n",
465 (double)(w * h) / 1000000. * (double)iter / elapsedEncode);
466 fprintf(stderr,
467 " Output bit stream: %f Megabits/sec\n",
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100468 (double)yuvSize * 8. / 1000000. * (double)iter / elapsedEncode);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800469 }
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100470 fprintf(stderr, "%s --> Frame rate: %f fps\n",
471 doYUV ? "Comp from YUV" : "Compress ",
472 (double)iter / elapsed);
473 fprintf(stderr, " Output image size: %d bytes\n",
474 totalJpegSize);
475 fprintf(stderr, " Compression ratio: %f:1\n",
476 (double)(w * h * ps) / (double)totalJpegSize);
477 fprintf(stderr,
478 " Throughput: %f Megapixels/sec\n",
479 (double)(w * h) / 1000000. * (double)iter / elapsed);
480 fprintf(stderr,
481 " Output bit stream: %f Megabits/sec\n",
482 (double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800483 }
484 if (tilew == w && tileh == h && doWrite) {
485 snprintf(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
486 jpegQual);
487 if ((file = fopen(tempStr, "wb")) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100488 THROW_UNIX("opening reference image");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800489 if (fwrite(jpegBuf[0], jpegSize[0], 1, file) != 1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100490 THROW_UNIX("writing reference image");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800491 fclose(file); file = NULL;
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100492 if (!quiet) fprintf(stderr, "Reference image written to %s\n", tempStr);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800493 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000494
Chris Blumecca8c4d2019-03-01 01:09:50 -0800495 /* Decompression test */
496 if (!compOnly) {
497 if (decomp(srcBuf, jpegBuf, jpegSize, tmpBuf, w, h, subsamp, jpegQual,
498 fileName, tilew, tileh) == -1)
499 goto bailout;
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100500 } else if (quiet == 1) fprintf(stderr, "N/A\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800501
502 for (i = 0; i < ntilesw * ntilesh; i++) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100503 tjFree(jpegBuf[i]);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800504 jpegBuf[i] = NULL;
505 }
506 free(jpegBuf); jpegBuf = NULL;
507 free(jpegSize); jpegSize = NULL;
508 if (doYUV) {
509 free(yuvBuf); yuvBuf = NULL;
510 }
511
512 if (tilew == w && tileh == h) break;
513 }
514
515bailout:
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100516 if (file) fclose(file);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800517 if (jpegBuf) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100518 for (i = 0; i < ntilesw * ntilesh; i++)
519 tjFree(jpegBuf[i]);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800520 }
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100521 free(jpegBuf);
522 free(yuvBuf);
523 free(jpegSize);
524 free(tmpBuf);
525 if (handle) tjDestroy(handle);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800526 return retval;
hbono@chromium.org98626972011-08-03 03:13:08 +0000527}
528
529
Jonathan Wright285aa142020-06-12 15:14:35 +0100530static int decompTest(char *fileName)
hbono@chromium.org98626972011-08-03 03:13:08 +0000531{
Chris Blumecca8c4d2019-03-01 01:09:50 -0800532 FILE *file = NULL;
533 tjhandle handle = NULL;
534 unsigned char **jpegBuf = NULL, *srcBuf = NULL;
535 unsigned long *jpegSize = NULL, srcSize, totalJpegSize;
536 tjtransform *t = NULL;
537 double start, elapsed;
538 int ps = tjPixelSize[pf], tile, row, col, i, iter, retval = 0, decompsrc = 0;
539 char *temp = NULL, tempStr[80], tempStr2[80];
540 /* Original image */
541 int w = 0, h = 0, tilew, tileh, ntilesw = 1, ntilesh = 1, subsamp = -1,
542 cs = -1;
543 /* Transformed image */
544 int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
hbono@chromium.org98626972011-08-03 03:13:08 +0000545
Chris Blumecca8c4d2019-03-01 01:09:50 -0800546 if ((file = fopen(fileName, "rb")) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100547 THROW_UNIX("opening file");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800548 if (fseek(file, 0, SEEK_END) < 0 ||
549 (srcSize = ftell(file)) == (unsigned long)-1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100550 THROW_UNIX("determining file size");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800551 if ((srcBuf = (unsigned char *)malloc(srcSize)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100552 THROW_UNIX("allocating memory");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800553 if (fseek(file, 0, SEEK_SET) < 0)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100554 THROW_UNIX("setting file position");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800555 if (fread(srcBuf, srcSize, 1, file) < 1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100556 THROW_UNIX("reading JPEG data");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800557 fclose(file); file = NULL;
hbono@chromium.org98626972011-08-03 03:13:08 +0000558
Chris Blumecca8c4d2019-03-01 01:09:50 -0800559 temp = strrchr(fileName, '.');
560 if (temp != NULL) *temp = '\0';
hbono@chromium.org98626972011-08-03 03:13:08 +0000561
Chris Blumecca8c4d2019-03-01 01:09:50 -0800562 if ((handle = tjInitTransform()) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100563 THROW_TJ("executing tjInitTransform()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800564 if (tjDecompressHeader3(handle, srcBuf, srcSize, &w, &h, &subsamp,
565 &cs) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100566 THROW_TJ("executing tjDecompressHeader3()");
567 if (w < 1 || h < 1)
568 THROW("reading JPEG header", "Invalid image dimensions");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800569 if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
570 pf = TJPF_CMYK; ps = tjPixelSize[pf];
571 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000572
Chris Blumecca8c4d2019-03-01 01:09:50 -0800573 if (quiet == 1) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100574 fprintf(stderr, "All performance values in Mpixels/sec\n\n");
575 fprintf(stderr,
576 "Bitmap JPEG JPEG %s %s Xform Comp Decomp ",
577 doTile ? "Tile " : "Image", doTile ? "Tile " : "Image");
578 if (doYUV) fprintf(stderr, "Decode");
579 fprintf(stderr, "\n");
580 fprintf(stderr,
581 "Format CS Subsamp Width Height Perf Ratio Perf ");
582 if (doYUV) fprintf(stderr, "Perf");
583 fprintf(stderr, "\n\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800584 } else if (!quiet)
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100585 fprintf(stderr, ">>>>> JPEG %s --> %s (%s) <<<<<\n",
586 formatName(subsamp, cs, tempStr), pixFormatStr[pf],
587 (flags & TJFLAG_BOTTOMUP) ? "Bottom-up" : "Top-down");
hbono@chromium.org98626972011-08-03 03:13:08 +0000588
Chris Blumecca8c4d2019-03-01 01:09:50 -0800589 for (tilew = doTile ? 16 : w, tileh = doTile ? 16 : h; ;
590 tilew *= 2, tileh *= 2) {
591 if (tilew > w) tilew = w;
592 if (tileh > h) tileh = h;
593 ntilesw = (w + tilew - 1) / tilew;
594 ntilesh = (h + tileh - 1) / tileh;
hbono@chromium.org98626972011-08-03 03:13:08 +0000595
Chris Blumecca8c4d2019-03-01 01:09:50 -0800596 if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
597 ntilesw * ntilesh)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100598 THROW_UNIX("allocating JPEG tile array");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800599 memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
600 if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
601 ntilesw * ntilesh)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100602 THROW_UNIX("allocating JPEG size array");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800603 memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
hbono@chromium.org98626972011-08-03 03:13:08 +0000604
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100605 if ((flags & TJFLAG_NOREALLOC) != 0 &&
606 (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter))
Chris Blumecca8c4d2019-03-01 01:09:50 -0800607 for (i = 0; i < ntilesw * ntilesh; i++) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100608 if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
609 THROW("getting buffer size", "Image is too large");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800610 if ((jpegBuf[i] = (unsigned char *)
611 tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100612 THROW_UNIX("allocating JPEG tiles");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800613 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000614
Chris Blumecca8c4d2019-03-01 01:09:50 -0800615 tw = w; th = h; ttilew = tilew; ttileh = tileh;
616 if (!quiet) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100617 fprintf(stderr, "\n%s size: %d x %d", doTile ? "Tile" : "Image", ttilew,
618 ttileh);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800619 if (sf.num != 1 || sf.denom != 1)
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100620 fprintf(stderr, " --> %d x %d", TJSCALED(tw, sf), TJSCALED(th, sf));
621 fprintf(stderr, "\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800622 } else if (quiet == 1) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100623 fprintf(stderr, "%-4s (%s) %-5s %-5s ", pixFormatStr[pf],
624 (flags & TJFLAG_BOTTOMUP) ? "BU" : "TD", csName[cs],
625 subNameLong[subsamp]);
626 fprintf(stderr, "%-5d %-5d ", tilew, tileh);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800627 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000628
Chris Blumecca8c4d2019-03-01 01:09:50 -0800629 tsubsamp = subsamp;
630 if (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter) {
631 if ((t = (tjtransform *)malloc(sizeof(tjtransform) * ntilesw *
632 ntilesh)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100633 THROW_UNIX("allocating image transform array");
hbono@chromium.org98626972011-08-03 03:13:08 +0000634
Chris Blumecca8c4d2019-03-01 01:09:50 -0800635 if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
636 xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
637 tw = h; th = w; ttilew = tileh; ttileh = tilew;
638 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000639
Chris Blumecca8c4d2019-03-01 01:09:50 -0800640 if (xformOpt & TJXOPT_GRAY) tsubsamp = TJ_GRAYSCALE;
641 if (xformOp == TJXOP_HFLIP || xformOp == TJXOP_ROT180)
642 tw = tw - (tw % tjMCUWidth[tsubsamp]);
643 if (xformOp == TJXOP_VFLIP || xformOp == TJXOP_ROT180)
644 th = th - (th % tjMCUHeight[tsubsamp]);
645 if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT90)
646 tw = tw - (tw % tjMCUHeight[tsubsamp]);
647 if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT270)
648 th = th - (th % tjMCUWidth[tsubsamp]);
649 tntilesw = (tw + ttilew - 1) / ttilew;
650 tntilesh = (th + ttileh - 1) / ttileh;
hbono@chromium.org98626972011-08-03 03:13:08 +0000651
Chris Blumecca8c4d2019-03-01 01:09:50 -0800652 if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
653 xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
654 if (tsubsamp == TJSAMP_422) tsubsamp = TJSAMP_440;
655 else if (tsubsamp == TJSAMP_440) tsubsamp = TJSAMP_422;
656 }
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400657
Chris Blumecca8c4d2019-03-01 01:09:50 -0800658 for (row = 0, tile = 0; row < tntilesh; row++) {
659 for (col = 0; col < tntilesw; col++, tile++) {
660 t[tile].r.w = min(ttilew, tw - col * ttilew);
661 t[tile].r.h = min(ttileh, th - row * ttileh);
662 t[tile].r.x = col * ttilew;
663 t[tile].r.y = row * ttileh;
664 t[tile].op = xformOp;
665 t[tile].options = xformOpt | TJXOPT_TRIM;
666 t[tile].customFilter = customFilter;
667 if (t[tile].options & TJXOPT_NOOUTPUT && jpegBuf[tile]) {
668 tjFree(jpegBuf[tile]); jpegBuf[tile] = NULL;
669 }
670 }
671 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000672
Chris Blumecca8c4d2019-03-01 01:09:50 -0800673 iter = -1;
674 elapsed = 0.;
675 while (1) {
676 start = getTime();
677 if (tjTransform(handle, srcBuf, srcSize, tntilesw * tntilesh, jpegBuf,
678 jpegSize, t, flags) == -1)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100679 THROW_TJ("executing tjTransform()");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800680 elapsed += getTime() - start;
681 if (iter >= 0) {
682 iter++;
683 if (elapsed >= benchTime) break;
684 } else if (elapsed >= warmup) {
685 iter = 0;
686 elapsed = 0.;
687 }
688 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000689
Chris Blumecca8c4d2019-03-01 01:09:50 -0800690 free(t); t = NULL;
hbono@chromium.org98626972011-08-03 03:13:08 +0000691
Chris Blumecca8c4d2019-03-01 01:09:50 -0800692 for (tile = 0, totalJpegSize = 0; tile < tntilesw * tntilesh; tile++)
693 totalJpegSize += jpegSize[tile];
hbono@chromium.org98626972011-08-03 03:13:08 +0000694
Chris Blumecca8c4d2019-03-01 01:09:50 -0800695 if (quiet) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100696 fprintf(stderr, "%-6s%s%-6s%s",
697 sigfig((double)(w * h) / 1000000. / elapsed, 4, tempStr, 80),
698 quiet == 2 ? "\n" : " ",
699 sigfig((double)(w * h * ps) / (double)totalJpegSize, 4,
700 tempStr2, 80),
701 quiet == 2 ? "\n" : " ");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800702 } else if (!quiet) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100703 fprintf(stderr, "Transform --> Frame rate: %f fps\n",
704 1.0 / elapsed);
705 fprintf(stderr, " Output image size: %lu bytes\n",
706 totalJpegSize);
707 fprintf(stderr, " Compression ratio: %f:1\n",
708 (double)(w * h * ps) / (double)totalJpegSize);
709 fprintf(stderr,
710 " Throughput: %f Megapixels/sec\n",
711 (double)(w * h) / 1000000. / elapsed);
712 fprintf(stderr,
713 " Output bit stream: %f Megabits/sec\n",
714 (double)totalJpegSize * 8. / 1000000. / elapsed);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800715 }
716 } else {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100717 if (quiet == 1) fprintf(stderr, "N/A N/A ");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800718 tjFree(jpegBuf[0]);
719 jpegBuf[0] = NULL;
720 decompsrc = 1;
721 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000722
Chris Blumecca8c4d2019-03-01 01:09:50 -0800723 if (w == tilew) ttilew = tw;
724 if (h == tileh) ttileh = th;
725 if (!(xformOpt & TJXOPT_NOOUTPUT)) {
726 if (decomp(NULL, decompsrc ? &srcBuf : jpegBuf,
727 decompsrc ? &srcSize : jpegSize, NULL, tw, th, tsubsamp, 0,
728 fileName, ttilew, ttileh) == -1)
729 goto bailout;
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100730 } else if (quiet == 1) fprintf(stderr, "N/A\n");
hbono@chromium.org98626972011-08-03 03:13:08 +0000731
Chris Blumecca8c4d2019-03-01 01:09:50 -0800732 for (i = 0; i < ntilesw * ntilesh; i++) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100733 tjFree(jpegBuf[i]);
734 jpegBuf[i] = NULL;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800735 }
736 free(jpegBuf); jpegBuf = NULL;
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100737 free(jpegSize); jpegSize = NULL;
hbono@chromium.org98626972011-08-03 03:13:08 +0000738
Chris Blumecca8c4d2019-03-01 01:09:50 -0800739 if (tilew == w && tileh == h) break;
740 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000741
Chris Blumecca8c4d2019-03-01 01:09:50 -0800742bailout:
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100743 if (file) fclose(file);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800744 if (jpegBuf) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100745 for (i = 0; i < ntilesw * ntilesh; i++)
746 tjFree(jpegBuf[i]);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800747 }
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100748 free(jpegBuf);
749 free(jpegSize);
750 free(srcBuf);
751 free(t);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800752 if (handle) { tjDestroy(handle); handle = NULL; }
753 return retval;
hbono@chromium.org98626972011-08-03 03:13:08 +0000754}
755
756
Jonathan Wright285aa142020-06-12 15:14:35 +0100757static void usage(char *progName)
hbono@chromium.org98626972011-08-03 03:13:08 +0000758{
Chris Blumecca8c4d2019-03-01 01:09:50 -0800759 int i;
760
761 printf("USAGE: %s\n", progName);
762 printf(" <Inputfile (BMP|PPM)> <Quality> [options]\n\n");
763 printf(" %s\n", progName);
764 printf(" <Inputfile (JPG)> [options]\n\n");
765 printf("Options:\n\n");
766 printf("-alloc = Dynamically allocate JPEG image buffers\n");
767 printf("-bmp = Generate output images in Windows Bitmap format (default = PPM)\n");
768 printf("-bottomup = Test bottom-up compression/decompression\n");
769 printf("-tile = Test performance of the codec when the image is encoded as separate\n");
770 printf(" tiles of varying sizes.\n");
771 printf("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =\n");
772 printf(" Test the specified color conversion path in the codec (default = BGR)\n");
773 printf("-cmyk = Indirectly test YCCK JPEG compression/decompression (the source\n");
774 printf(" and destination bitmaps are still RGB. The conversion is done\n");
775 printf(" internally prior to compression or after decompression.)\n");
776 printf("-fastupsample = Use the fastest chrominance upsampling algorithm available in\n");
777 printf(" the underlying codec\n");
778 printf("-fastdct = Use the fastest DCT/IDCT algorithms available in the underlying\n");
779 printf(" codec\n");
780 printf("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the\n");
781 printf(" underlying codec\n");
782 printf("-progressive = Use progressive entropy coding in JPEG images generated by\n");
783 printf(" compression and transform operations.\n");
784 printf("-subsamp <s> = When testing JPEG compression, this option specifies the level\n");
785 printf(" of chrominance subsampling to use (<s> = 444, 422, 440, 420, 411, or\n");
786 printf(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in\n");
787 printf(" sequence.\n");
788 printf("-quiet = Output results in tabular rather than verbose format\n");
789 printf("-yuv = Test YUV encoding/decoding functions\n");
790 printf("-yuvpad <p> = If testing YUV encoding/decoding, this specifies the number of\n");
791 printf(" bytes to which each row of each plane in the intermediate YUV image is\n");
792 printf(" padded (default = 1)\n");
793 printf("-scale M/N = Scale down the width/height of the decompressed JPEG image by a\n");
794 printf(" factor of M/N (M/N = ");
795 for (i = 0; i < nsf; i++) {
796 printf("%d/%d", scalingFactors[i].num, scalingFactors[i].denom);
797 if (nsf == 2 && i != nsf - 1) printf(" or ");
798 else if (nsf > 2) {
799 if (i != nsf - 1) printf(", ");
800 if (i == nsf - 2) printf("or ");
801 }
802 if (i % 8 == 0 && i != 0) printf("\n ");
803 }
804 printf(")\n");
805 printf("-hflip, -vflip, -transpose, -transverse, -rot90, -rot180, -rot270 =\n");
806 printf(" Perform the corresponding lossless transform prior to\n");
807 printf(" decompression (these options are mutually exclusive)\n");
808 printf("-grayscale = Perform lossless grayscale conversion prior to decompression\n");
809 printf(" test (can be combined with the other transforms above)\n");
810 printf("-copynone = Do not copy any extra markers (including EXIF and ICC profile data)\n");
811 printf(" when transforming the image.\n");
812 printf("-benchtime <t> = Run each benchmark for at least <t> seconds (default = 5.0)\n");
813 printf("-warmup <t> = Run each benchmark for <t> seconds (default = 1.0) prior to\n");
814 printf(" starting the timer, in order to prime the caches and thus improve the\n");
815 printf(" consistency of the results.\n");
816 printf("-componly = Stop after running compression tests. Do not test decompression.\n");
817 printf("-nowrite = Do not write reference or output images (improves consistency of\n");
818 printf(" performance measurements.)\n");
Jonathan Wright24e31052021-04-26 12:10:48 +0100819 printf("-limitscans = Refuse to decompress or transform progressive JPEG images that\n");
820 printf(" have an unreasonably large number of scans\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800821 printf("-stoponwarning = Immediately discontinue the current\n");
822 printf(" compression/decompression/transform operation if the underlying codec\n");
823 printf(" throws a warning (non-fatal error)\n\n");
824 printf("NOTE: If the quality is specified as a range (e.g. 90-100), a separate\n");
825 printf("test will be performed for all quality values in the range.\n\n");
826 exit(1);
hbono@chromium.org98626972011-08-03 03:13:08 +0000827}
828
Jonathan Wright285aa142020-06-12 15:14:35 +0100829#ifndef GTEST
hbono@chromium.org98626972011-08-03 03:13:08 +0000830int main(int argc, char *argv[])
Jonathan Wright285aa142020-06-12 15:14:35 +0100831#else
832int tjbench(int argc, char *argv[])
833#endif
hbono@chromium.org98626972011-08-03 03:13:08 +0000834{
Chris Blumecca8c4d2019-03-01 01:09:50 -0800835 unsigned char *srcBuf = NULL;
836 int w = 0, h = 0, i, j, minQual = -1, maxQual = -1;
837 char *temp;
838 int minArg = 2, retval = 0, subsamp = -1;
hbono@chromium.org98626972011-08-03 03:13:08 +0000839
Chris Blumecca8c4d2019-03-01 01:09:50 -0800840 if ((scalingFactors = tjGetScalingFactors(&nsf)) == NULL || nsf == 0)
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100841 THROW("executing tjGetScalingFactors()", tjGetErrorStr());
hbono@chromium.org98626972011-08-03 03:13:08 +0000842
Chris Blumecca8c4d2019-03-01 01:09:50 -0800843 if (argc < minArg) usage(argv[0]);
hbono@chromium.org98626972011-08-03 03:13:08 +0000844
Chris Blumecca8c4d2019-03-01 01:09:50 -0800845 temp = strrchr(argv[1], '.');
846 if (temp != NULL) {
847 if (!strcasecmp(temp, ".bmp")) ext = "bmp";
848 if (!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg"))
849 decompOnly = 1;
850 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000851
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100852 fprintf(stderr, "\n");
hbono@chromium.org98626972011-08-03 03:13:08 +0000853
Chris Blumecca8c4d2019-03-01 01:09:50 -0800854 if (!decompOnly) {
855 minArg = 3;
856 if (argc < minArg) usage(argv[0]);
857 if ((minQual = atoi(argv[2])) < 1 || minQual > 100) {
858 puts("ERROR: Quality must be between 1 and 100.");
859 exit(1);
860 }
861 if ((temp = strchr(argv[2], '-')) != NULL && strlen(temp) > 1 &&
862 sscanf(&temp[1], "%d", &maxQual) == 1 && maxQual > minQual &&
863 maxQual >= 1 && maxQual <= 100) {}
864 else maxQual = minQual;
865 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000866
Chris Blumecca8c4d2019-03-01 01:09:50 -0800867 if (argc > minArg) {
868 for (i = minArg; i < argc; i++) {
869 if (!strcasecmp(argv[i], "-tile")) {
870 doTile = 1; xformOpt |= TJXOPT_CROP;
871 } else if (!strcasecmp(argv[i], "-fastupsample")) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100872 fprintf(stderr, "Using fast upsampling code\n\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800873 flags |= TJFLAG_FASTUPSAMPLE;
874 } else if (!strcasecmp(argv[i], "-fastdct")) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100875 fprintf(stderr, "Using fastest DCT/IDCT algorithm\n\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800876 flags |= TJFLAG_FASTDCT;
877 } else if (!strcasecmp(argv[i], "-accuratedct")) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100878 fprintf(stderr, "Using most accurate DCT/IDCT algorithm\n\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800879 flags |= TJFLAG_ACCURATEDCT;
880 } else if (!strcasecmp(argv[i], "-progressive")) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100881 fprintf(stderr, "Using progressive entropy coding\n\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800882 flags |= TJFLAG_PROGRESSIVE;
883 } else if (!strcasecmp(argv[i], "-rgb"))
884 pf = TJPF_RGB;
885 else if (!strcasecmp(argv[i], "-rgbx"))
886 pf = TJPF_RGBX;
887 else if (!strcasecmp(argv[i], "-bgr"))
888 pf = TJPF_BGR;
889 else if (!strcasecmp(argv[i], "-bgrx"))
890 pf = TJPF_BGRX;
891 else if (!strcasecmp(argv[i], "-xbgr"))
892 pf = TJPF_XBGR;
893 else if (!strcasecmp(argv[i], "-xrgb"))
894 pf = TJPF_XRGB;
895 else if (!strcasecmp(argv[i], "-cmyk"))
896 pf = TJPF_CMYK;
897 else if (!strcasecmp(argv[i], "-bottomup"))
898 flags |= TJFLAG_BOTTOMUP;
899 else if (!strcasecmp(argv[i], "-quiet"))
900 quiet = 1;
901 else if (!strcasecmp(argv[i], "-qq"))
902 quiet = 2;
903 else if (!strcasecmp(argv[i], "-scale") && i < argc - 1) {
904 int temp1 = 0, temp2 = 0, match = 0;
hbono@chromium.org98626972011-08-03 03:13:08 +0000905
Chris Blumecca8c4d2019-03-01 01:09:50 -0800906 if (sscanf(argv[++i], "%d/%d", &temp1, &temp2) == 2) {
907 for (j = 0; j < nsf; j++) {
908 if ((double)temp1 / (double)temp2 ==
909 (double)scalingFactors[j].num /
910 (double)scalingFactors[j].denom) {
911 sf = scalingFactors[j];
912 match = 1; break;
913 }
914 }
915 if (!match) usage(argv[0]);
916 } else usage(argv[0]);
917 } else if (!strcasecmp(argv[i], "-hflip"))
918 xformOp = TJXOP_HFLIP;
919 else if (!strcasecmp(argv[i], "-vflip"))
920 xformOp = TJXOP_VFLIP;
921 else if (!strcasecmp(argv[i], "-transpose"))
922 xformOp = TJXOP_TRANSPOSE;
923 else if (!strcasecmp(argv[i], "-transverse"))
924 xformOp = TJXOP_TRANSVERSE;
925 else if (!strcasecmp(argv[i], "-rot90"))
926 xformOp = TJXOP_ROT90;
927 else if (!strcasecmp(argv[i], "-rot180"))
928 xformOp = TJXOP_ROT180;
929 else if (!strcasecmp(argv[i], "-rot270"))
930 xformOp = TJXOP_ROT270;
931 else if (!strcasecmp(argv[i], "-grayscale"))
932 xformOpt |= TJXOPT_GRAY;
933 else if (!strcasecmp(argv[i], "-custom"))
934 customFilter = dummyDCTFilter;
935 else if (!strcasecmp(argv[i], "-nooutput"))
936 xformOpt |= TJXOPT_NOOUTPUT;
937 else if (!strcasecmp(argv[i], "-copynone"))
938 xformOpt |= TJXOPT_COPYNONE;
939 else if (!strcasecmp(argv[i], "-benchtime") && i < argc - 1) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100940 double tempd = atof(argv[++i]);
hbono@chromium.org98626972011-08-03 03:13:08 +0000941
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100942 if (tempd > 0.0) benchTime = tempd;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800943 else usage(argv[0]);
944 } else if (!strcasecmp(argv[i], "-warmup") && i < argc - 1) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100945 double tempd = atof(argv[++i]);
hbono@chromium.org98626972011-08-03 03:13:08 +0000946
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100947 if (tempd >= 0.0) warmup = tempd;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800948 else usage(argv[0]);
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100949 fprintf(stderr, "Warmup time = %.1f seconds\n\n", warmup);
Chris Blumecca8c4d2019-03-01 01:09:50 -0800950 } else if (!strcasecmp(argv[i], "-alloc"))
951 flags &= (~TJFLAG_NOREALLOC);
952 else if (!strcasecmp(argv[i], "-bmp"))
953 ext = "bmp";
954 else if (!strcasecmp(argv[i], "-yuv")) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100955 fprintf(stderr, "Testing YUV planar encoding/decoding\n\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800956 doYUV = 1;
957 } else if (!strcasecmp(argv[i], "-yuvpad") && i < argc - 1) {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100958 int tempi = atoi(argv[++i]);
hbono@chromium.org98626972011-08-03 03:13:08 +0000959
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100960 if (tempi >= 1) yuvPad = tempi;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800961 } else if (!strcasecmp(argv[i], "-subsamp") && i < argc - 1) {
962 i++;
963 if (toupper(argv[i][0]) == 'G') subsamp = TJSAMP_GRAY;
964 else {
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100965 int tempi = atoi(argv[i]);
hbono@chromium.org98626972011-08-03 03:13:08 +0000966
Jonathan Wrightdb870df2020-08-05 11:42:22 +0100967 switch (tempi) {
Chris Blumecca8c4d2019-03-01 01:09:50 -0800968 case 444: subsamp = TJSAMP_444; break;
969 case 422: subsamp = TJSAMP_422; break;
970 case 440: subsamp = TJSAMP_440; break;
971 case 420: subsamp = TJSAMP_420; break;
972 case 411: subsamp = TJSAMP_411; break;
973 }
974 }
975 } else if (!strcasecmp(argv[i], "-componly"))
976 compOnly = 1;
977 else if (!strcasecmp(argv[i], "-nowrite"))
978 doWrite = 0;
Jonathan Wright24e31052021-04-26 12:10:48 +0100979 else if (!strcasecmp(argv[i], "-limitscans"))
980 flags |= TJFLAG_LIMITSCANS;
Chris Blumecca8c4d2019-03-01 01:09:50 -0800981 else if (!strcasecmp(argv[i], "-stoponwarning"))
982 flags |= TJFLAG_STOPONWARNING;
983 else usage(argv[0]);
984 }
985 }
hbono@chromium.org98626972011-08-03 03:13:08 +0000986
Chris Blumecca8c4d2019-03-01 01:09:50 -0800987 if ((sf.num != 1 || sf.denom != 1) && doTile) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100988 fprintf(stderr, "Disabling tiled compression/decompression tests, because those tests do not\n");
989 fprintf(stderr, "work when scaled decompression is enabled.\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800990 doTile = 0;
991 }
992
993 if ((flags & TJFLAG_NOREALLOC) == 0 && doTile) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +0100994 fprintf(stderr, "Disabling tiled compression/decompression tests, because those tests do not\n");
995 fprintf(stderr, "work when dynamic JPEG buffer allocation is enabled.\n\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -0800996 doTile = 0;
997 }
998
999 if (!decompOnly) {
1000 if ((srcBuf = tjLoadImage(argv[1], &w, 1, &h, &pf, flags)) == NULL)
Jonathan Wrightdb870df2020-08-05 11:42:22 +01001001 THROW_TJG("loading bitmap");
Chris Blumecca8c4d2019-03-01 01:09:50 -08001002 temp = strrchr(argv[1], '.');
1003 if (temp != NULL) *temp = '\0';
1004 }
1005
1006 if (quiet == 1 && !decompOnly) {
Jonathan Wright681ce7f2020-06-12 18:20:50 +01001007 fprintf(stderr, "All performance values in Mpixels/sec\n\n");
1008 fprintf(stderr, "Bitmap JPEG JPEG %s %s ",
1009 doTile ? "Tile " : "Image", doTile ? "Tile " : "Image");
1010 if (doYUV) fprintf(stderr, "Encode ");
1011 fprintf(stderr, "Comp Comp Decomp ");
1012 if (doYUV) fprintf(stderr, "Decode");
1013 fprintf(stderr, "\n");
1014 fprintf(stderr, "Format Subsamp Qual Width Height ");
1015 if (doYUV) fprintf(stderr, "Perf ");
1016 fprintf(stderr, "Perf Ratio Perf ");
1017 if (doYUV) fprintf(stderr, "Perf");
1018 fprintf(stderr, "\n\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -08001019 }
1020
1021 if (decompOnly) {
1022 decompTest(argv[1]);
Jonathan Wright681ce7f2020-06-12 18:20:50 +01001023 fprintf(stderr, "\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -08001024 goto bailout;
1025 }
1026 if (subsamp >= 0 && subsamp < TJ_NUMSAMP) {
1027 for (i = maxQual; i >= minQual; i--)
1028 fullTest(srcBuf, w, h, subsamp, i, argv[1]);
Jonathan Wright681ce7f2020-06-12 18:20:50 +01001029 fprintf(stderr, "\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -08001030 } else {
1031 if (pf != TJPF_CMYK) {
1032 for (i = maxQual; i >= minQual; i--)
1033 fullTest(srcBuf, w, h, TJSAMP_GRAY, i, argv[1]);
Jonathan Wright681ce7f2020-06-12 18:20:50 +01001034 fprintf(stderr, "\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -08001035 }
1036 for (i = maxQual; i >= minQual; i--)
1037 fullTest(srcBuf, w, h, TJSAMP_420, i, argv[1]);
Jonathan Wright681ce7f2020-06-12 18:20:50 +01001038 fprintf(stderr, "\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -08001039 for (i = maxQual; i >= minQual; i--)
1040 fullTest(srcBuf, w, h, TJSAMP_422, i, argv[1]);
Jonathan Wright681ce7f2020-06-12 18:20:50 +01001041 fprintf(stderr, "\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -08001042 for (i = maxQual; i >= minQual; i--)
1043 fullTest(srcBuf, w, h, TJSAMP_444, i, argv[1]);
Jonathan Wright681ce7f2020-06-12 18:20:50 +01001044 fprintf(stderr, "\n");
Chris Blumecca8c4d2019-03-01 01:09:50 -08001045 }
1046
1047bailout:
Jonathan Wrightdb870df2020-08-05 11:42:22 +01001048 tjFree(srcBuf);
Chris Blumecca8c4d2019-03-01 01:09:50 -08001049 return retval;
hbono@chromium.org98626972011-08-03 03:13:08 +00001050}