DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 1 | /* |
DRC | cbc9970 | 2015-01-16 06:29:52 +0000 | [diff] [blame] | 2 | * Copyright (C)2009-2015 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 | { |
DRC | cbc9970 | 2015-01-16 06:29:52 +0000 | [diff] [blame] | 53 | "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY", "", "", "", "", "CMYK" |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 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 | } |
DRC | 1a45b81 | 2014-05-09 18:06:58 +0000 | [diff] [blame] | 254 | } |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 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 | 4186162 | 2014-04-16 23:38:37 +0000 | [diff] [blame] | 276 | int 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 | eb66974 | 2014-08-22 19:59:51 +0000 | [diff] [blame] | 315 | if((jpegbuf[i]=(unsigned char *)tjAlloc(tjBufSize(tilew, tileh, |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 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 | { |
DRC | eb66974 | 2014-08-22 19:59:51 +0000 | [diff] [blame] | 447 | if(jpegbuf[i]) tjFree(jpegbuf[i]); jpegbuf[i]=NULL; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 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 | { |
DRC | eb66974 | 2014-08-22 19:59:51 +0000 | [diff] [blame] | 465 | if(jpegbuf[i]) tjFree(jpegbuf[i]); jpegbuf[i]=NULL; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 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;} |
DRC | 4186162 | 2014-04-16 23:38:37 +0000 | [diff] [blame] | 473 | return retval; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | |
DRC | 4186162 | 2014-04-16 23:38:37 +0000 | [diff] [blame] | 477 | int 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 | cbc9970 | 2015-01-16 06:29:52 +0000 | [diff] [blame] | 509 | if(cs==TJCS_YCCK || cs==TJCS_CMYK) |
| 510 | { |
| 511 | pf=TJPF_CMYK; ps=tjPixelSize[pf]; |
| 512 | } |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 513 | |
| 514 | if(quiet==1) |
| 515 | { |
| 516 | printf("All performance values in Mpixels/sec\n\n"); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 517 | printf("Bitmap JPEG JPEG %s %s Xform Comp Decomp ", |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 518 | dotile? "Tile ":"Image", dotile? "Tile ":"Image"); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 519 | if(doyuv) printf("Decode"); |
| 520 | printf("\n"); |
| 521 | printf("Format CS Subsamp Width Height Perf Ratio Perf "); |
| 522 | if(doyuv) printf("Perf"); |
| 523 | printf("\n\n"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 524 | } |
| 525 | else if(!quiet) |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 526 | printf(">>>>> JPEG %s --> %s (%s) <<<<<\n", |
| 527 | formatName(subsamp, cs, tempstr), pixFormatStr[pf], |
| 528 | (flags&TJFLAG_BOTTOMUP)? "Bottom-up":"Top-down"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 529 | |
| 530 | for(tilew=dotile? 16:w, tileh=dotile? 16:h; ; tilew*=2, tileh*=2) |
| 531 | { |
| 532 | if(tilew>w) tilew=w; if(tileh>h) tileh=h; |
| 533 | ntilesw=(w+tilew-1)/tilew; ntilesh=(h+tileh-1)/tileh; |
| 534 | |
| 535 | if((jpegbuf=(unsigned char **)malloc(sizeof(unsigned char *) |
| 536 | *ntilesw*ntilesh))==NULL) |
| 537 | _throwunix("allocating JPEG tile array"); |
| 538 | memset(jpegbuf, 0, sizeof(unsigned char *)*ntilesw*ntilesh); |
| 539 | if((jpegsize=(unsigned long *)malloc(sizeof(unsigned long) |
| 540 | *ntilesw*ntilesh))==NULL) |
| 541 | _throwunix("allocating JPEG size array"); |
| 542 | memset(jpegsize, 0, sizeof(unsigned long)*ntilesw*ntilesh); |
| 543 | |
DRC | dd59233 | 2014-03-12 06:15:51 +0000 | [diff] [blame] | 544 | if((flags&TJFLAG_NOREALLOC)!=0 || !dotile) |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 545 | for(i=0; i<ntilesw*ntilesh; i++) |
| 546 | { |
DRC | eb66974 | 2014-08-22 19:59:51 +0000 | [diff] [blame] | 547 | if((jpegbuf[i]=(unsigned char *)tjAlloc(tjBufSize(tilew, tileh, |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 548 | subsamp)))==NULL) |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 549 | _throwunix("allocating JPEG tiles"); |
| 550 | } |
| 551 | |
| 552 | _w=w; _h=h; _tilew=tilew; _tileh=tileh; |
| 553 | if(!quiet) |
| 554 | { |
| 555 | printf("\n%s size: %d x %d", dotile? "Tile":"Image", _tilew, |
| 556 | _tileh); |
| 557 | if(sf.num!=1 || sf.denom!=1) |
| 558 | printf(" --> %d x %d", TJSCALED(_w, sf), TJSCALED(_h, sf)); |
| 559 | printf("\n"); |
| 560 | } |
| 561 | else if(quiet==1) |
| 562 | { |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 563 | printf("%-4s (%s) %-5s %-5s ", pixFormatStr[pf], |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 564 | (flags&TJFLAG_BOTTOMUP)? "BU":"TD", csName[cs], subNameLong[subsamp]); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 565 | printf("%-5d %-5d ", tilew, tileh); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | _subsamp=subsamp; |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 569 | if(dotile || xformop!=TJXOP_NONE || xformopt!=0 || customFilter) |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 570 | { |
| 571 | if((t=(tjtransform *)malloc(sizeof(tjtransform)*ntilesw*ntilesh)) |
| 572 | ==NULL) |
| 573 | _throwunix("allocating image transform array"); |
| 574 | |
| 575 | if(xformop==TJXOP_TRANSPOSE || xformop==TJXOP_TRANSVERSE |
| 576 | || xformop==TJXOP_ROT90 || xformop==TJXOP_ROT270) |
| 577 | { |
| 578 | _w=h; _h=w; _tilew=tileh; _tileh=tilew; |
| 579 | } |
| 580 | |
| 581 | if(xformopt&TJXOPT_GRAY) _subsamp=TJ_GRAYSCALE; |
| 582 | if(xformop==TJXOP_HFLIP || xformop==TJXOP_ROT180) |
| 583 | _w=_w-(_w%tjMCUWidth[_subsamp]); |
| 584 | if(xformop==TJXOP_VFLIP || xformop==TJXOP_ROT180) |
| 585 | _h=_h-(_h%tjMCUHeight[_subsamp]); |
| 586 | if(xformop==TJXOP_TRANSVERSE || xformop==TJXOP_ROT90) |
| 587 | _w=_w-(_w%tjMCUHeight[_subsamp]); |
| 588 | if(xformop==TJXOP_TRANSVERSE || xformop==TJXOP_ROT270) |
| 589 | _h=_h-(_h%tjMCUWidth[_subsamp]); |
| 590 | _ntilesw=(_w+_tilew-1)/_tilew; |
| 591 | _ntilesh=(_h+_tileh-1)/_tileh; |
| 592 | |
DRC | ce6891f | 2014-03-13 20:33:43 +0000 | [diff] [blame] | 593 | if(xformop==TJXOP_TRANSPOSE || xformop==TJXOP_TRANSVERSE |
| 594 | || xformop==TJXOP_ROT90 || xformop==TJXOP_ROT270) |
| 595 | { |
| 596 | if(_subsamp==TJSAMP_422) _subsamp=TJSAMP_440; |
| 597 | else if(_subsamp==TJSAMP_440) _subsamp=TJSAMP_422; |
| 598 | } |
| 599 | |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 600 | for(row=0, tile=0; row<_ntilesh; row++) |
| 601 | { |
| 602 | for(col=0; col<_ntilesw; col++, tile++) |
| 603 | { |
| 604 | t[tile].r.w=min(_tilew, _w-col*_tilew); |
| 605 | t[tile].r.h=min(_tileh, _h-row*_tileh); |
| 606 | t[tile].r.x=col*_tilew; |
| 607 | t[tile].r.y=row*_tileh; |
| 608 | t[tile].op=xformop; |
| 609 | t[tile].options=xformopt|TJXOPT_TRIM; |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 610 | t[tile].customFilter=customFilter; |
| 611 | if(t[tile].options&TJXOPT_NOOUTPUT && jpegbuf[tile]) |
| 612 | { |
DRC | eb66974 | 2014-08-22 19:59:51 +0000 | [diff] [blame] | 613 | tjFree(jpegbuf[tile]); jpegbuf[tile]=NULL; |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 614 | } |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
DRC | adf5551 | 2014-03-12 07:17:23 +0000 | [diff] [blame] | 618 | iter=-warmup; |
| 619 | elapsed=0.; |
| 620 | while(1) |
| 621 | { |
| 622 | start=gettime(); |
| 623 | if(tjTransform(handle, srcbuf, srcsize, _ntilesw*_ntilesh, jpegbuf, |
| 624 | jpegsize, t, flags)==-1) |
| 625 | _throwtj("executing tjTransform()"); |
| 626 | iter++; |
| 627 | if(iter>=1) |
| 628 | { |
| 629 | elapsed+=gettime()-start; |
| 630 | if(elapsed>=benchtime) break; |
| 631 | } |
| 632 | } |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 633 | |
| 634 | free(t); t=NULL; |
| 635 | |
| 636 | for(tile=0, totaljpegsize=0; tile<_ntilesw*_ntilesh; tile++) |
| 637 | totaljpegsize+=jpegsize[tile]; |
| 638 | |
| 639 | if(quiet) |
| 640 | { |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 641 | printf("%-6s%s%-6s%s", |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 642 | sigfig((double)(w*h)/1000000./elapsed, 4, tempstr, 80), |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 643 | quiet==2? "\n":" ", |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 644 | sigfig((double)(w*h*ps)/(double)totaljpegsize, 4, tempstr2, 80), |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 645 | quiet==2? "\n":" "); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 646 | } |
| 647 | else if(!quiet) |
| 648 | { |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 649 | printf("Transform --> Frame rate: %f fps\n", 1.0/elapsed); |
| 650 | printf(" Output image size: %lu bytes\n", totaljpegsize); |
| 651 | printf(" Compression ratio: %f:1\n", |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 652 | (double)(w*h*ps)/(double)totaljpegsize); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 653 | printf(" Throughput: %f Megapixels/sec\n", |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 654 | (double)(w*h)/1000000./elapsed); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 655 | printf(" Output bit stream: %f Megabits/sec\n", |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 656 | (double)totaljpegsize*8./1000000./elapsed); |
| 657 | } |
| 658 | } |
| 659 | else |
| 660 | { |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 661 | if(quiet==1) printf("N/A N/A "); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 662 | jpegsize[0]=srcsize; |
| 663 | memcpy(jpegbuf[0], srcbuf, srcsize); |
| 664 | } |
| 665 | |
| 666 | if(w==tilew) _tilew=_w; |
| 667 | if(h==tileh) _tileh=_h; |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 668 | if(!(xformopt&TJXOPT_NOOUTPUT)) |
| 669 | { |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 670 | if(decomp(NULL, jpegbuf, jpegsize, NULL, _w, _h, _subsamp, 0, |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 671 | filename, _tilew, _tileh)==-1) |
| 672 | goto bailout; |
| 673 | } |
| 674 | else if(quiet==1) printf("N/A\n"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 675 | |
| 676 | for(i=0; i<ntilesw*ntilesh; i++) |
| 677 | { |
DRC | eb66974 | 2014-08-22 19:59:51 +0000 | [diff] [blame] | 678 | tjFree(jpegbuf[i]); jpegbuf[i]=NULL; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 679 | } |
| 680 | free(jpegbuf); jpegbuf=NULL; |
| 681 | if(jpegsize) {free(jpegsize); jpegsize=NULL;} |
| 682 | |
| 683 | if(tilew==w && tileh==h) break; |
| 684 | } |
| 685 | |
| 686 | bailout: |
| 687 | if(file) {fclose(file); file=NULL;} |
| 688 | if(jpegbuf) |
| 689 | { |
| 690 | for(i=0; i<ntilesw*ntilesh; i++) |
| 691 | { |
DRC | eb66974 | 2014-08-22 19:59:51 +0000 | [diff] [blame] | 692 | if(jpegbuf[i]) tjFree(jpegbuf[i]); jpegbuf[i]=NULL; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 693 | } |
| 694 | free(jpegbuf); jpegbuf=NULL; |
| 695 | } |
| 696 | if(jpegsize) {free(jpegsize); jpegsize=NULL;} |
| 697 | if(srcbuf) {free(srcbuf); srcbuf=NULL;} |
| 698 | if(t) {free(t); t=NULL;} |
| 699 | if(handle) {tjDestroy(handle); handle=NULL;} |
DRC | 4186162 | 2014-04-16 23:38:37 +0000 | [diff] [blame] | 700 | return retval; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | |
| 704 | void usage(char *progname) |
| 705 | { |
| 706 | int i; |
| 707 | printf("USAGE: %s\n", progname); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 708 | printf(" <Inputfile (BMP|PPM)> <Quality> [options]\n\n"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 709 | printf(" %s\n", progname); |
| 710 | printf(" <Inputfile (JPG)> [options]\n\n"); |
| 711 | printf("Options:\n\n"); |
| 712 | printf("-alloc = Dynamically allocate JPEG image buffers\n"); |
DRC | dd5fcdd | 2014-03-17 10:40:10 +0000 | [diff] [blame] | 713 | printf("-bmp = Generate output images in Windows Bitmap format (default = PPM)\n"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 714 | printf("-bottomup = Test bottom-up compression/decompression\n"); |
| 715 | printf("-tile = Test performance of the codec when the image is encoded as separate\n"); |
| 716 | printf(" tiles of varying sizes.\n"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 717 | printf("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =\n"); |
DRC | dd5fcdd | 2014-03-17 10:40:10 +0000 | [diff] [blame] | 718 | printf(" Test the specified color conversion path in the codec (default = BGR)\n"); |
DRC | cbc9970 | 2015-01-16 06:29:52 +0000 | [diff] [blame] | 719 | printf("-cmyk = Indirectly test YCCK JPEG compression/decompression (the source\n"); |
| 720 | printf(" and destination bitmaps are still RGB. The conversion is done\n"); |
| 721 | printf(" internally prior to compression or after decompression.)\n"); |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 722 | printf("-fastupsample = Use the fastest chrominance upsampling algorithm available in\n"); |
| 723 | printf(" the underlying codec\n"); |
| 724 | printf("-fastdct = Use the fastest DCT/IDCT algorithms available in the underlying\n"); |
| 725 | printf(" codec\n"); |
| 726 | printf("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the\n"); |
| 727 | printf(" underlying codec\n"); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 728 | printf("-subsamp <s> = When testing JPEG compression, this option specifies the level\n"); |
| 729 | printf(" of chrominance subsampling to use (<s> = 444, 422, 440, 420, 411, or\n"); |
| 730 | printf(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in\n"); |
| 731 | printf(" sequence.\n"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 732 | printf("-quiet = Output results in tabular rather than verbose format\n"); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 733 | printf("-yuv = Test YUV encoding/decoding functions\n"); |
| 734 | printf("-yuvpad <p> = If testing YUV encoding/decoding, this specifies the number of\n"); |
| 735 | 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] | 736 | printf(" padded (default = 1)\n"); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 737 | 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] | 738 | printf(" factor of M/N (M/N = "); |
| 739 | for(i=0; i<nsf; i++) |
| 740 | { |
| 741 | printf("%d/%d", scalingfactors[i].num, scalingfactors[i].denom); |
| 742 | if(nsf==2 && i!=nsf-1) printf(" or "); |
| 743 | else if(nsf>2) |
| 744 | { |
| 745 | if(i!=nsf-1) printf(", "); |
| 746 | if(i==nsf-2) printf("or "); |
| 747 | } |
DRC | ab2df6e | 2012-01-28 06:49:56 +0000 | [diff] [blame] | 748 | if(i%8==0 && i!=0) printf("\n "); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 749 | } |
| 750 | printf(")\n"); |
| 751 | printf("-hflip, -vflip, -transpose, -transverse, -rot90, -rot180, -rot270 =\n"); |
| 752 | printf(" Perform the corresponding lossless transform prior to\n"); |
| 753 | printf(" decompression (these options are mutually exclusive)\n"); |
| 754 | printf("-grayscale = Perform lossless grayscale conversion prior to decompression\n"); |
| 755 | printf(" test (can be combined with the other transforms above)\n"); |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 756 | 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] | 757 | 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] | 758 | printf(" taking performance measurements (default = 1)\n"); |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 759 | printf("-componly = Stop after running compression tests. Do not test decompression.\n\n"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 760 | printf("NOTE: If the quality is specified as a range (e.g. 90-100), a separate\n"); |
| 761 | printf("test will be performed for all quality values in the range.\n\n"); |
| 762 | exit(1); |
| 763 | } |
| 764 | |
| 765 | |
| 766 | int main(int argc, char *argv[]) |
| 767 | { |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 768 | unsigned char *srcbuf=NULL; int w=0, h=0, i, j; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 769 | int minqual=-1, maxqual=-1; char *temp; |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 770 | int minarg=2, retval=0, subsamp=-1; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 771 | |
| 772 | if((scalingfactors=tjGetScalingFactors(&nsf))==NULL || nsf==0) |
| 773 | _throwtj("executing tjGetScalingFactors()"); |
| 774 | |
| 775 | if(argc<minarg) usage(argv[0]); |
| 776 | |
| 777 | temp=strrchr(argv[1], '.'); |
| 778 | if(temp!=NULL) |
| 779 | { |
| 780 | if(!strcasecmp(temp, ".bmp")) ext="bmp"; |
| 781 | if(!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg")) decomponly=1; |
| 782 | } |
| 783 | |
| 784 | printf("\n"); |
| 785 | |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 786 | if(!decomponly) |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 787 | { |
| 788 | minarg=3; |
| 789 | if(argc<minarg) usage(argv[0]); |
| 790 | if((minqual=atoi(argv[2]))<1 || minqual>100) |
| 791 | { |
| 792 | puts("ERROR: Quality must be between 1 and 100."); |
| 793 | exit(1); |
| 794 | } |
| 795 | if((temp=strchr(argv[2], '-'))!=NULL && strlen(temp)>1 |
| 796 | && sscanf(&temp[1], "%d", &maxqual)==1 && maxqual>minqual && maxqual>=1 |
| 797 | && maxqual<=100) {} |
| 798 | else maxqual=minqual; |
| 799 | } |
| 800 | |
| 801 | if(argc>minarg) |
| 802 | { |
| 803 | for(i=minarg; i<argc; i++) |
| 804 | { |
| 805 | if(!strcasecmp(argv[i], "-tile")) |
| 806 | { |
| 807 | dotile=1; xformopt|=TJXOPT_CROP; |
| 808 | } |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 809 | if(!strcasecmp(argv[i], "-fastupsample")) |
| 810 | { |
| 811 | printf("Using fast upsampling code\n\n"); |
| 812 | flags|=TJFLAG_FASTUPSAMPLE; |
| 813 | } |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 814 | if(!strcasecmp(argv[i], "-fastdct")) |
| 815 | { |
| 816 | printf("Using fastest DCT/IDCT algorithm\n\n"); |
| 817 | flags|=TJFLAG_FASTDCT; |
| 818 | } |
| 819 | if(!strcasecmp(argv[i], "-accuratedct")) |
| 820 | { |
| 821 | printf("Using most accurate DCT/IDCT algorithm\n\n"); |
| 822 | flags|=TJFLAG_ACCURATEDCT; |
| 823 | } |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 824 | if(!strcasecmp(argv[i], "-rgb")) pf=TJPF_RGB; |
| 825 | if(!strcasecmp(argv[i], "-rgbx")) pf=TJPF_RGBX; |
| 826 | if(!strcasecmp(argv[i], "-bgr")) pf=TJPF_BGR; |
| 827 | if(!strcasecmp(argv[i], "-bgrx")) pf=TJPF_BGRX; |
| 828 | if(!strcasecmp(argv[i], "-xbgr")) pf=TJPF_XBGR; |
| 829 | if(!strcasecmp(argv[i], "-xrgb")) pf=TJPF_XRGB; |
DRC | cbc9970 | 2015-01-16 06:29:52 +0000 | [diff] [blame] | 830 | if(!strcasecmp(argv[i], "-cmyk")) pf=TJPF_CMYK; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 831 | if(!strcasecmp(argv[i], "-bottomup")) flags|=TJFLAG_BOTTOMUP; |
| 832 | if(!strcasecmp(argv[i], "-quiet")) quiet=1; |
| 833 | if(!strcasecmp(argv[i], "-qq")) quiet=2; |
| 834 | if(!strcasecmp(argv[i], "-scale") && i<argc-1) |
| 835 | { |
| 836 | int temp1=0, temp2=0, match=0; |
| 837 | if(sscanf(argv[++i], "%d/%d", &temp1, &temp2)==2) |
| 838 | { |
| 839 | for(j=0; j<nsf; j++) |
| 840 | { |
DRC | ab2df6e | 2012-01-28 06:49:56 +0000 | [diff] [blame] | 841 | if((double)temp1/(double)temp2 |
| 842 | == (double)scalingfactors[j].num/(double)scalingfactors[j].denom) |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 843 | { |
| 844 | sf=scalingfactors[j]; |
| 845 | match=1; break; |
| 846 | } |
| 847 | } |
| 848 | if(!match) usage(argv[0]); |
| 849 | } |
| 850 | else usage(argv[0]); |
| 851 | } |
| 852 | if(!strcasecmp(argv[i], "-hflip")) xformop=TJXOP_HFLIP; |
| 853 | if(!strcasecmp(argv[i], "-vflip")) xformop=TJXOP_VFLIP; |
| 854 | if(!strcasecmp(argv[i], "-transpose")) xformop=TJXOP_TRANSPOSE; |
| 855 | if(!strcasecmp(argv[i], "-transverse")) xformop=TJXOP_TRANSVERSE; |
| 856 | if(!strcasecmp(argv[i], "-rot90")) xformop=TJXOP_ROT90; |
| 857 | if(!strcasecmp(argv[i], "-rot180")) xformop=TJXOP_ROT180; |
| 858 | if(!strcasecmp(argv[i], "-rot270")) xformop=TJXOP_ROT270; |
| 859 | if(!strcasecmp(argv[i], "-grayscale")) xformopt|=TJXOPT_GRAY; |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 860 | if(!strcasecmp(argv[i], "-custom")) customFilter=dummyDCTFilter; |
| 861 | if(!strcasecmp(argv[i], "-nooutput")) xformopt|=TJXOPT_NOOUTPUT; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 862 | if(!strcasecmp(argv[i], "-benchtime") && i<argc-1) |
| 863 | { |
| 864 | double temp=atof(argv[++i]); |
| 865 | if(temp>0.0) benchtime=temp; |
| 866 | else usage(argv[0]); |
| 867 | } |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 868 | if(!strcasecmp(argv[i], "-warmup") && i<argc-1) |
| 869 | { |
| 870 | int temp=atoi(argv[++i]); |
| 871 | if(temp>=0) |
| 872 | { |
| 873 | warmup=temp; |
| 874 | printf("Warmup runs = %d\n\n", warmup); |
| 875 | } |
| 876 | else usage(argv[0]); |
| 877 | } |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 878 | if(!strcmp(argv[i], "-?")) usage(argv[0]); |
| 879 | if(!strcasecmp(argv[i], "-alloc")) flags&=(~TJFLAG_NOREALLOC); |
DRC | 94f0e03 | 2011-05-25 04:35:53 +0000 | [diff] [blame] | 880 | if(!strcasecmp(argv[i], "-bmp")) ext="bmp"; |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 881 | if(!strcasecmp(argv[i], "-yuv")) |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 882 | { |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 883 | printf("Testing YUV planar encoding/decoding\n\n"); |
| 884 | doyuv=1; |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 885 | } |
| 886 | if(!strcasecmp(argv[i], "-yuvpad") && i<argc-1) |
| 887 | { |
| 888 | int temp=atoi(argv[++i]); |
| 889 | if(temp>=1) yuvpad=temp; |
| 890 | } |
| 891 | if(!strcasecmp(argv[i], "-subsamp") && i<argc-1) |
| 892 | { |
| 893 | i++; |
| 894 | if(toupper(argv[i][0])=='G') subsamp=TJSAMP_GRAY; |
| 895 | else |
| 896 | { |
| 897 | int temp=atoi(argv[i]); |
| 898 | switch(temp) |
| 899 | { |
| 900 | case 444: subsamp=TJSAMP_444; break; |
| 901 | case 422: subsamp=TJSAMP_422; break; |
| 902 | case 440: subsamp=TJSAMP_440; break; |
| 903 | case 420: subsamp=TJSAMP_420; break; |
| 904 | case 411: subsamp=TJSAMP_411; break; |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | if(!strcasecmp(argv[i], "-componly")) componly=1; |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
| 912 | if((sf.num!=1 || sf.denom!=1) && dotile) |
| 913 | { |
| 914 | printf("Disabling tiled compression/decompression tests, because those tests do not\n"); |
| 915 | printf("work when scaled decompression is enabled.\n"); |
| 916 | dotile=0; |
| 917 | } |
| 918 | |
DRC | 684ace1 | 2014-08-22 03:04:06 +0000 | [diff] [blame] | 919 | if((flags&TJFLAG_NOREALLOC)==0 && dotile) |
| 920 | { |
| 921 | printf("Disabling tiled compression/decompression tests, because those tests do not\n"); |
| 922 | printf("work when dynamic JPEG buffer allocation is enabled.\n\n"); |
| 923 | dotile=0; |
| 924 | } |
| 925 | |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 926 | if(!decomponly) |
| 927 | { |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 928 | if(loadbmp(argv[1], &srcbuf, &w, &h, pf, (flags&TJFLAG_BOTTOMUP)!=0)==-1) |
| 929 | _throwbmp("loading bitmap"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 930 | temp=strrchr(argv[1], '.'); |
| 931 | if(temp!=NULL) *temp='\0'; |
| 932 | } |
| 933 | |
| 934 | if(quiet==1 && !decomponly) |
| 935 | { |
| 936 | printf("All performance values in Mpixels/sec\n\n"); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 937 | printf("Bitmap JPEG JPEG %s %s ", |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 938 | dotile? "Tile ":"Image", dotile? "Tile ":"Image"); |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 939 | if(doyuv) printf("Encode "); |
| 940 | printf("Comp Comp Decomp "); |
| 941 | if(doyuv) printf("Decode"); |
| 942 | printf("\n"); |
| 943 | printf("Format Subsamp Qual Width Height "); |
| 944 | if(doyuv) printf("Perf "); |
| 945 | printf("Perf Ratio Perf "); |
| 946 | if(doyuv) printf("Perf"); |
| 947 | printf("\n\n"); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | if(decomponly) |
| 951 | { |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 952 | decompTest(argv[1]); |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 953 | printf("\n"); |
| 954 | goto bailout; |
| 955 | } |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 956 | if(subsamp>=0 && subsamp<TJ_NUMSAMP) |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 957 | { |
| 958 | for(i=maxqual; i>=minqual; i--) |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 959 | fullTest(srcbuf, w, h, subsamp, i, argv[1]); |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 960 | printf("\n"); |
| 961 | } |
| 962 | else |
| 963 | { |
DRC | cbc9970 | 2015-01-16 06:29:52 +0000 | [diff] [blame] | 964 | if(pf!=TJPF_CMYK) |
| 965 | { |
| 966 | for(i=maxqual; i>=minqual; i--) |
| 967 | fullTest(srcbuf, w, h, TJSAMP_GRAY, i, argv[1]); |
| 968 | printf("\n"); |
| 969 | } |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 970 | for(i=maxqual; i>=minqual; i--) |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 971 | fullTest(srcbuf, w, h, TJSAMP_420, i, argv[1]); |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 972 | printf("\n"); |
| 973 | for(i=maxqual; i>=minqual; i--) |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 974 | fullTest(srcbuf, w, h, TJSAMP_422, i, argv[1]); |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 975 | printf("\n"); |
| 976 | for(i=maxqual; i>=minqual; i--) |
DRC | 95e4cb2 | 2014-03-12 06:51:39 +0000 | [diff] [blame] | 977 | fullTest(srcbuf, w, h, TJSAMP_444, i, argv[1]); |
DRC | c6501f7 | 2013-11-04 23:07:54 +0000 | [diff] [blame] | 978 | printf("\n"); |
| 979 | } |
DRC | b8b359a | 2011-05-25 03:54:56 +0000 | [diff] [blame] | 980 | |
| 981 | bailout: |
| 982 | if(srcbuf) free(srcbuf); |
| 983 | return retval; |
| 984 | } |