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