DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1 | /* Copyright (C)2004 Landmark Graphics Corporation |
| 2 | * Copyright (C)2005, 2006 Sun Microsystems, Inc. |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 3 | * Copyright (C)2009-2011 D. R. Commander |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 4 | * |
| 5 | * This library is free software and may be redistributed and/or modified under |
| 6 | * the terms of the wxWindows Library License, Version 3.1 or (at your option) |
| 7 | * any later version. The full license is in the LICENSE.txt file included |
| 8 | * with this distribution. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * wxWindows Library License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <math.h> |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 20 | #include <errno.h> |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 21 | #include "./bmp.h" |
| 22 | #include "./rrutil.h" |
| 23 | #include "./rrtimer.h" |
| 24 | #include "./turbojpeg.h" |
| 25 | |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 26 | #define _throw(op, err) { \ |
| 27 | printf("ERROR in line %d while %s:\n%s\n", __LINE__, op, err); goto bailout;} |
| 28 | #define _throwunix(m) _throw(m, strerror(errno)) |
| 29 | #define _throwtj(m) _throw(m, tjGetErrorStr()) |
| 30 | #define _throwbmp(m) _throw(m, bmpgeterr()) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 31 | |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 32 | #define PAD(v, p) ((v+(p)-1)&(~((p)-1))) |
| 33 | |
| 34 | enum {YUVENCODE=1, YUVDECODE}; |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 35 | int forcemmx=0, forcesse=0, forcesse2=0, forcesse3=0, fastupsample=0, |
DRC | fbb6747 | 2010-11-24 04:02:37 +0000 | [diff] [blame] | 36 | decomponly=0, yuv=0; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 37 | const int _ps[BMPPIXELFORMATS]={3, 4, 3, 4, 4, 4}; |
| 38 | const int _flags[BMPPIXELFORMATS]={0, 0, TJ_BGR, TJ_BGR, |
| 39 | TJ_BGR|TJ_ALPHAFIRST, TJ_ALPHAFIRST}; |
| 40 | const int _rindex[BMPPIXELFORMATS]={0, 0, 2, 2, 3, 1}; |
| 41 | const int _gindex[BMPPIXELFORMATS]={1, 1, 1, 1, 2, 2}; |
| 42 | const int _bindex[BMPPIXELFORMATS]={2, 2, 0, 0, 1, 3}; |
DRC | b4b3140 | 2011-02-19 17:31:24 +0000 | [diff] [blame] | 43 | const char *_pfname[]={"RGB", "RGBX", "BGR", "BGRX", "XBGR", "XRGB"}; |
DRC | 61e51f9 | 2009-04-05 21:53:20 +0000 | [diff] [blame] | 44 | const char *_subnamel[NUMSUBOPT]={"4:4:4", "4:2:2", "4:2:0", "GRAY"}; |
| 45 | const char *_subnames[NUMSUBOPT]={"444", "422", "420", "GRAY"}; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 46 | |
| 47 | void printsigfig(double val, int figs) |
| 48 | { |
| 49 | char format[80]; |
| 50 | double _l=log10(val); int l; |
| 51 | if(_l<0.) |
| 52 | { |
| 53 | l=(int)fabs(_l); |
| 54 | sprintf(format, "%%%d.%df", figs+l+2, figs+l); |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | l=(int)_l+1; |
| 59 | if(figs<=l) sprintf(format, "%%.0f"); |
| 60 | else sprintf(format, "%%%d.%df", figs+1, figs-l); |
| 61 | } |
| 62 | printf(format, val); |
| 63 | } |
| 64 | |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 65 | void dotest(unsigned char *srcbuf, int w, int h, int pf, int bu, |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 66 | int jpegsub, int qual, char *filename, int dotile, int useppm, int quiet) |
| 67 | { |
| 68 | char tempstr[1024]; |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 69 | FILE *outfile=NULL; tjhandle hnd; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 70 | unsigned char **jpegbuf=NULL, *rgbbuf=NULL; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 71 | double start, elapsed; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 72 | int jpgbufsize=0, i, j, tilesizex, tilesizey, numtilesx, numtilesy, ITER; |
| 73 | unsigned long *comptilesize=NULL; |
| 74 | int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0) |
DRC | 61e51f9 | 2009-04-05 21:53:20 +0000 | [diff] [blame] | 75 | |(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0) |
| 76 | |(fastupsample?TJ_FASTUPSAMPLE:0); |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 77 | int ps=_ps[pf], tilen; |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 78 | int pitch=w*ps, yuvsize; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 79 | |
| 80 | flags |= _flags[pf]; |
| 81 | if(bu) flags |= TJ_BOTTOMUP; |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 82 | if(yuv==YUVENCODE) flags |= TJ_YUV; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 83 | |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 84 | yuvsize=TJBUFSIZEYUV(w, h, jpegsub); |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 85 | if((rgbbuf=(unsigned char *)malloc(max(yuvsize, pitch*h))) == NULL) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 86 | _throwunix("allocating image buffer"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 87 | |
DRC | fbb6747 | 2010-11-24 04:02:37 +0000 | [diff] [blame] | 88 | if(!quiet) |
| 89 | { |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 90 | if(yuv==YUVENCODE) |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 91 | printf(">>>>> %s (%s) <--> YUV %s <<<<<\n", _pfname[pf], |
DRC | fbb6747 | 2010-11-24 04:02:37 +0000 | [diff] [blame] | 92 | bu?"Bottom-up":"Top-down", _subnamel[jpegsub]); |
| 93 | else |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 94 | printf(">>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", _pfname[pf], |
DRC | fbb6747 | 2010-11-24 04:02:37 +0000 | [diff] [blame] | 95 | bu?"Bottom-up":"Top-down", _subnamel[jpegsub], qual); |
| 96 | } |
DRC | 5cb1b68 | 2011-02-24 22:13:20 +0000 | [diff] [blame] | 97 | if(yuv) dotile=0; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 98 | if(dotile) {tilesizex=tilesizey=4;} else {tilesizex=w; tilesizey=h;} |
| 99 | |
| 100 | do |
| 101 | { |
| 102 | tilesizex*=2; if(tilesizex>w) tilesizex=w; |
| 103 | tilesizey*=2; if(tilesizey>h) tilesizey=h; |
| 104 | numtilesx=(w+tilesizex-1)/tilesizex; |
| 105 | numtilesy=(h+tilesizey-1)/tilesizey; |
| 106 | if((comptilesize=(unsigned long *)malloc(sizeof(unsigned long)*numtilesx*numtilesy)) == NULL |
| 107 | || (jpegbuf=(unsigned char **)malloc(sizeof(unsigned char *)*numtilesx*numtilesy)) == NULL) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 108 | _throwunix("allocating image buffers"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 109 | memset(jpegbuf, 0, sizeof(unsigned char *)*numtilesx*numtilesy); |
| 110 | for(i=0; i<numtilesx*numtilesy; i++) |
| 111 | { |
| 112 | if((jpegbuf[i]=(unsigned char *)malloc(TJBUFSIZE(tilesizex, tilesizey))) == NULL) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 113 | _throwunix("allocating image buffers"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | // Compression test |
DRC | 2a28599 | 2011-02-19 17:20:11 +0000 | [diff] [blame] | 117 | if(quiet==1) printf("%s\t%s\t%s\t%d\t", _pfname[pf], bu?"BU":"TD", |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 118 | _subnamel[jpegsub], qual); |
| 119 | for(i=0; i<h; i++) memcpy(&rgbbuf[pitch*i], &srcbuf[w*ps*i], w*ps); |
| 120 | if((hnd=tjInitCompress())==NULL) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 121 | _throwtj("executing tjInitCompress()"); |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 122 | if(yuv==YUVENCODE) |
| 123 | { |
| 124 | if(tjEncodeYUV(hnd, rgbbuf, tilesizex, pitch, tilesizey, ps, |
| 125 | jpegbuf[0], jpegsub, flags)==-1) |
| 126 | _throwtj("executing tjEncodeYUV()"); |
| 127 | comptilesize[0]=TJBUFSIZEYUV(tilesizex, tilesizey, jpegsub); |
| 128 | } |
| 129 | else if(tjCompress(hnd, rgbbuf, tilesizex, pitch, tilesizey, ps, |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 130 | jpegbuf[0], &comptilesize[0], jpegsub, qual, flags)==-1) |
| 131 | _throwtj("executing tjCompress()"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 132 | ITER=0; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 133 | start=rrtime(); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 134 | do |
| 135 | { |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 136 | jpgbufsize=0; tilen=0; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 137 | for(i=0; i<h; i+=tilesizey) |
| 138 | { |
| 139 | for(j=0; j<w; j+=tilesizex) |
| 140 | { |
| 141 | int tempw=min(tilesizex, w-j), temph=min(tilesizey, h-i); |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 142 | if(yuv==YUVENCODE) |
| 143 | { |
| 144 | if(tjEncodeYUV(hnd, &rgbbuf[pitch*i+j*ps], tempw, pitch, |
| 145 | temph, ps, jpegbuf[tilen], jpegsub, flags)==-1) |
| 146 | _throwtj("executing tjEncodeYUV()"); |
| 147 | comptilesize[tilen]=TJBUFSIZEYUV(tempw, temph, jpegsub); |
| 148 | } |
| 149 | else if(tjCompress(hnd, &rgbbuf[pitch*i+j*ps], tempw, pitch, |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 150 | temph, ps, jpegbuf[tilen], &comptilesize[tilen], jpegsub, qual, |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 151 | flags)==-1) |
| 152 | _throwtj("executing tjCompress()"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 153 | jpgbufsize+=comptilesize[tilen]; |
| 154 | tilen++; |
| 155 | } |
| 156 | } |
| 157 | ITER++; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 158 | } while((elapsed=rrtime()-start)<5.); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 159 | if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()"); |
| 160 | hnd=NULL; |
DRC | 2a28599 | 2011-02-19 17:20:11 +0000 | [diff] [blame] | 161 | if(quiet==1) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 162 | { |
| 163 | if(tilesizex==w && tilesizey==h) printf("Full \t"); |
| 164 | else printf("%-4d %-4d\t", tilesizex, tilesizey); |
DRC | 2a28599 | 2011-02-19 17:20:11 +0000 | [diff] [blame] | 165 | } |
| 166 | if(quiet) |
| 167 | { |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 168 | printsigfig((double)(w*h)/1000000.*(double)ITER/elapsed, 4); |
DRC | 2a28599 | 2011-02-19 17:20:11 +0000 | [diff] [blame] | 169 | printf("%c", quiet==2? '\n':'\t'); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 170 | printsigfig((double)(w*h*ps)/(double)jpgbufsize, 4); |
DRC | 2a28599 | 2011-02-19 17:20:11 +0000 | [diff] [blame] | 171 | printf("%c", quiet==2? '\n':'\t'); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 172 | } |
| 173 | else |
| 174 | { |
| 175 | if(tilesizex==w && tilesizey==h) printf("\nFull image\n"); |
| 176 | else printf("\nTile size: %d x %d\n", tilesizex, tilesizey); |
| 177 | printf("C--> Frame rate: %f fps\n", (double)ITER/elapsed); |
| 178 | printf(" Output image size: %d bytes\n", jpgbufsize); |
| 179 | printf(" Compression ratio: %f:1\n", |
| 180 | (double)(w*h*ps)/(double)jpgbufsize); |
| 181 | printf(" Source throughput: %f Megapixels/sec\n", |
| 182 | (double)(w*h)/1000000.*(double)ITER/elapsed); |
| 183 | printf(" Output bit stream: %f Megabits/sec\n", |
| 184 | (double)jpgbufsize*8./1000000.*(double)ITER/elapsed); |
| 185 | } |
| 186 | if(tilesizex==w && tilesizey==h) |
| 187 | { |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 188 | if(yuv==YUVENCODE) |
DRC | fbb6747 | 2010-11-24 04:02:37 +0000 | [diff] [blame] | 189 | sprintf(tempstr, "%s_%s.yuv", filename, _subnames[jpegsub]); |
| 190 | else |
| 191 | sprintf(tempstr, "%s_%sQ%d.jpg", filename, _subnames[jpegsub], qual); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 192 | if((outfile=fopen(tempstr, "wb"))==NULL) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 193 | _throwunix("opening reference image"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 194 | if(fwrite(jpegbuf[0], jpgbufsize, 1, outfile)!=1) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 195 | _throwunix("writing reference image"); |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 196 | fclose(outfile); outfile=NULL; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 197 | if(!quiet) printf("Reference image written to %s\n", tempstr); |
| 198 | } |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 199 | if(yuv==YUVENCODE) |
| 200 | { |
| 201 | if(quiet==1) printf("\n"); goto bailout; |
| 202 | } |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 203 | |
| 204 | // Decompression test |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 205 | memset(rgbbuf, 127, max(yuvsize, pitch*h)); // Grey image means decompressor did nothing |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 206 | if((hnd=tjInitDecompress())==NULL) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 207 | _throwtj("executing tjInitDecompress()"); |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 208 | if(yuv==YUVDECODE) |
| 209 | { |
| 210 | if(tjDecompressToYUV(hnd, jpegbuf[0], jpgbufsize, rgbbuf, flags)==-1) |
| 211 | _throwtj("executing tjDecompressToYUV()"); |
| 212 | } |
| 213 | else if(tjDecompress(hnd, jpegbuf[0], jpgbufsize, rgbbuf, tilesizex, pitch, |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 214 | tilesizey, ps, flags)==-1) |
| 215 | _throwtj("executing tjDecompress()"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 216 | ITER=0; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 217 | start=rrtime(); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 218 | do |
| 219 | { |
| 220 | int tilen=0; |
| 221 | for(i=0; i<h; i+=tilesizey) |
| 222 | { |
| 223 | for(j=0; j<w; j+=tilesizex) |
| 224 | { |
| 225 | int tempw=min(tilesizex, w-j), temph=min(tilesizey, h-i); |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 226 | if(yuv==YUVDECODE) |
| 227 | { |
| 228 | if(tjDecompressToYUV(hnd, jpegbuf[tilen], comptilesize[tilen], |
| 229 | &rgbbuf[pitch*i+ps*j], flags)==-1) |
| 230 | _throwtj("executing tjDecompressToYUV()"); |
| 231 | } |
| 232 | else if(tjDecompress(hnd, jpegbuf[tilen], comptilesize[tilen], |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 233 | &rgbbuf[pitch*i+ps*j], tempw, pitch, temph, ps, flags)==-1) |
| 234 | _throwtj("executing tjDecompress()"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 235 | tilen++; |
| 236 | } |
| 237 | } |
| 238 | ITER++; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 239 | } while((elapsed=rrtime()-start)<5.); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 240 | if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()"); |
| 241 | hnd=NULL; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 242 | if(quiet) |
| 243 | { |
| 244 | printsigfig((double)(w*h)/1000000.*(double)ITER/elapsed, 4); |
| 245 | printf("\n"); |
| 246 | } |
| 247 | else |
| 248 | { |
| 249 | printf("D--> Frame rate: %f fps\n", (double)ITER/elapsed); |
| 250 | printf(" Dest. throughput: %f Megapixels/sec\n", |
| 251 | (double)(w*h)/1000000.*(double)ITER/elapsed); |
| 252 | } |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 253 | if(yuv==YUVDECODE) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 254 | { |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 255 | sprintf(tempstr, "%s_%sQ%d.yuv", filename, _subnames[jpegsub], qual); |
| 256 | if((outfile=fopen(tempstr, "wb"))==NULL) |
| 257 | _throwunix("opening YUV image for output"); |
| 258 | if(fwrite(rgbbuf, yuvsize, 1, outfile)!=1) |
| 259 | _throwunix("writing YUV image"); |
| 260 | fclose(outfile); outfile=NULL; |
| 261 | } |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 262 | else |
| 263 | { |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 264 | if(tilesizex==w && tilesizey==h) |
| 265 | sprintf(tempstr, "%s_%sQ%d_full.%s", filename, _subnames[jpegsub], qual, |
| 266 | useppm?"ppm":"bmp"); |
| 267 | else sprintf(tempstr, "%s_%sQ%d_%dx%d.%s", filename, _subnames[jpegsub], |
| 268 | qual, tilesizex, tilesizey, useppm?"ppm":"bmp"); |
| 269 | if(savebmp(tempstr, rgbbuf, w, h, pf, pitch, bu)==-1) |
| 270 | _throwbmp("saving bitmap"); |
| 271 | sprintf(strrchr(tempstr, '.'), "-err.%s", useppm?"ppm":"bmp"); |
| 272 | if(!quiet) |
| 273 | printf("Computing compression error and saving to %s.\n", tempstr); |
| 274 | if(jpegsub==TJ_GRAYSCALE) |
| 275 | { |
| 276 | for(j=0; j<h; j++) |
| 277 | { |
| 278 | for(i=0; i<w*ps; i+=ps) |
| 279 | { |
| 280 | int y=(int)((double)srcbuf[w*ps*j+i+_rindex[pf]]*0.299 |
| 281 | + (double)srcbuf[w*ps*j+i+_gindex[pf]]*0.587 |
| 282 | + (double)srcbuf[w*ps*j+i+_bindex[pf]]*0.114 + 0.5); |
| 283 | if(y>255) y=255; if(y<0) y=0; |
| 284 | rgbbuf[pitch*j+i+_rindex[pf]]=abs(rgbbuf[pitch*j+i+_rindex[pf]]-y); |
| 285 | rgbbuf[pitch*j+i+_gindex[pf]]=abs(rgbbuf[pitch*j+i+_gindex[pf]]-y); |
| 286 | rgbbuf[pitch*j+i+_bindex[pf]]=abs(rgbbuf[pitch*j+i+_bindex[pf]]-y); |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | for(j=0; j<h; j++) for(i=0; i<w*ps; i++) |
| 293 | rgbbuf[pitch*j+i]=abs(rgbbuf[pitch*j+i]-srcbuf[w*ps*j+i]); |
| 294 | } |
| 295 | if(savebmp(tempstr, rgbbuf, w, h, pf, pitch, bu)==-1) |
| 296 | _throwbmp("saving bitmap"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 297 | } |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 298 | |
| 299 | // Cleanup |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 300 | if(outfile) {fclose(outfile); outfile=NULL;} |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 301 | if(jpegbuf) |
| 302 | { |
| 303 | for(i=0; i<numtilesx*numtilesy; i++) |
| 304 | {if(jpegbuf[i]) free(jpegbuf[i]); jpegbuf[i]=NULL;} |
| 305 | free(jpegbuf); jpegbuf=NULL; |
| 306 | } |
| 307 | if(comptilesize) {free(comptilesize); comptilesize=NULL;} |
| 308 | } while(tilesizex<w || tilesizey<h); |
| 309 | |
| 310 | if(rgbbuf) {free(rgbbuf); rgbbuf=NULL;} |
| 311 | return; |
| 312 | |
| 313 | bailout: |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 314 | if(outfile) {fclose(outfile); outfile=NULL;} |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 315 | if(jpegbuf) |
| 316 | { |
| 317 | for(i=0; i<numtilesx*numtilesy; i++) |
| 318 | {if(jpegbuf[i]) free(jpegbuf[i]); jpegbuf[i]=NULL;} |
| 319 | free(jpegbuf); jpegbuf=NULL; |
| 320 | } |
| 321 | if(comptilesize) {free(comptilesize); comptilesize=NULL;} |
| 322 | if(rgbbuf) {free(rgbbuf); rgbbuf=NULL;} |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 323 | if(hnd) {tjDestroy(hnd); hnd=NULL;} |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 324 | return; |
| 325 | } |
| 326 | |
| 327 | |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 328 | void dodecomptest(char *filename, int pf, int bu, int useppm, |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 329 | int quiet) |
| 330 | { |
| 331 | char tempstr[1024]; |
| 332 | FILE *file=NULL; tjhandle hnd; |
| 333 | unsigned char *jpegbuf=NULL, *rgbbuf=NULL; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 334 | double start, elapsed; |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 335 | int w, h, ITER; |
| 336 | unsigned long jpgbufsize=0; |
| 337 | int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0) |
| 338 | |(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0) |
| 339 | |(fastupsample?TJ_FASTUPSAMPLE:0); |
DRC | cad1cfe | 2010-12-14 01:22:00 +0000 | [diff] [blame] | 340 | int ps=_ps[pf], pitch, jpegsub=-1; |
DRC | 61c15bd | 2010-11-13 05:31:25 +0000 | [diff] [blame] | 341 | char *temp=NULL; |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 342 | int yuvsize, bufsize; |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 343 | |
| 344 | flags |= _flags[pf]; |
| 345 | if(bu) flags |= TJ_BOTTOMUP; |
| 346 | |
| 347 | if((file=fopen(filename, "rb"))==NULL) |
| 348 | _throwunix("opening file"); |
DRC | 61c15bd | 2010-11-13 05:31:25 +0000 | [diff] [blame] | 349 | if(fseek(file, 0, SEEK_END)<0 || (jpgbufsize=ftell(file))<0) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 350 | _throwunix("determining file size"); |
DRC | 61c15bd | 2010-11-13 05:31:25 +0000 | [diff] [blame] | 351 | if((jpegbuf=(unsigned char *)malloc(jpgbufsize))==NULL) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 352 | _throwunix("allocating memory"); |
| 353 | if(fseek(file, 0, SEEK_SET)<0) |
| 354 | _throwunix("setting file position"); |
DRC | 61c15bd | 2010-11-13 05:31:25 +0000 | [diff] [blame] | 355 | if(fread(jpegbuf, jpgbufsize, 1, file)<1) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 356 | _throwunix("reading JPEG data"); |
DRC | cad1cfe | 2010-12-14 01:22:00 +0000 | [diff] [blame] | 357 | fclose(file); file=NULL; |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 358 | |
| 359 | temp=strrchr(filename, '.'); |
| 360 | if(temp!=NULL) *temp='\0'; |
| 361 | |
| 362 | if((hnd=tjInitDecompress())==NULL) _throwtj("executing tjInitDecompress()"); |
DRC | cad1cfe | 2010-12-14 01:22:00 +0000 | [diff] [blame] | 363 | if(tjDecompressHeader2(hnd, jpegbuf, jpgbufsize, &w, &h, &jpegsub)==-1) |
| 364 | _throwtj("executing tjDecompressHeader2()"); |
| 365 | |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 366 | yuvsize=TJBUFSIZEYUV(w, h, jpegsub); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 367 | |
| 368 | pitch=w*ps; |
| 369 | |
DRC | 2a28599 | 2011-02-19 17:20:11 +0000 | [diff] [blame] | 370 | if(quiet==1) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 371 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 372 | printf("All performance values in Mpixels/sec\n\n"); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 373 | printf("Bitmap\tBitmap\tImage Size\tDecomp\n"), |
| 374 | printf("Format\tOrder\t X Y \tPerf\n\n"); |
| 375 | printf("%s\t%s\t%-4d %-4d\t", _pfname[pf], bu?"BU":"TD", w, h); |
| 376 | } |
| 377 | |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 378 | bufsize=(yuv==YUVDECODE? yuvsize:pitch*h); |
| 379 | if((rgbbuf=(unsigned char *)malloc(bufsize))==NULL) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 380 | _throwunix("allocating image buffer"); |
| 381 | |
| 382 | if(!quiet) |
| 383 | { |
DRC | cad1cfe | 2010-12-14 01:22:00 +0000 | [diff] [blame] | 384 | if(yuv==YUVDECODE) |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 385 | printf(">>>>> JPEG --> YUV %s <<<<<\n", _subnamel[jpegsub]); |
DRC | cad1cfe | 2010-12-14 01:22:00 +0000 | [diff] [blame] | 386 | else |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 387 | printf(">>>>> JPEG --> %s (%s) <<<<<\n", _pfname[pf], |
DRC | cad1cfe | 2010-12-14 01:22:00 +0000 | [diff] [blame] | 388 | bu?"Bottom-up":"Top-down"); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 389 | printf("\nImage size: %d x %d\n", w, h); |
| 390 | } |
| 391 | |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 392 | memset(rgbbuf, 127, bufsize); // Grey image means decompressor did nothing |
| 393 | if(yuv==YUVDECODE) |
| 394 | { |
| 395 | if(tjDecompressToYUV(hnd, jpegbuf, jpgbufsize, rgbbuf, flags)==-1) |
| 396 | _throwtj("executing tjDecompressToYUV()"); |
| 397 | } |
| 398 | else if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, |
| 399 | flags)==-1) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 400 | _throwtj("executing tjDecompress()"); |
| 401 | ITER=0; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 402 | start=rrtime(); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 403 | do |
| 404 | { |
DRC | eeab695 | 2011-02-25 00:02:04 +0000 | [diff] [blame^] | 405 | if(yuv==YUVDECODE) |
| 406 | { |
| 407 | if(tjDecompressToYUV(hnd, jpegbuf, jpgbufsize, rgbbuf, flags)==-1) |
| 408 | _throwtj("executing tjDecompressToYUV()"); |
| 409 | } |
| 410 | else if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, |
| 411 | flags)==-1) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 412 | _throwtj("executing tjDecompress()"); |
| 413 | ITER++; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 414 | } while((elapsed=rrtime()-start)<5.); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 415 | if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()"); |
| 416 | hnd=NULL; |
| 417 | if(quiet) |
| 418 | { |
| 419 | printsigfig((double)(w*h)/1000000.*(double)ITER/elapsed, 4); |
| 420 | printf("\n"); |
| 421 | } |
| 422 | else |
| 423 | { |
| 424 | printf("D--> Frame rate: %f fps\n", (double)ITER/elapsed); |
| 425 | printf(" Dest. throughput: %f Megapixels/sec\n", |
| 426 | (double)(w*h)/1000000.*(double)ITER/elapsed); |
| 427 | } |
| 428 | sprintf(tempstr, "%s_full.%s", filename, useppm?"ppm":"bmp"); |
DRC | cad1cfe | 2010-12-14 01:22:00 +0000 | [diff] [blame] | 429 | if(yuv==YUVDECODE) |
| 430 | { |
| 431 | sprintf(tempstr, "%s_%s.yuv", filename, _subnames[jpegsub]); |
| 432 | if((file=fopen(tempstr, "wb"))==NULL) |
| 433 | _throwunix("opening YUV image for output"); |
| 434 | if(fwrite(rgbbuf, yuvsize, 1, file)!=1) |
| 435 | _throwunix("writing YUV image"); |
| 436 | fclose(file); file=NULL; |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | if(savebmp(tempstr, rgbbuf, w, h, pf, pitch, bu)==-1) |
| 441 | _throwbmp("saving bitmap"); |
| 442 | } |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 443 | |
| 444 | bailout: |
DRC | cad1cfe | 2010-12-14 01:22:00 +0000 | [diff] [blame] | 445 | if(file) {fclose(file); file=NULL;} |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 446 | if(jpegbuf) {free(jpegbuf); jpegbuf=NULL;} |
| 447 | if(rgbbuf) {free(rgbbuf); rgbbuf=NULL;} |
| 448 | if(hnd) {tjDestroy(hnd); hnd=NULL;} |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | |
| 453 | void usage(char *progname) |
| 454 | { |
DRC | e89bbae | 2010-11-12 10:18:08 +0000 | [diff] [blame] | 455 | printf("USAGE: %s <Inputfile (BMP|PPM))> <%% Quality>\n", progname); |
| 456 | printf(" %s <Inputfile (JPG))>\n\n", progname); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 457 | printf(" [-tile]\n"); |
| 458 | printf(" Test performance of the codec when the image is encoded\n"); |
| 459 | printf(" as separate tiles of varying sizes.\n\n"); |
| 460 | printf(" [-forcemmx] [-forcesse] [-forcesse2] [-forcesse3]\n"); |
DRC | b4b3140 | 2011-02-19 17:31:24 +0000 | [diff] [blame] | 461 | printf(" Force MMX, SSE, SSE2, or SSE3 code paths in the underlying codec\n\n"); |
| 462 | printf(" [-rgb | -bgr | -rgbx | -bgrx | -xbgr | -xrgb]\n"); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 463 | printf(" Test the specified color conversion path in the codec (default: BGR)\n\n"); |
| 464 | printf(" [-fastupsample]\n"); |
| 465 | printf(" Use fast, inaccurate upsampling code to perform 4:2:2 and 4:2:0\n"); |
| 466 | printf(" YUV decoding in libjpeg decompressor\n\n"); |
| 467 | printf(" [-quiet]\n"); |
DRC | ac08ef6 | 2010-12-09 10:01:57 +0000 | [diff] [blame] | 468 | printf(" Output in tabular rather than verbose format\n\n"); |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 469 | printf(" [-yuvencode]\n"); |
DRC | fbb6747 | 2010-11-24 04:02:37 +0000 | [diff] [blame] | 470 | printf(" Encode RGB input as planar YUV rather than compressing as JPEG\n\n"); |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 471 | printf(" [-yuvdecode]\n"); |
| 472 | printf(" Decode JPEG image to planar YUV rather than RGB\n\n"); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 473 | printf(" NOTE: If the quality is specified as a range, i.e. 90-100, a separate\n"); |
| 474 | printf(" test will be performed for all quality values in the range.\n"); |
| 475 | exit(1); |
| 476 | } |
| 477 | |
| 478 | |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 479 | int main(int argc, char *argv[]) |
| 480 | { |
| 481 | unsigned char *bmpbuf=NULL; int w, h, i, useppm=0; |
| 482 | int qual, dotile=0, quiet=0, hiqual=-1; char *temp; |
DRC | 2e4d044 | 2011-02-08 01:18:37 +0000 | [diff] [blame] | 483 | int pf=BMP_BGR; |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 484 | int bu=0, minarg=2; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 485 | |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 486 | if(argc<minarg) usage(argv[0]); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 487 | |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 488 | temp=strrchr(argv[1], '.'); |
| 489 | if(temp!=NULL) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 490 | { |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 491 | if(!stricmp(temp, ".ppm")) useppm=1; |
| 492 | if(!stricmp(temp, ".jpg") || !stricmp(temp, ".jpeg")) decomponly=1; |
| 493 | } |
| 494 | |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 495 | printf("\n"); |
| 496 | |
DRC | ac08ef6 | 2010-12-09 10:01:57 +0000 | [diff] [blame] | 497 | if(argc>minarg) |
| 498 | { |
| 499 | for(i=minarg; i<argc; i++) |
| 500 | { |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 501 | if(!stricmp(argv[i], "-yuvencode")) |
DRC | ac08ef6 | 2010-12-09 10:01:57 +0000 | [diff] [blame] | 502 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 503 | printf("Testing YUV planar encoding\n\n"); |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 504 | yuv=YUVENCODE; hiqual=qual=100; |
| 505 | } |
| 506 | if(!stricmp(argv[i], "-yuvdecode")) |
| 507 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 508 | printf("Testing YUV planar decoding\n\n"); |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 509 | yuv=YUVDECODE; |
DRC | ac08ef6 | 2010-12-09 10:01:57 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
DRC | 9e17f7d | 2010-12-10 04:59:13 +0000 | [diff] [blame] | 514 | if(!decomponly && yuv!=YUVENCODE) |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 515 | { |
| 516 | minarg=3; |
| 517 | if(argc<minarg) usage(argv[0]); |
| 518 | if((qual=atoi(argv[2]))<1 || qual>100) |
| 519 | { |
| 520 | puts("ERROR: Quality must be between 1 and 100."); |
| 521 | exit(1); |
| 522 | } |
| 523 | if((temp=strchr(argv[2], '-'))!=NULL && strlen(temp)>1 |
| 524 | && sscanf(&temp[1], "%d", &hiqual)==1 && hiqual>qual && hiqual>=1 |
| 525 | && hiqual<=100) {} |
| 526 | else hiqual=qual; |
| 527 | } |
| 528 | |
| 529 | if(argc>minarg) |
| 530 | { |
| 531 | for(i=minarg; i<argc; i++) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 532 | { |
| 533 | if(!stricmp(argv[i], "-tile")) dotile=1; |
| 534 | if(!stricmp(argv[i], "-forcesse3")) |
| 535 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 536 | printf("Using SSE3 code\n\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 537 | forcesse3=1; |
| 538 | } |
| 539 | if(!stricmp(argv[i], "-forcesse2")) |
| 540 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 541 | printf("Using SSE2 code\n\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 542 | forcesse2=1; |
| 543 | } |
| 544 | if(!stricmp(argv[i], "-forcesse")) |
| 545 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 546 | printf("Using SSE code\n\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 547 | forcesse=1; |
| 548 | } |
| 549 | if(!stricmp(argv[i], "-forcemmx")) |
| 550 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 551 | printf("Using MMX code\n\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 552 | forcemmx=1; |
| 553 | } |
DRC | 61e51f9 | 2009-04-05 21:53:20 +0000 | [diff] [blame] | 554 | if(!stricmp(argv[i], "-fastupsample")) |
| 555 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 556 | printf("Using fast upsampling code\n\n"); |
DRC | 61e51f9 | 2009-04-05 21:53:20 +0000 | [diff] [blame] | 557 | fastupsample=1; |
| 558 | } |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 559 | if(!stricmp(argv[i], "-rgb")) pf=BMP_RGB; |
DRC | b4b3140 | 2011-02-19 17:31:24 +0000 | [diff] [blame] | 560 | if(!stricmp(argv[i], "-rgbx")) pf=BMP_RGBX; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 561 | if(!stricmp(argv[i], "-bgr")) pf=BMP_BGR; |
DRC | b4b3140 | 2011-02-19 17:31:24 +0000 | [diff] [blame] | 562 | if(!stricmp(argv[i], "-bgrx")) pf=BMP_BGRX; |
| 563 | if(!stricmp(argv[i], "-xbgr")) pf=BMP_XBGR; |
| 564 | if(!stricmp(argv[i], "-xrgb")) pf=BMP_XRGB; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 565 | if(!stricmp(argv[i], "-bottomup")) bu=1; |
| 566 | if(!stricmp(argv[i], "-quiet")) quiet=1; |
DRC | 2a28599 | 2011-02-19 17:20:11 +0000 | [diff] [blame] | 567 | if(!stricmp(argv[i], "-qq")) quiet=2; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 571 | if(!decomponly) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 572 | { |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 573 | if(loadbmp(argv[1], &bmpbuf, &w, &h, pf, 1, bu)==-1) |
| 574 | _throwbmp("loading bitmap"); |
| 575 | temp=strrchr(argv[1], '.'); |
| 576 | if(temp!=NULL) *temp='\0'; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 577 | } |
| 578 | |
DRC | 2a28599 | 2011-02-19 17:20:11 +0000 | [diff] [blame] | 579 | if(quiet==1 && !decomponly) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 580 | { |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 581 | printf("All performance values in Mpixels/sec\n\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 582 | printf("Bitmap\tBitmap\tJPEG\tJPEG\tTile Size\tCompr\tCompr\tDecomp\n"); |
| 583 | printf("Format\tOrder\tFormat\tQual\t X Y \tPerf \tRatio\tPerf\n\n"); |
| 584 | } |
| 585 | |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 586 | if(decomponly) |
| 587 | { |
| 588 | dodecomptest(argv[1], pf, bu, 1, quiet); |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 589 | printf("\n"); |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 590 | goto bailout; |
| 591 | } |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 592 | for(i=hiqual; i>=qual; i--) |
| 593 | dotest(bmpbuf, w, h, pf, bu, TJ_GRAYSCALE, i, argv[1], dotile, useppm, quiet); |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 594 | printf("\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 595 | for(i=hiqual; i>=qual; i--) |
DRC | 61e51f9 | 2009-04-05 21:53:20 +0000 | [diff] [blame] | 596 | dotest(bmpbuf, w, h, pf, bu, TJ_420, i, argv[1], dotile, useppm, quiet); |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 597 | printf("\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 598 | for(i=hiqual; i>=qual; i--) |
| 599 | dotest(bmpbuf, w, h, pf, bu, TJ_422, i, argv[1], dotile, useppm, quiet); |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 600 | printf("\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 601 | for(i=hiqual; i>=qual; i--) |
| 602 | dotest(bmpbuf, w, h, pf, bu, TJ_444, i, argv[1], dotile, useppm, quiet); |
DRC | 0b11d1c | 2011-02-24 21:43:35 +0000 | [diff] [blame] | 603 | printf("\n"); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 604 | |
DRC | e8ce2e0 | 2010-11-12 10:14:11 +0000 | [diff] [blame] | 605 | bailout: |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 606 | if(bmpbuf) free(bmpbuf); |
| 607 | return 0; |
| 608 | } |