From: DRC Date: Fri, 12 Nov 2010 10:14:11 +0000 (+0000) Subject: Add option to test decompression only + clean up error handling X-Git-Tag: 1.0.90~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e8ce2e0864edad1a7732e563ab2f2fdc314c4130;p=libjpeg-turbo Add option to test decompression only + clean up error handling git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@291 632fc199-4ca6-4c93-a231-07263d6284db --- diff --git a/jpgtest.cxx b/jpgtest.cxx index b1c5e1a..81f8bf5 100644 --- a/jpgtest.cxx +++ b/jpgtest.cxx @@ -1,6 +1,6 @@ /* Copyright (C)2004 Landmark Graphics Corporation * Copyright (C)2005, 2006 Sun Microsystems, Inc. - * Copyright (C)2009 D. R. Commander + * Copyright (C)2009-2010 D. R. Commander * * This library is free software and may be redistributed and/or modified under * the terms of the wxWindows Library License, Version 3.1 or (at your option) @@ -17,14 +17,20 @@ #include #include #include +#include #include "./bmp.h" #include "./rrutil.h" #include "./rrtimer.h" #include "./turbojpeg.h" -#define _catch(f) {if((f)==-1) {printf("Error in %s:\n%s\n", #f, tjGetErrorStr()); goto bailout;}} +#define _throw(op, err) { \ + printf("ERROR in line %d while %s:\n%s\n", __LINE__, op, err); goto bailout;} +#define _throwunix(m) _throw(m, strerror(errno)) +#define _throwtj(m) _throw(m, tjGetErrorStr()) +#define _throwbmp(m) _throw(m, bmpgeterr()) -int forcemmx=0, forcesse=0, forcesse2=0, forcesse3=0, fastupsample=0; +int forcemmx=0, forcesse=0, forcesse2=0, forcesse3=0, fastupsample=0, + decomponly=0; const int _ps[BMPPIXELFORMATS]={3, 4, 3, 4, 4, 4}; const int _flags[BMPPIXELFORMATS]={0, 0, TJ_BGR, TJ_BGR, TJ_BGR|TJ_ALPHAFIRST, TJ_ALPHAFIRST}; @@ -72,10 +78,7 @@ void dotest(unsigned char *srcbuf, int w, int h, BMPPIXELFORMAT pf, int bu, if(bu) flags |= TJ_BOTTOMUP; if((rgbbuf=(unsigned char *)malloc(pitch*h)) == NULL) - { - puts("ERROR: Could not allocate image buffer."); - exit(1); - } + _throwunix("allocating image buffer"); if(!quiet) printf("\n>>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", _pfname[pf], bu?"Bottom-up":"Top-down", _subnamel[jpegsub], qual); @@ -89,18 +92,12 @@ void dotest(unsigned char *srcbuf, int w, int h, BMPPIXELFORMAT pf, int bu, numtilesy=(h+tilesizey-1)/tilesizey; if((comptilesize=(unsigned long *)malloc(sizeof(unsigned long)*numtilesx*numtilesy)) == NULL || (jpegbuf=(unsigned char **)malloc(sizeof(unsigned char *)*numtilesx*numtilesy)) == NULL) - { - puts("ERROR: Could not allocate image buffers."); - goto bailout; - } + _throwunix("allocating image buffers"); memset(jpegbuf, 0, sizeof(unsigned char *)*numtilesx*numtilesy); for(i=0; i>>>> JPEG --> %s (%s) <<<<<\n", _pfname[pf], + bu?"Bottom-up":"Top-down"); + printf("\nImage size: %d x %d\n", w, h); + } + + memset(rgbbuf, 127, pitch*h); // Grey image means decompressor did nothing + if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, flags)==-1) + _throwtj("executing tjDecompress()"); + ITER=0; + timer.start(); + do + { + if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, flags) + ==-1) + _throwtj("executing tjDecompress()"); + ITER++; + } while((elapsed=timer.elapsed())<5.); + if(tjDestroy(hnd)==-1) _throwtj("executing tjDestroy()"); + hnd=NULL; + if(quiet) + { + printsigfig((double)(w*h)/1000000.*(double)ITER/elapsed, 4); + printf("\n"); + } + else + { + printf("D--> Frame rate: %f fps\n", (double)ITER/elapsed); + printf(" Dest. throughput: %f Megapixels/sec\n", + (double)(w*h)/1000000.*(double)ITER/elapsed); + } + sprintf(tempstr, "%s_full.%s", filename, useppm?"ppm":"bmp"); + if(savebmp(tempstr, rgbbuf, w, h, pf, pitch, bu)==-1) + _throwbmp("saving bitmap"); + + bailout: + if(jpegbuf) {free(jpegbuf); jpegbuf=NULL;} + if(rgbbuf) {free(rgbbuf); rgbbuf=NULL;} + if(hnd) {tjDestroy(hnd); hnd=NULL;} + return; +} + + +void usage(char *progname) +{ + printf("USAGE: %s <%% Quality>\n\n", progname); + printf(" [-tile]\n"); + printf(" Test performance of the codec when the image is encoded\n"); + printf(" as separate tiles of varying sizes.\n\n"); + printf(" [-forcemmx] [-forcesse] [-forcesse2] [-forcesse3]\n"); + printf(" Force MMX, SSE, or SSE2 code paths in Intel codec\n\n"); + printf(" [-rgb | -bgr | -rgba | -bgra | -abgr | -argb]\n"); + printf(" Test the specified color conversion path in the codec (default: BGR)\n\n"); + printf(" [-fastupsample]\n"); + printf(" Use fast, inaccurate upsampling code to perform 4:2:2 and 4:2:0\n"); + printf(" YUV decoding in libjpeg decompressor\n\n"); + printf(" [-quiet]\n"); + printf(" Output in tabular rather than verbose format\n\n"); + printf(" NOTE: If the quality is specified as a range, i.e. 90-100, a separate\n"); + printf(" test will be performed for all quality values in the range.\n"); + exit(1); +} + + int main(int argc, char *argv[]) { unsigned char *bmpbuf=NULL; int w, h, i, useppm=0; int qual, dotile=0, quiet=0, hiqual=-1; char *temp; BMPPIXELFORMAT pf=BMP_BGR; - int bu=0; + int bu=0, minarg=2; printf("\n"); - if(argc<3) + if(argc <%% Quality>\n\n", argv[0]); - printf(" [-tile]\n"); - printf(" Test performance of the codec when the image is encoded\n"); - printf(" as separate tiles of varying sizes.\n\n"); - printf(" [-forcemmx] [-forcesse] [-forcesse2] [-forcesse3]\n"); - printf(" Force MMX, SSE, or SSE2 code paths in Intel codec\n\n"); - printf(" [-rgb | -bgr | -rgba | -bgra | -abgr | -argb]\n"); - printf(" Test the specified color conversion path in the codec (default: BGR)\n\n"); - printf(" [-fastupsample]\n"); - printf(" Use fast, inaccurate upsampling code to perform 4:2:2 and 4:2:0\n"); - printf(" YUV decoding in libjpeg decompressor\n\n"); - printf(" [-quiet]\n"); - printf(" Output in tabular rather than verbose format\n\n"); - printf(" NOTE: If the quality is specified as a range, i.e. 90-100, a separate\n"); - printf(" test will be performed for all quality values in the range.\n"); - exit(1); + if(!stricmp(temp, ".ppm")) useppm=1; + if(!stricmp(temp, ".jpg") || !stricmp(temp, ".jpeg")) decomponly=1; } - if((qual=atoi(argv[2]))<1 || qual>100) + + if(!decomponly) { - puts("ERROR: Quality must be between 1 and 100."); - exit(1); + minarg=3; + if(argc100) + { + puts("ERROR: Quality must be between 1 and 100."); + exit(1); + } + if((temp=strchr(argv[2], '-'))!=NULL && strlen(temp)>1 + && sscanf(&temp[1], "%d", &hiqual)==1 && hiqual>qual && hiqual>=1 + && hiqual<=100) {} + else hiqual=qual; } - if((temp=strchr(argv[2], '-'))!=NULL && strlen(temp)>1 - && sscanf(&temp[1], "%d", &hiqual)==1 && hiqual>qual && hiqual>=1 - && hiqual<=100) {} - else hiqual=qual; - if(argc>3) + if(argc>minarg) { - for(i=3; i=qual; i--) dotest(bmpbuf, w, h, pf, bu, TJ_GRAYSCALE, i, argv[1], dotile, useppm, quiet); if(quiet) printf("\n"); @@ -387,6 +484,7 @@ int main(int argc, char *argv[]) for(i=hiqual; i>=qual; i--) dotest(bmpbuf, w, h, pf, bu, TJ_444, i, argv[1], dotile, useppm, quiet); + bailout: if(bmpbuf) free(bmpbuf); return 0; }