Bump to 2.0.6
[platform/upstream/libjpeg-turbo.git] / tjbench.c
1 /*
2  * Copyright (C)2009-2019 D. R. Commander.  All Rights Reserved.
3  *
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>
32 #include <ctype.h>
33 #include <math.h>
34 #include <errno.h>
35 #include <limits.h>
36 #include <cdjpeg.h>
37 #include "./tjutil.h"
38 #include "./turbojpeg.h"
39
40
41 #define THROW(op, err) { \
42   printf("ERROR in line %d while %s:\n%s\n", __LINE__, op, err); \
43   retval = -1;  goto bailout; \
44 }
45
46 #if _USE_PRODUCT_TV
47 #define THROW_UNIX(m) { \
48         char err_str[256]; \
49         strerror_r(errno, err_str, 256); \
50         THROW(m, err_str) \
51 }
52 #else
53 #define THROW_UNIX(m)  THROW(m, strerror(errno))
54 #endif
55
56 char tjErrorStr[JMSG_LENGTH_MAX] = "\0", tjErrorMsg[JMSG_LENGTH_MAX] = "\0";
57 int tjErrorLine = -1, tjErrorCode = -1;
58
59 #define THROW_TJG(m) { \
60   printf("ERROR in line %d while %s:\n%s\n", __LINE__, m, \
61          tjGetErrorStr2(NULL)); \
62   retval = -1;  goto bailout; \
63 }
64
65 #define THROW_TJ(m) { \
66   int _tjErrorCode = tjGetErrorCode(handle); \
67   char *_tjErrorStr = tjGetErrorStr2(handle); \
68   \
69   if (!(flags & TJFLAG_STOPONWARNING) && _tjErrorCode == TJERR_WARNING) { \
70     if (strncmp(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX) || \
71         strncmp(tjErrorMsg, m, JMSG_LENGTH_MAX) || \
72         tjErrorCode != _tjErrorCode || tjErrorLine != __LINE__) { \
73       strncpy(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX - 1); \
74       strncpy(tjErrorMsg, m, JMSG_LENGTH_MAX - 1); \
75       tjErrorCode = _tjErrorCode; \
76       tjErrorLine = __LINE__; \
77       printf("WARNING in line %d while %s:\n%s\n", __LINE__, m, _tjErrorStr); \
78     } \
79   } else { \
80     printf("%s in line %d while %s:\n%s\n", \
81            _tjErrorCode == TJERR_WARNING ? "WARNING" : "ERROR", __LINE__, m, \
82            _tjErrorStr); \
83     retval = -1;  goto bailout; \
84   } \
85 }
86
87 int flags = TJFLAG_NOREALLOC, compOnly = 0, decompOnly = 0, doYUV = 0,
88   quiet = 0, doTile = 0, pf = TJPF_BGR, yuvPad = 1, doWrite = 1;
89 char *ext = "ppm";
90 const char *pixFormatStr[TJ_NUMPF] = {
91   "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY", "", "", "", "", "CMYK"
92 };
93 const char *subNameLong[TJ_NUMSAMP] = {
94   "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1"
95 };
96 const char *csName[TJ_NUMCS] = {
97   "RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
98 };
99 const char *subName[TJ_NUMSAMP] = {
100   "444", "422", "420", "GRAY", "440", "411"
101 };
102 tjscalingfactor *scalingFactors = NULL, sf = { 1, 1 };
103 int nsf = 0, xformOp = TJXOP_NONE, xformOpt = 0;
104 int (*customFilter) (short *, tjregion, tjregion, int, int, tjtransform *);
105 double benchTime = 5.0, warmup = 1.0;
106
107
108 static char *formatName(int subsamp, int cs, char *buf)
109 {
110   if (cs == TJCS_YCbCr)
111     return (char *)subNameLong[subsamp];
112   else if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
113     snprintf(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
114     return buf;
115   } else
116     return (char *)csName[cs];
117 }
118
119
120 static char *sigfig(double val, int figs, char *buf, int len)
121 {
122   char format[80];
123   int digitsAfterDecimal = figs - (int)ceil(log10(fabs(val)));
124
125   if (digitsAfterDecimal < 1)
126     snprintf(format, 80, "%%.0f");
127   else
128     snprintf(format, 80, "%%.%df", digitsAfterDecimal);
129   snprintf(buf, len, format, val);
130   return buf;
131 }
132
133
134 /* Custom DCT filter which produces a negative of the image */
135 static int dummyDCTFilter(short *coeffs, tjregion arrayRegion,
136                           tjregion planeRegion, int componentIndex,
137                           int transformIndex, tjtransform *transform)
138 {
139   int i;
140
141   for (i = 0; i < arrayRegion.w * arrayRegion.h; i++)
142     coeffs[i] = -coeffs[i];
143   return 0;
144 }
145
146
147 /* Decompression test */
148 static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
149                   unsigned long *jpegSize, unsigned char *dstBuf, int w, int h,
150                   int subsamp, int jpegQual, char *fileName, int tilew,
151                   int tileh)
152 {
153   char tempStr[1024], sizeStr[24] = "\0", qualStr[13] = "\0", *ptr;
154   FILE *file = NULL;
155   tjhandle handle = NULL;
156   int row, col, iter = 0, dstBufAlloc = 0, retval = 0;
157   double elapsed, elapsedDecode;
158   int ps = tjPixelSize[pf];
159   int scaledw = TJSCALED(w, sf);
160   int scaledh = TJSCALED(h, sf);
161   int pitch = scaledw * ps;
162   int ntilesw = (w + tilew - 1) / tilew, ntilesh = (h + tileh - 1) / tileh;
163   unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
164
165   if (jpegQual > 0) {
166     snprintf(qualStr, 13, "_Q%d", jpegQual);
167     qualStr[12] = 0;
168   }
169
170   if ((handle = tjInitDecompress()) == NULL)
171     THROW_TJ("executing tjInitDecompress()");
172
173   if (dstBuf == NULL) {
174     if ((unsigned long long)pitch * (unsigned long long)scaledh >
175         (unsigned long long)((size_t)-1))
176       THROW("allocating destination buffer", "Image is too large");
177     if ((dstBuf = (unsigned char *)malloc((size_t)pitch * scaledh)) == NULL)
178       THROW_UNIX("allocating destination buffer");
179     dstBufAlloc = 1;
180   }
181   /* Set the destination buffer to gray so we know whether the decompressor
182      attempted to write to it */
183   memset(dstBuf, 127, (size_t)pitch * scaledh);
184
185   if (doYUV) {
186     int width = doTile ? tilew : scaledw;
187     int height = doTile ? tileh : scaledh;
188     unsigned long yuvSize = tjBufSizeYUV2(width, yuvPad, height, subsamp);
189
190     if (yuvSize == (unsigned long)-1)
191       THROW_TJ("allocating YUV buffer");
192     if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
193       THROW_UNIX("allocating YUV buffer");
194     memset(yuvBuf, 127, yuvSize);
195   }
196
197   /* Benchmark */
198   iter = -1;
199   elapsed = elapsedDecode = 0.;
200   while (1) {
201     int tile = 0;
202     double start = getTime();
203
204     for (row = 0, dstPtr = dstBuf; row < ntilesh;
205          row++, dstPtr += (size_t)pitch * tileh) {
206       for (col = 0, dstPtr2 = dstPtr; col < ntilesw;
207            col++, tile++, dstPtr2 += ps * tilew) {
208         int width = doTile ? min(tilew, w - col * tilew) : scaledw;
209         int height = doTile ? min(tileh, h - row * tileh) : scaledh;
210
211         if (doYUV) {
212           double startDecode;
213
214           if (tjDecompressToYUV2(handle, jpegBuf[tile], jpegSize[tile], yuvBuf,
215                                  width, yuvPad, height, flags) == -1)
216             THROW_TJ("executing tjDecompressToYUV2()");
217           startDecode = getTime();
218           if (tjDecodeYUV(handle, yuvBuf, yuvPad, subsamp, dstPtr2, width,
219                           pitch, height, pf, flags) == -1)
220             THROW_TJ("executing tjDecodeYUV()");
221           if (iter >= 0) elapsedDecode += getTime() - startDecode;
222         } else if (tjDecompress2(handle, jpegBuf[tile], jpegSize[tile],
223                                  dstPtr2, width, pitch, height, pf,
224                                  flags) == -1)
225           THROW_TJ("executing tjDecompress2()");
226       }
227     }
228     elapsed += getTime() - start;
229     if (iter >= 0) {
230       iter++;
231       if (elapsed >= benchTime) break;
232     } else if (elapsed >= warmup) {
233       iter = 0;
234       elapsed = elapsedDecode = 0.;
235     }
236   }
237   if (doYUV) elapsed -= elapsedDecode;
238
239   if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
240   handle = NULL;
241
242   if (quiet) {
243     printf("%-6s%s",
244            sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
245                   tempStr, 1024),
246            quiet == 2 ? "\n" : "  ");
247     if (doYUV)
248       printf("%s\n",
249              sigfig((double)(w * h) / 1000000. * (double)iter / elapsedDecode,
250                     4, tempStr, 1024));
251     else if (quiet != 2) printf("\n");
252   } else {
253     printf("%s --> Frame rate:         %f fps\n",
254            doYUV ? "Decomp to YUV" : "Decompress   ", (double)iter / elapsed);
255     printf("                  Throughput:         %f Megapixels/sec\n",
256            (double)(w * h) / 1000000. * (double)iter / elapsed);
257     if (doYUV) {
258       printf("YUV Decode    --> Frame rate:         %f fps\n",
259              (double)iter / elapsedDecode);
260       printf("                  Throughput:         %f Megapixels/sec\n",
261              (double)(w * h) / 1000000. * (double)iter / elapsedDecode);
262     }
263   }
264
265   if (!doWrite) goto bailout;
266
267   if (sf.num != 1 || sf.denom != 1)
268     snprintf(sizeStr, 24, "%d_%d", sf.num, sf.denom);
269   else if (tilew != w || tileh != h)
270     snprintf(sizeStr, 24, "%dx%d", tilew, tileh);
271   else snprintf(sizeStr, 24, "full");
272   if (decompOnly)
273     snprintf(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
274   else
275     snprintf(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
276              qualStr, sizeStr, ext);
277
278   if (tjSaveImage(tempStr, dstBuf, scaledw, 0, scaledh, pf, flags) == -1)
279     THROW_TJG("saving bitmap");
280   ptr = strrchr(tempStr, '.');
281   snprintf(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
282   if (srcBuf && sf.num == 1 && sf.denom == 1) {
283     if (!quiet) printf("Compression error written to %s.\n", tempStr);
284     if (subsamp == TJ_GRAYSCALE) {
285       unsigned long index, index2;
286
287       for (row = 0, index = 0; row < h; row++, index += pitch) {
288         for (col = 0, index2 = index; col < w; col++, index2 += ps) {
289           unsigned long rindex = index2 + tjRedOffset[pf];
290           unsigned long gindex = index2 + tjGreenOffset[pf];
291           unsigned long bindex = index2 + tjBlueOffset[pf];
292           int y = (int)((double)srcBuf[rindex] * 0.299 +
293                         (double)srcBuf[gindex] * 0.587 +
294                         (double)srcBuf[bindex] * 0.114 + 0.5);
295
296           if (y > 255) y = 255;
297           if (y < 0) y = 0;
298           dstBuf[rindex] = abs(dstBuf[rindex] - y);
299           dstBuf[gindex] = abs(dstBuf[gindex] - y);
300           dstBuf[bindex] = abs(dstBuf[bindex] - y);
301         }
302       }
303     } else {
304       for (row = 0; row < h; row++)
305         for (col = 0; col < w * ps; col++)
306           dstBuf[pitch * row + col] =
307             abs(dstBuf[pitch * row + col] - srcBuf[pitch * row + col]);
308     }
309     if (tjSaveImage(tempStr, dstBuf, w, 0, h, pf, flags) == -1)
310       THROW_TJG("saving bitmap");
311   }
312
313 bailout:
314   if (file) fclose(file);
315   if (handle) tjDestroy(handle);
316   if (dstBufAlloc) free(dstBuf);
317   free(yuvBuf);
318   return retval;
319 }
320
321
322 static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
323                     int jpegQual, char *fileName)
324 {
325   char tempStr[1024], tempStr2[80];
326   FILE *file = NULL;
327   tjhandle handle = NULL;
328   unsigned char **jpegBuf = NULL, *yuvBuf = NULL, *tmpBuf = NULL, *srcPtr,
329     *srcPtr2;
330   double start, elapsed, elapsedEncode;
331   int totalJpegSize = 0, row, col, i, tilew = w, tileh = h, retval = 0;
332   int iter;
333   unsigned long *jpegSize = NULL, yuvSize = 0;
334   int ps = tjPixelSize[pf];
335   int ntilesw = 1, ntilesh = 1, pitch = w * ps;
336   const char *pfStr = pixFormatStr[pf];
337
338   if ((unsigned long long)pitch * (unsigned long long)h >
339       (unsigned long long)((size_t)-1))
340     THROW("allocating temporary image buffer", "Image is too large");
341   if ((tmpBuf = (unsigned char *)malloc((size_t)pitch * h)) == NULL)
342     THROW_UNIX("allocating temporary image buffer");
343
344   if (!quiet)
345     printf(">>>>>  %s (%s) <--> JPEG %s Q%d  <<<<<\n", pfStr,
346            (flags & TJFLAG_BOTTOMUP) ? "Bottom-up" : "Top-down",
347            subNameLong[subsamp], jpegQual);
348
349   for (tilew = doTile ? 8 : w, tileh = doTile ? 8 : h; ;
350        tilew *= 2, tileh *= 2) {
351     if (tilew > w) tilew = w;
352     if (tileh > h) tileh = h;
353     ntilesw = (w + tilew - 1) / tilew;
354     ntilesh = (h + tileh - 1) / tileh;
355
356     if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
357                                             ntilesw * ntilesh)) == NULL)
358       THROW_UNIX("allocating JPEG tile array");
359     memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
360     if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
361                                             ntilesw * ntilesh)) == NULL)
362       THROW_UNIX("allocating JPEG size array");
363     memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
364
365     if ((flags & TJFLAG_NOREALLOC) != 0)
366       for (i = 0; i < ntilesw * ntilesh; i++) {
367         if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
368           THROW("getting buffer size", "Image is too large");
369         if ((jpegBuf[i] = (unsigned char *)
370                           tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
371           THROW_UNIX("allocating JPEG tiles");
372       }
373
374     /* Compression test */
375     if (quiet == 1)
376       printf("%-4s (%s)  %-5s    %-3d   ", pfStr,
377              (flags & TJFLAG_BOTTOMUP) ? "BU" : "TD", subNameLong[subsamp],
378              jpegQual);
379     for (i = 0; i < h; i++)
380       memcpy(&tmpBuf[pitch * i], &srcBuf[w * ps * i], w * ps);
381     if ((handle = tjInitCompress()) == NULL)
382       THROW_TJ("executing tjInitCompress()");
383
384     if (doYUV) {
385       yuvSize = tjBufSizeYUV2(tilew, yuvPad, tileh, subsamp);
386       if (yuvSize == (unsigned long)-1)
387         THROW_TJ("allocating YUV buffer");
388       if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL)
389         THROW_UNIX("allocating YUV buffer");
390       memset(yuvBuf, 127, yuvSize);
391     }
392
393     /* Benchmark */
394     iter = -1;
395     elapsed = elapsedEncode = 0.;
396     while (1) {
397       int tile = 0;
398
399       totalJpegSize = 0;
400       start = getTime();
401       for (row = 0, srcPtr = srcBuf; row < ntilesh;
402            row++, srcPtr += pitch * tileh) {
403         for (col = 0, srcPtr2 = srcPtr; col < ntilesw;
404              col++, tile++, srcPtr2 += ps * tilew) {
405           int width = min(tilew, w - col * tilew);
406           int height = min(tileh, h - row * tileh);
407
408           if (doYUV) {
409             double startEncode = getTime();
410
411             if (tjEncodeYUV3(handle, srcPtr2, width, pitch, height, pf, yuvBuf,
412                              yuvPad, subsamp, flags) == -1)
413               THROW_TJ("executing tjEncodeYUV3()");
414             if (iter >= 0) elapsedEncode += getTime() - startEncode;
415             if (tjCompressFromYUV(handle, yuvBuf, width, yuvPad, height,
416                                   subsamp, &jpegBuf[tile], &jpegSize[tile],
417                                   jpegQual, flags) == -1)
418               THROW_TJ("executing tjCompressFromYUV()");
419           } else {
420             if (tjCompress2(handle, srcPtr2, width, pitch, height, pf,
421                             &jpegBuf[tile], &jpegSize[tile], subsamp, jpegQual,
422                             flags) == -1)
423               THROW_TJ("executing tjCompress2()");
424           }
425           totalJpegSize += jpegSize[tile];
426         }
427       }
428       elapsed += getTime() - start;
429       if (iter >= 0) {
430         iter++;
431         if (elapsed >= benchTime) break;
432       } else if (elapsed >= warmup) {
433         iter = 0;
434         elapsed = elapsedEncode = 0.;
435       }
436     }
437     if (doYUV) elapsed -= elapsedEncode;
438
439     if (tjDestroy(handle) == -1) THROW_TJ("executing tjDestroy()");
440     handle = NULL;
441
442     if (quiet == 1) printf("%-5d  %-5d   ", tilew, tileh);
443     if (quiet) {
444       if (doYUV)
445         printf("%-6s%s",
446                sigfig((double)(w * h) / 1000000. *
447                       (double)iter / elapsedEncode, 4, tempStr, 1024),
448                quiet == 2 ? "\n" : "  ");
449       printf("%-6s%s",
450              sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4,
451                     tempStr, 1024),
452              quiet == 2 ? "\n" : "  ");
453       printf("%-6s%s",
454              sigfig((double)(w * h * ps) / (double)totalJpegSize, 4, tempStr2,
455                     80),
456              quiet == 2 ? "\n" : "  ");
457     } else {
458       printf("\n%s size: %d x %d\n", doTile ? "Tile" : "Image", tilew, tileh);
459       if (doYUV) {
460         printf("Encode YUV    --> Frame rate:         %f fps\n",
461                (double)iter / elapsedEncode);
462         printf("                  Output image size:  %lu bytes\n", yuvSize);
463         printf("                  Compression ratio:  %f:1\n",
464                (double)(w * h * ps) / (double)yuvSize);
465         printf("                  Throughput:         %f Megapixels/sec\n",
466                (double)(w * h) / 1000000. * (double)iter / elapsedEncode);
467         printf("                  Output bit stream:  %f Megabits/sec\n",
468                (double)yuvSize * 8. / 1000000. * (double)iter / elapsedEncode);
469       }
470       printf("%s --> Frame rate:         %f fps\n",
471              doYUV ? "Comp from YUV" : "Compress     ",
472              (double)iter / elapsed);
473       printf("                  Output image size:  %d bytes\n",
474              totalJpegSize);
475       printf("                  Compression ratio:  %f:1\n",
476              (double)(w * h * ps) / (double)totalJpegSize);
477       printf("                  Throughput:         %f Megapixels/sec\n",
478              (double)(w * h) / 1000000. * (double)iter / elapsed);
479       printf("                  Output bit stream:  %f Megabits/sec\n",
480              (double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed);
481     }
482     if (tilew == w && tileh == h && doWrite) {
483       snprintf(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
484                jpegQual);
485       if ((file = fopen(tempStr, "wb")) == NULL)
486         THROW_UNIX("opening reference image");
487       if (fwrite(jpegBuf[0], jpegSize[0], 1, file) != 1)
488         THROW_UNIX("writing reference image");
489       fclose(file);  file = NULL;
490       if (!quiet) printf("Reference image written to %s\n", tempStr);
491     }
492
493     /* Decompression test */
494     if (!compOnly) {
495       if (decomp(srcBuf, jpegBuf, jpegSize, tmpBuf, w, h, subsamp, jpegQual,
496                  fileName, tilew, tileh) == -1)
497         goto bailout;
498     } else if (quiet == 1) printf("N/A\n");
499
500     for (i = 0; i < ntilesw * ntilesh; i++) {
501       tjFree(jpegBuf[i]);
502       jpegBuf[i] = NULL;
503     }
504     free(jpegBuf);  jpegBuf = NULL;
505     free(jpegSize);  jpegSize = NULL;
506     if (doYUV) {
507       free(yuvBuf);  yuvBuf = NULL;
508     }
509
510     if (tilew == w && tileh == h) break;
511   }
512
513 bailout:
514   if (file) fclose(file);
515   if (jpegBuf) {
516     for (i = 0; i < ntilesw * ntilesh; i++)
517       tjFree(jpegBuf[i]);
518   }
519   free(jpegBuf);
520   free(yuvBuf);
521   free(jpegSize);
522   free(tmpBuf);
523   if (handle) tjDestroy(handle);
524   return retval;
525 }
526
527
528 static int decompTest(char *fileName)
529 {
530   FILE *file = NULL;
531   tjhandle handle = NULL;
532   unsigned char **jpegBuf = NULL, *srcBuf = NULL;
533   unsigned long *jpegSize = NULL, srcSize, totalJpegSize;
534   tjtransform *t = NULL;
535   double start, elapsed;
536   int ps = tjPixelSize[pf], tile, row, col, i, iter, retval = 0, decompsrc = 0;
537   char *temp = NULL, tempStr[80], tempStr2[80];
538   /* Original image */
539   int w = 0, h = 0, tilew, tileh, ntilesw = 1, ntilesh = 1, subsamp = -1,
540     cs = -1;
541   /* Transformed image */
542   int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
543
544   if ((file = fopen(fileName, "rb")) == NULL)
545     THROW_UNIX("opening file");
546   if (fseek(file, 0, SEEK_END) < 0 ||
547       (srcSize = ftell(file)) == (unsigned long)-1)
548     THROW_UNIX("determining file size");
549   if ((srcBuf = (unsigned char *)malloc(srcSize)) == NULL)
550     THROW_UNIX("allocating memory");
551   if (fseek(file, 0, SEEK_SET) < 0)
552     THROW_UNIX("setting file position");
553   if (fread(srcBuf, srcSize, 1, file) < 1)
554     THROW_UNIX("reading JPEG data");
555   fclose(file);  file = NULL;
556
557   temp = strrchr(fileName, '.');
558   if (temp != NULL) *temp = '\0';
559
560   if ((handle = tjInitTransform()) == NULL)
561     THROW_TJ("executing tjInitTransform()");
562   if (tjDecompressHeader3(handle, srcBuf, srcSize, &w, &h, &subsamp,
563                           &cs) == -1)
564     THROW_TJ("executing tjDecompressHeader3()");
565   if (w < 1 || h < 1)
566     THROW("reading JPEG header", "Invalid image dimensions");
567   if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
568     pf = TJPF_CMYK;  ps = tjPixelSize[pf];
569   }
570
571   if (quiet == 1) {
572     printf("All performance values in Mpixels/sec\n\n");
573     printf("Bitmap     JPEG   JPEG     %s  %s   Xform   Comp    Decomp  ",
574            doTile ? "Tile " : "Image", doTile ? "Tile " : "Image");
575     if (doYUV) printf("Decode");
576     printf("\n");
577     printf("Format     CS     Subsamp  Width  Height  Perf    Ratio   Perf    ");
578     if (doYUV) printf("Perf");
579     printf("\n\n");
580   } else if (!quiet)
581     printf(">>>>>  JPEG %s --> %s (%s)  <<<<<\n",
582            formatName(subsamp, cs, tempStr), pixFormatStr[pf],
583            (flags & TJFLAG_BOTTOMUP) ? "Bottom-up" : "Top-down");
584
585   for (tilew = doTile ? 16 : w, tileh = doTile ? 16 : h; ;
586        tilew *= 2, tileh *= 2) {
587     if (tilew > w) tilew = w;
588     if (tileh > h) tileh = h;
589     ntilesw = (w + tilew - 1) / tilew;
590     ntilesh = (h + tileh - 1) / tileh;
591
592     if ((jpegBuf = (unsigned char **)malloc(sizeof(unsigned char *) *
593                                             ntilesw * ntilesh)) == NULL)
594       THROW_UNIX("allocating JPEG tile array");
595     memset(jpegBuf, 0, sizeof(unsigned char *) * ntilesw * ntilesh);
596     if ((jpegSize = (unsigned long *)malloc(sizeof(unsigned long) *
597                                             ntilesw * ntilesh)) == NULL)
598       THROW_UNIX("allocating JPEG size array");
599     memset(jpegSize, 0, sizeof(unsigned long) * ntilesw * ntilesh);
600
601     if ((flags & TJFLAG_NOREALLOC) != 0 &&
602         (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter))
603       for (i = 0; i < ntilesw * ntilesh; i++) {
604         if (tjBufSize(tilew, tileh, subsamp) > (unsigned long)INT_MAX)
605           THROW("getting buffer size", "Image is too large");
606         if ((jpegBuf[i] = (unsigned char *)
607                           tjAlloc(tjBufSize(tilew, tileh, subsamp))) == NULL)
608           THROW_UNIX("allocating JPEG tiles");
609       }
610
611     tw = w;  th = h;  ttilew = tilew;  ttileh = tileh;
612     if (!quiet) {
613       printf("\n%s size: %d x %d", doTile ? "Tile" : "Image", ttilew, ttileh);
614       if (sf.num != 1 || sf.denom != 1)
615         printf(" --> %d x %d", TJSCALED(tw, sf), TJSCALED(th, sf));
616       printf("\n");
617     } else if (quiet == 1) {
618       printf("%-4s (%s)  %-5s  %-5s    ", pixFormatStr[pf],
619              (flags & TJFLAG_BOTTOMUP) ? "BU" : "TD", csName[cs],
620              subNameLong[subsamp]);
621       printf("%-5d  %-5d   ", tilew, tileh);
622     }
623
624     tsubsamp = subsamp;
625     if (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter) {
626       if ((t = (tjtransform *)malloc(sizeof(tjtransform) * ntilesw *
627                                      ntilesh)) == NULL)
628         THROW_UNIX("allocating image transform array");
629
630       if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
631           xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
632         tw = h;  th = w;  ttilew = tileh;  ttileh = tilew;
633       }
634
635       if (xformOpt & TJXOPT_GRAY) tsubsamp = TJ_GRAYSCALE;
636       if (xformOp == TJXOP_HFLIP || xformOp == TJXOP_ROT180)
637         tw = tw - (tw % tjMCUWidth[tsubsamp]);
638       if (xformOp == TJXOP_VFLIP || xformOp == TJXOP_ROT180)
639         th = th - (th % tjMCUHeight[tsubsamp]);
640       if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT90)
641         tw = tw - (tw % tjMCUHeight[tsubsamp]);
642       if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT270)
643         th = th - (th % tjMCUWidth[tsubsamp]);
644       tntilesw = (tw + ttilew - 1) / ttilew;
645       tntilesh = (th + ttileh - 1) / ttileh;
646
647       if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
648           xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
649         if (tsubsamp == TJSAMP_422) tsubsamp = TJSAMP_440;
650         else if (tsubsamp == TJSAMP_440) tsubsamp = TJSAMP_422;
651       }
652
653       for (row = 0, tile = 0; row < tntilesh; row++) {
654         for (col = 0; col < tntilesw; col++, tile++) {
655           t[tile].r.w = min(ttilew, tw - col * ttilew);
656           t[tile].r.h = min(ttileh, th - row * ttileh);
657           t[tile].r.x = col * ttilew;
658           t[tile].r.y = row * ttileh;
659           t[tile].op = xformOp;
660           t[tile].options = xformOpt | TJXOPT_TRIM;
661           t[tile].customFilter = customFilter;
662           if (t[tile].options & TJXOPT_NOOUTPUT && jpegBuf[tile]) {
663             tjFree(jpegBuf[tile]);  jpegBuf[tile] = NULL;
664           }
665         }
666       }
667
668       iter = -1;
669       elapsed = 0.;
670       while (1) {
671         start = getTime();
672         if (tjTransform(handle, srcBuf, srcSize, tntilesw * tntilesh, jpegBuf,
673                         jpegSize, t, flags) == -1)
674           THROW_TJ("executing tjTransform()");
675         elapsed += getTime() - start;
676         if (iter >= 0) {
677           iter++;
678           if (elapsed >= benchTime) break;
679         } else if (elapsed >= warmup) {
680           iter = 0;
681           elapsed = 0.;
682         }
683       }
684
685       free(t);  t = NULL;
686
687       for (tile = 0, totalJpegSize = 0; tile < tntilesw * tntilesh; tile++)
688         totalJpegSize += jpegSize[tile];
689
690       if (quiet) {
691         printf("%-6s%s%-6s%s",
692                sigfig((double)(w * h) / 1000000. / elapsed, 4, tempStr, 80),
693                quiet == 2 ? "\n" : "  ",
694                sigfig((double)(w * h * ps) / (double)totalJpegSize, 4,
695                       tempStr2, 80),
696                quiet == 2 ? "\n" : "  ");
697       } else if (!quiet) {
698         printf("Transform     --> Frame rate:         %f fps\n",
699                1.0 / elapsed);
700         printf("                  Output image size:  %lu bytes\n",
701                totalJpegSize);
702         printf("                  Compression ratio:  %f:1\n",
703                (double)(w * h * ps) / (double)totalJpegSize);
704         printf("                  Throughput:         %f Megapixels/sec\n",
705                (double)(w * h) / 1000000. / elapsed);
706         printf("                  Output bit stream:  %f Megabits/sec\n",
707                (double)totalJpegSize * 8. / 1000000. / elapsed);
708       }
709     } else {
710       if (quiet == 1) printf("N/A     N/A     ");
711       tjFree(jpegBuf[0]);
712       jpegBuf[0] = NULL;
713       decompsrc = 1;
714     }
715
716     if (w == tilew) ttilew = tw;
717     if (h == tileh) ttileh = th;
718     if (!(xformOpt & TJXOPT_NOOUTPUT)) {
719       if (decomp(NULL, decompsrc ? &srcBuf : jpegBuf,
720                  decompsrc ? &srcSize : jpegSize, NULL, tw, th, tsubsamp, 0,
721                  fileName, ttilew, ttileh) == -1)
722         goto bailout;
723     } else if (quiet == 1) printf("N/A\n");
724
725     for (i = 0; i < ntilesw * ntilesh; i++) {
726       tjFree(jpegBuf[i]);
727       jpegBuf[i] = NULL;
728     }
729     free(jpegBuf);  jpegBuf = NULL;
730     free(jpegSize);  jpegSize = NULL;
731
732     if (tilew == w && tileh == h) break;
733   }
734
735 bailout:
736   if (file) fclose(file);
737   if (jpegBuf) {
738     for (i = 0; i < ntilesw * ntilesh; i++)
739       tjFree(jpegBuf[i]);
740   }
741   free(jpegBuf);
742   free(jpegSize);
743   free(srcBuf);
744   free(t);
745   if (handle) { tjDestroy(handle);  handle = NULL; }
746   return retval;
747 }
748
749
750 static void usage(char *progName)
751 {
752   int i;
753
754   printf("USAGE: %s\n", progName);
755   printf("       <Inputfile (BMP|PPM)> <Quality> [options]\n\n");
756   printf("       %s\n", progName);
757   printf("       <Inputfile (JPG)> [options]\n\n");
758   printf("Options:\n\n");
759   printf("-alloc = Dynamically allocate JPEG image buffers\n");
760   printf("-bmp = Generate output images in Windows Bitmap format (default = PPM)\n");
761   printf("-bottomup = Test bottom-up compression/decompression\n");
762   printf("-tile = Test performance of the codec when the image is encoded as separate\n");
763   printf("     tiles of varying sizes.\n");
764   printf("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =\n");
765   printf("     Test the specified color conversion path in the codec (default = BGR)\n");
766   printf("-cmyk = Indirectly test YCCK JPEG compression/decompression (the source\n");
767   printf("     and destination bitmaps are still RGB.  The conversion is done\n");
768   printf("     internally prior to compression or after decompression.)\n");
769   printf("-fastupsample = Use the fastest chrominance upsampling algorithm available in\n");
770   printf("     the underlying codec\n");
771   printf("-fastdct = Use the fastest DCT/IDCT algorithms available in the underlying\n");
772   printf("     codec\n");
773   printf("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the\n");
774   printf("     underlying codec\n");
775   printf("-progressive = Use progressive entropy coding in JPEG images generated by\n");
776   printf("     compression and transform operations.\n");
777   printf("-subsamp <s> = When testing JPEG compression, this option specifies the level\n");
778   printf("     of chrominance subsampling to use (<s> = 444, 422, 440, 420, 411, or\n");
779   printf("     GRAY).  The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in\n");
780   printf("     sequence.\n");
781   printf("-quiet = Output results in tabular rather than verbose format\n");
782   printf("-yuv = Test YUV encoding/decoding functions\n");
783   printf("-yuvpad <p> = If testing YUV encoding/decoding, this specifies the number of\n");
784   printf("     bytes to which each row of each plane in the intermediate YUV image is\n");
785   printf("     padded (default = 1)\n");
786   printf("-scale M/N = Scale down the width/height of the decompressed JPEG image by a\n");
787   printf("     factor of M/N (M/N = ");
788   for (i = 0; i < nsf; i++) {
789     printf("%d/%d", scalingFactors[i].num, scalingFactors[i].denom);
790     if (nsf == 2 && i != nsf - 1) printf(" or ");
791     else if (nsf > 2) {
792       if (i != nsf - 1) printf(", ");
793       if (i == nsf - 2) printf("or ");
794     }
795     if (i % 8 == 0 && i != 0) printf("\n     ");
796   }
797   printf(")\n");
798   printf("-hflip, -vflip, -transpose, -transverse, -rot90, -rot180, -rot270 =\n");
799   printf("     Perform the corresponding lossless transform prior to\n");
800   printf("     decompression (these options are mutually exclusive)\n");
801   printf("-grayscale = Perform lossless grayscale conversion prior to decompression\n");
802   printf("     test (can be combined with the other transforms above)\n");
803   printf("-copynone = Do not copy any extra markers (including EXIF and ICC profile data)\n");
804   printf("     when transforming the image.\n");
805   printf("-benchtime <t> = Run each benchmark for at least <t> seconds (default = 5.0)\n");
806   printf("-warmup <t> = Run each benchmark for <t> seconds (default = 1.0) prior to\n");
807   printf("     starting the timer, in order to prime the caches and thus improve the\n");
808   printf("     consistency of the results.\n");
809   printf("-componly = Stop after running compression tests.  Do not test decompression.\n");
810   printf("-nowrite = Do not write reference or output images (improves consistency of\n");
811   printf("     performance measurements.)\n");
812   printf("-stoponwarning = Immediately discontinue the current\n");
813   printf("     compression/decompression/transform operation if the underlying codec\n");
814   printf("     throws a warning (non-fatal error)\n\n");
815   printf("NOTE:  If the quality is specified as a range (e.g. 90-100), a separate\n");
816   printf("test will be performed for all quality values in the range.\n\n");
817   exit(1);
818 }
819
820
821 int main(int argc, char *argv[])
822 {
823   unsigned char *srcBuf = NULL;
824   int w = 0, h = 0, i, j, minQual = -1, maxQual = -1;
825   char *temp;
826   int minArg = 2, retval = 0, subsamp = -1;
827
828   if ((scalingFactors = tjGetScalingFactors(&nsf)) == NULL || nsf == 0)
829     THROW("executing tjGetScalingFactors()", tjGetErrorStr());
830
831   if (argc < minArg) usage(argv[0]);
832
833   temp = strrchr(argv[1], '.');
834   if (temp != NULL) {
835     if (!strcasecmp(temp, ".bmp")) ext = "bmp";
836     if (!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg"))
837       decompOnly = 1;
838   }
839
840   printf("\n");
841
842   if (!decompOnly) {
843     minArg = 3;
844     if (argc < minArg) usage(argv[0]);
845     if ((minQual = atoi(argv[2])) < 1 || minQual > 100) {
846       puts("ERROR: Quality must be between 1 and 100.");
847       exit(1);
848     }
849     if ((temp = strchr(argv[2], '-')) != NULL && strlen(temp) > 1 &&
850         sscanf(&temp[1], "%d", &maxQual) == 1 && maxQual > minQual &&
851         maxQual >= 1 && maxQual <= 100) {}
852     else maxQual = minQual;
853   }
854
855   if (argc > minArg) {
856     for (i = minArg; i < argc; i++) {
857       if (!strcasecmp(argv[i], "-tile")) {
858         doTile = 1;  xformOpt |= TJXOPT_CROP;
859       } else if (!strcasecmp(argv[i], "-fastupsample")) {
860         printf("Using fast upsampling code\n\n");
861         flags |= TJFLAG_FASTUPSAMPLE;
862       } else if (!strcasecmp(argv[i], "-fastdct")) {
863         printf("Using fastest DCT/IDCT algorithm\n\n");
864         flags |= TJFLAG_FASTDCT;
865       } else if (!strcasecmp(argv[i], "-accuratedct")) {
866         printf("Using most accurate DCT/IDCT algorithm\n\n");
867         flags |= TJFLAG_ACCURATEDCT;
868       } else if (!strcasecmp(argv[i], "-progressive")) {
869         printf("Using progressive entropy coding\n\n");
870         flags |= TJFLAG_PROGRESSIVE;
871       } else if (!strcasecmp(argv[i], "-rgb"))
872         pf = TJPF_RGB;
873       else if (!strcasecmp(argv[i], "-rgbx"))
874         pf = TJPF_RGBX;
875       else if (!strcasecmp(argv[i], "-bgr"))
876         pf = TJPF_BGR;
877       else if (!strcasecmp(argv[i], "-bgrx"))
878         pf = TJPF_BGRX;
879       else if (!strcasecmp(argv[i], "-xbgr"))
880         pf = TJPF_XBGR;
881       else if (!strcasecmp(argv[i], "-xrgb"))
882         pf = TJPF_XRGB;
883       else if (!strcasecmp(argv[i], "-cmyk"))
884         pf = TJPF_CMYK;
885       else if (!strcasecmp(argv[i], "-bottomup"))
886         flags |= TJFLAG_BOTTOMUP;
887       else if (!strcasecmp(argv[i], "-quiet"))
888         quiet = 1;
889       else if (!strcasecmp(argv[i], "-qq"))
890         quiet = 2;
891       else if (!strcasecmp(argv[i], "-scale") && i < argc - 1) {
892         int temp1 = 0, temp2 = 0, match = 0;
893
894         if (sscanf(argv[++i], "%d/%d", &temp1, &temp2) == 2) {
895           for (j = 0; j < nsf; j++) {
896             if ((double)temp1 / (double)temp2 ==
897                 (double)scalingFactors[j].num /
898                 (double)scalingFactors[j].denom) {
899               sf = scalingFactors[j];
900               match = 1;  break;
901             }
902           }
903           if (!match) usage(argv[0]);
904         } else usage(argv[0]);
905       } else if (!strcasecmp(argv[i], "-hflip"))
906         xformOp = TJXOP_HFLIP;
907       else if (!strcasecmp(argv[i], "-vflip"))
908         xformOp = TJXOP_VFLIP;
909       else if (!strcasecmp(argv[i], "-transpose"))
910         xformOp = TJXOP_TRANSPOSE;
911       else if (!strcasecmp(argv[i], "-transverse"))
912         xformOp = TJXOP_TRANSVERSE;
913       else if (!strcasecmp(argv[i], "-rot90"))
914         xformOp = TJXOP_ROT90;
915       else if (!strcasecmp(argv[i], "-rot180"))
916         xformOp = TJXOP_ROT180;
917       else if (!strcasecmp(argv[i], "-rot270"))
918         xformOp = TJXOP_ROT270;
919       else if (!strcasecmp(argv[i], "-grayscale"))
920         xformOpt |= TJXOPT_GRAY;
921       else if (!strcasecmp(argv[i], "-custom"))
922         customFilter = dummyDCTFilter;
923       else if (!strcasecmp(argv[i], "-nooutput"))
924         xformOpt |= TJXOPT_NOOUTPUT;
925       else if (!strcasecmp(argv[i], "-copynone"))
926         xformOpt |= TJXOPT_COPYNONE;
927       else if (!strcasecmp(argv[i], "-benchtime") && i < argc - 1) {
928         double tempd = atof(argv[++i]);
929
930         if (tempd > 0.0) benchTime = tempd;
931         else usage(argv[0]);
932       } else if (!strcasecmp(argv[i], "-warmup") && i < argc - 1) {
933         double tempd = atof(argv[++i]);
934
935         if (tempd >= 0.0) warmup = tempd;
936         else usage(argv[0]);
937         printf("Warmup time = %.1f seconds\n\n", warmup);
938       } else if (!strcasecmp(argv[i], "-alloc"))
939         flags &= (~TJFLAG_NOREALLOC);
940       else if (!strcasecmp(argv[i], "-bmp"))
941         ext = "bmp";
942       else if (!strcasecmp(argv[i], "-yuv")) {
943         printf("Testing YUV planar encoding/decoding\n\n");
944         doYUV = 1;
945       } else if (!strcasecmp(argv[i], "-yuvpad") && i < argc - 1) {
946         int tempi = atoi(argv[++i]);
947
948         if (tempi >= 1) yuvPad = tempi;
949       } else if (!strcasecmp(argv[i], "-subsamp") && i < argc - 1) {
950         i++;
951         if (toupper(argv[i][0]) == 'G') subsamp = TJSAMP_GRAY;
952         else {
953           int tempi = atoi(argv[i]);
954
955           switch (tempi) {
956           case 444:  subsamp = TJSAMP_444;  break;
957           case 422:  subsamp = TJSAMP_422;  break;
958           case 440:  subsamp = TJSAMP_440;  break;
959           case 420:  subsamp = TJSAMP_420;  break;
960           case 411:  subsamp = TJSAMP_411;  break;
961           }
962         }
963       } else if (!strcasecmp(argv[i], "-componly"))
964         compOnly = 1;
965       else if (!strcasecmp(argv[i], "-nowrite"))
966         doWrite = 0;
967       else if (!strcasecmp(argv[i], "-stoponwarning"))
968         flags |= TJFLAG_STOPONWARNING;
969       else usage(argv[0]);
970     }
971   }
972
973   if ((sf.num != 1 || sf.denom != 1) && doTile) {
974     printf("Disabling tiled compression/decompression tests, because those tests do not\n");
975     printf("work when scaled decompression is enabled.\n");
976     doTile = 0;
977   }
978
979   if ((flags & TJFLAG_NOREALLOC) == 0 && doTile) {
980     printf("Disabling tiled compression/decompression tests, because those tests do not\n");
981     printf("work when dynamic JPEG buffer allocation is enabled.\n\n");
982     doTile = 0;
983   }
984
985   if (!decompOnly) {
986     if ((srcBuf = tjLoadImage(argv[1], &w, 1, &h, &pf, flags)) == NULL)
987       THROW_TJG("loading bitmap");
988     temp = strrchr(argv[1], '.');
989     if (temp != NULL) *temp = '\0';
990   }
991
992   if (quiet == 1 && !decompOnly) {
993     printf("All performance values in Mpixels/sec\n\n");
994     printf("Bitmap     JPEG     JPEG  %s  %s   ",
995            doTile ? "Tile " : "Image", doTile ? "Tile " : "Image");
996     if (doYUV) printf("Encode  ");
997     printf("Comp    Comp    Decomp  ");
998     if (doYUV) printf("Decode");
999     printf("\n");
1000     printf("Format     Subsamp  Qual  Width  Height  ");
1001     if (doYUV) printf("Perf    ");
1002     printf("Perf    Ratio   Perf    ");
1003     if (doYUV) printf("Perf");
1004     printf("\n\n");
1005   }
1006
1007   if (decompOnly) {
1008     decompTest(argv[1]);
1009     printf("\n");
1010     goto bailout;
1011   }
1012   if (subsamp >= 0 && subsamp < TJ_NUMSAMP) {
1013     for (i = maxQual; i >= minQual; i--)
1014       fullTest(srcBuf, w, h, subsamp, i, argv[1]);
1015     printf("\n");
1016   } else {
1017     if (pf != TJPF_CMYK) {
1018       for (i = maxQual; i >= minQual; i--)
1019         fullTest(srcBuf, w, h, TJSAMP_GRAY, i, argv[1]);
1020       printf("\n");
1021     }
1022     for (i = maxQual; i >= minQual; i--)
1023       fullTest(srcBuf, w, h, TJSAMP_420, i, argv[1]);
1024     printf("\n");
1025     for (i = maxQual; i >= minQual; i--)
1026       fullTest(srcBuf, w, h, TJSAMP_422, i, argv[1]);
1027     printf("\n");
1028     for (i = maxQual; i >= minQual; i--)
1029       fullTest(srcBuf, w, h, TJSAMP_444, i, argv[1]);
1030     printf("\n");
1031   }
1032
1033 bailout:
1034   tjFree(srcBuf);
1035   return retval;
1036 }