From: DRC Date: Mon, 4 Nov 2013 23:07:54 +0000 (+0000) Subject: Add the ability to test scaling when decompressing to YUV; compression from YUV to... X-Git-Tag: 1.3.90~177 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c6501f7f5f28901470329beccf555c99d647ea6c;p=libjpeg-turbo Add the ability to test scaling when decompressing to YUV; compression from YUV to JPEG; and YUV padding. Replace clunky -411 and -440 parameters with a -subsamp parameter that allows any of the subsampling options to be tested in isolation. git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1074 632fc199-4ca6-4c93-a231-07263d6284db --- diff --git a/tjbench.c b/tjbench.c index 0164d9b..7a7bc92 100644 --- a/tjbench.c +++ b/tjbench.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -44,9 +45,9 @@ #define _throwtj(m) _throw(m, tjGetErrorStr()) #define _throwbmp(m) _throw(m, bmpgeterr()) -enum {YUVENCODE=1, YUVDECODE}; -int flags=TJFLAG_NOREALLOC, decomponly=0, yuv=0, quiet=0, dotile=0, - pf=TJPF_BGR; +enum {YUVENCODE=1, YUVDECODE, YUVCOMPRESS}; +int flags=TJFLAG_NOREALLOC, componly=0, decomponly=0, yuv=0, quiet=0, dotile=0, + pf=TJPF_BGR, yuvpad=1; char *ext="ppm"; const char *pixFormatStr[TJ_NUMPF]= { @@ -110,9 +111,9 @@ int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf, int row, col, i, dstbufalloc=0, retval=0; double start, elapsed; int ps=tjPixelSize[pf]; - int yuvsize=tjBufSizeYUV(w, h, subsamp), bufsize; - int scaledw=(yuv==YUVDECODE)? w : TJSCALED(w, sf); - int scaledh=(yuv==YUVDECODE)? h : TJSCALED(h, sf); + int scaledw=TJSCALED(w, sf); + int scaledh=TJSCALED(h, sf); + int yuvsize=tjBufSizeYUV2(scaledw, yuvpad, scaledh, subsamp), bufsize; int pitch=scaledw*ps; int ntilesw=(w+tilew-1)/tilew, ntilesh=(h+tileh-1)/tileh; unsigned char *dstptr, *dstptr2; @@ -140,8 +141,9 @@ int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf, /* Execute once to preload cache */ if(yuv==YUVDECODE) { - if(tjDecompressToYUV(handle, jpegbuf[0], jpegsize[0], dstbuf, flags)==-1) - _throwtj("executing tjDecompressToYUV()"); + if(tjDecompressToYUV2(handle, jpegbuf[0], jpegsize[0], dstbuf, scaledw, + yuvpad, scaledh, flags)==-1) + _throwtj("executing tjDecompressToYUV2()"); } else if(tjDecompress2(handle, jpegbuf[0], jpegsize[0], dstbuf, scaledw, pitch, scaledh, pf, flags)==-1) @@ -153,8 +155,9 @@ int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf, int tile=0; if(yuv==YUVDECODE) { - if(tjDecompressToYUV(handle, jpegbuf[0], jpegsize[0], dstbuf, flags)==-1) - _throwtj("executing tjDecompressToYUV()"); + if(tjDecompressToYUV2(handle, jpegbuf[0], jpegsize[0], dstbuf, scaledw, + yuvpad, scaledh, flags)==-1) + _throwtj("executing tjDecompressToYUV2()"); } else for(row=0, dstptr=dstbuf; row>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", pixFormatStr[pf], + printf(">>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", pfStr, (flags&TJFLAG_BOTTOMUP)? "Bottom-up":"Top-down", subNameLong[subsamp], jpegqual); @@ -375,17 +379,27 @@ void dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual, /* Compression test */ if(quiet==1) - printf("%s\t%s\t%s\t%d\t", pixFormatStr[pf], - (flags&TJFLAG_BOTTOMUP)? "BU":"TD", subNameLong[subsamp], jpegqual); - for(i=0; i [options]\n\n"); + printf(" [options]\n\n"); printf(" %s\n", progname); printf(" [options]\n\n"); printf("Options:\n\n"); @@ -705,11 +731,21 @@ void usage(char *progname) printf(" codec\n"); printf("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the\n"); printf(" underlying codec\n"); - printf("-411 = Test 4:1:1 chrominance subsampling instead of 4:2:0\n"); - printf("-440 = Test 4:4:0 chrominance subsampling instead of 4:2:2\n"); + printf("-subsamp = if compressing a JPEG image from a YUV planar source image,\n"); + printf(" this specifies the level of chrominance subsampling used in the source\n"); + printf(" image. Otherwise, this specifies the level of chrominance subsampling\n"); + printf(" to use in the JPEG destination image. = 444, 422, 440, 420, 411,\n"); + printf(" or GRAY\n"); printf("-quiet = Output results in tabular rather than verbose format\n"); printf("-yuvencode = Encode RGB input as planar YUV rather than compressing as JPEG\n"); printf("-yuvdecode = Decode JPEG image to planar YUV rather than RGB\n"); + printf("-yuvsize WxH = if compressing a JPEG image from a YUV planar source image, this\n"); + printf(" specifies the width and height of the source image.\n"); + printf("-yuvpad

