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