= if compressing a JPEG image from a YUV planar source image, this\n"); + printf(" specifies the number of bytes to which each row of each plane in the\n"); + printf(" source image is padded. If decompressing a JPEG image to a YUV planar\n"); + printf(" destination image, this specifies the row padding for each plane of the\n"); + printf(" destination image. (default=1)\n"); printf("-scale M/N = scale down the width/height of the decompressed JPEG image by a\n"); printf(" factor of M/N (M/N = "); for(i=0; i = Run each benchmark for at least seconds (default = 5.0)\n\n"); + printf("-benchtime = Run each benchmark for at least seconds (default = 5.0)\n"); + printf("-componly = Stop after running compression tests. Do not test decompression.\n\n"); printf("NOTE: If the quality is specified as a range (e.g. 90-100), a separate\n"); printf("test will be performed for all quality values in the range.\n\n"); exit(1); @@ -738,9 +775,9 @@ void usage(char *progname) int main(int argc, char *argv[]) { - unsigned char *srcbuf=NULL; int w, h, i, j; + unsigned char *srcbuf=NULL; int w=0, h=0, i, j; int minqual=-1, maxqual=-1; char *temp; - int minarg=2, retval=0, do440=0, do411=0; + int minarg=2, retval=0, subsamp=-1; if((scalingfactors=tjGetScalingFactors(&nsf))==NULL || nsf==0) _throwtj("executing tjGetScalingFactors()"); @@ -752,6 +789,7 @@ int main(int argc, char *argv[]) { if(!strcasecmp(temp, ".bmp")) ext="bmp"; if(!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg")) decomponly=1; + if(!strcasecmp(temp, ".yuv")) yuv=YUVCOMPRESS; } printf("\n"); @@ -811,7 +849,6 @@ int main(int argc, char *argv[]) printf("Using most accurate DCT/IDCT algorithm\n\n"); flags|=TJFLAG_ACCURATEDCT; } - if(!strcmp(argv[i], "-440")) do440=1; if(!strcasecmp(argv[i], "-rgb")) pf=TJPF_RGB; if(!strcasecmp(argv[i], "-rgbx")) pf=TJPF_RGBX; if(!strcasecmp(argv[i], "-bgr")) pf=TJPF_BGR; @@ -858,10 +895,44 @@ int main(int argc, char *argv[]) if(!strcmp(argv[i], "-?")) usage(argv[0]); if(!strcasecmp(argv[i], "-alloc")) flags&=(~TJFLAG_NOREALLOC); if(!strcasecmp(argv[i], "-bmp")) ext="bmp"; - if(!strcasecmp(argv[i], "-411")) do411=1; + if(!strcasecmp(argv[i], "-yuvsize") && i=1 + && temp2>=1) + { + w=temp1; h=temp2; + } + else usage(argv[0]); + } + if(!strcasecmp(argv[i], "-yuvpad") && i=1) yuvpad=temp; + } + if(!strcasecmp(argv[i], "-subsamp") && i=TJ_NUMSAMP) + _throw("opening YUV image file", + "YUV image size and/or subsampling not specified"); + if((file=fopen(argv[1], "rb"))==NULL) + _throwunix("opening YUV image file"); + if(fseek(file, 0, SEEK_END)<0 || + (srcsize=ftell(file))==(unsigned long)-1) + _throwunix("determining YUV image file size"); + if(srcsize!=tjBufSizeYUV2(w, yuvpad, h, subsamp)) + _throw("opening YUV image file", "YUV image file is the wrong size"); + if((srcbuf=(unsigned char *)malloc(srcsize))==NULL) + _throwunix("allocating memory for YUV image"); + if(fseek(file, 0, SEEK_SET)<0) + _throwunix("setting YUV image file position"); + if(fread(srcbuf, srcsize, 1, file)<1) + _throwunix("reading YUV data"); + fclose(file); file=NULL; + } + else + { + if(loadbmp(argv[1], &srcbuf, &w, &h, pf, (flags&TJFLAG_BOTTOMUP)!=0)==-1) + _throwbmp("loading bitmap"); + } temp=strrchr(argv[1], '.'); if(temp!=NULL) *temp='\0'; } @@ -898,18 +993,27 @@ int main(int argc, char *argv[]) printf("\n"); goto bailout; } - for(i=maxqual; i>=minqual; i--) - dotest(srcbuf, w, h, TJ_GRAYSCALE, i, argv[1]); - printf("\n"); - for(i=maxqual; i>=minqual; i--) - dotest(srcbuf, w, h, do411? TJSAMP_411:TJ_420, i, argv[1]); - printf("\n"); - for(i=maxqual; i>=minqual; i--) - dotest(srcbuf, w, h, do440? TJSAMP_440:TJ_422, i, argv[1]); - printf("\n"); - for(i=maxqual; i>=minqual; i--) - dotest(srcbuf, w, h, TJ_444, i, argv[1]); - printf("\n"); + if(yuv==YUVCOMPRESS || (subsamp>=0 && subsamp=minqual; i--) + dotest(srcbuf, w, h, subsamp, i, argv[1]); + printf("\n"); + } + else + { + for(i=maxqual; i>=minqual; i--) + dotest(srcbuf, w, h, TJSAMP_GRAY, i, argv[1]); + printf("\n"); + for(i=maxqual; i>=minqual; i--) + dotest(srcbuf, w, h, TJSAMP_420, i, argv[1]); + printf("\n"); + for(i=maxqual; i>=minqual; i--) + dotest(srcbuf, w, h, TJSAMP_422, i, argv[1]); + printf("\n"); + for(i=maxqual; i>=minqual; i--) + dotest(srcbuf, w, h, TJSAMP_444, i, argv[1]); + printf("\n"); + } bailout: if(srcbuf) free(srcbuf);