From: DRC Date: Tue, 15 Feb 2011 21:57:26 +0000 (+0000) Subject: General code cleanup X-Git-Tag: 1.1.90~244 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=993bf0e51565d2d86d311b2246d5604536a1520b;p=libjpeg-turbo General code cleanup git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@368 632fc199-4ca6-4c93-a231-07263d6284db --- diff --git a/jpgtest.c b/jpgtest.c index 6ec507a..362ade9 100644 --- a/jpgtest.c +++ b/jpgtest.c @@ -33,7 +33,7 @@ enum {YUVENCODE=1, YUVDECODE}; int forcemmx=0, forcesse=0, forcesse2=0, forcesse3=0, fastupsample=0, - decomponly=0, yuv=0; + decomponly=0, yuv=0, quiet=0, dotile=0, pf=BMP_BGR, bu=0, useppm=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}; @@ -64,8 +64,142 @@ void printsigfig(double val, int figs) printf(format, val); } -void dotest(unsigned char *srcbuf, int w, int h, int pf, int bu, - int jpegsub, int qual, char *filename, int dotile, int useppm, int quiet) +// Decompression test +int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf, + unsigned long *comptilesize, unsigned char *rgbbuf, int w, int h, + int jpegsub, int qual, char *filename, int tilesizex, int tilesizey) +{ + char tempstr[1024], qualstr[5]="\0"; + FILE *outfile=NULL; tjhandle hnd=NULL; + int flags=(forcemmx?TJ_FORCEMMX:0)|(forcesse?TJ_FORCESSE:0) + |(forcesse2?TJ_FORCESSE2:0)|(forcesse3?TJ_FORCESSE3:0) + |(fastupsample?TJ_FASTUPSAMPLE:0); + int i, j, ITER, rgbbufalloc=0; + double start, elapsed; + int ps=_ps[pf]; + int pitch=w*ps; + int hsf=_hsf[jpegsub], vsf=_vsf[jpegsub]; + int pw=PAD(w, hsf), ph=PAD(h, vsf); + int cw=pw/hsf, ch=ph/vsf; + int ypitch=PAD(pw, 4), uvpitch=PAD(cw, 4); + int yuvsize=ypitch*ph + (jpegsub==TJ_GRAYSCALE? 0:uvpitch*ch*2); + + if(qual>0) + { + snprintf(qualstr, 5, "Q%d", qual); + qualstr[4]=0; + } + + flags |= _flags[pf]; + if(bu) flags |= TJ_BOTTOMUP; + if(yuv==YUVDECODE) flags |= TJ_YUV; + if((hnd=tjInitDecompress())==NULL) + _throwtj("executing tjInitDecompress()"); + + if(rgbbuf==NULL) + { + if((rgbbuf=(unsigned char *)malloc(max(yuvsize, pitch*h))) == NULL) + _throwunix("allocating image buffer"); + rgbbufalloc=1; + } + memset(rgbbuf, 127, max(yuvsize, pitch*h)); // Grey image means decompressor did nothing + + if(tjDecompress(hnd, jpegbuf[0], comptilesize[0], rgbbuf, tilesizex, pitch, + tilesizey, ps, flags)==-1) + _throwtj("executing tjDecompress()"); + ITER=0; + start=rrtime(); + do + { + int tilen=0; + for(i=0; i Frame rate: %f fps\n", (double)ITER/elapsed); + printf(" Dest. throughput: %f Megapixels/sec\n", + (double)(w*h)/1000000.*(double)ITER/elapsed); + } + if(yuv==YUVDECODE) + { + sprintf(tempstr, "%s_%s%s.yuv", filename, _subnames[jpegsub], qualstr); + if((outfile=fopen(tempstr, "wb"))==NULL) + _throwunix("opening YUV image for output"); + if(fwrite(rgbbuf, yuvsize, 1, outfile)!=1) + _throwunix("writing YUV image"); + fclose(outfile); outfile=NULL; + } + else + { + if(tilesizex==w && tilesizey==h) + sprintf(tempstr, "%s_%s%s_full.%s", filename, _subnames[jpegsub], + qualstr, useppm?"ppm":"bmp"); + else sprintf(tempstr, "%s_%s%s_%dx%d.%s", filename, _subnames[jpegsub], + qualstr, tilesizex, tilesizey, useppm?"ppm":"bmp"); + if(savebmp(tempstr, rgbbuf, w, h, pf, pitch, bu)==-1) + _throwbmp("saving bitmap"); + sprintf(strrchr(tempstr, '.'), "-err.%s", useppm?"ppm":"bmp"); + if(srcbuf) + { + if(!quiet) + printf("Computing compression error and saving to %s.\n", tempstr); + if(jpegsub==TJ_GRAYSCALE) + { + for(j=0; j255) y=255; if(y<0) y=0; + rgbbuf[pitch*j+i+_rindex[pf]]=abs(rgbbuf[pitch*j+i+_rindex[pf]]-y); + rgbbuf[pitch*j+i+_gindex[pf]]=abs(rgbbuf[pitch*j+i+_gindex[pf]]-y); + rgbbuf[pitch*j+i+_bindex[pf]]=abs(rgbbuf[pitch*j+i+_bindex[pf]]-y); + } + } + } + else + { + for(j=0; j Frame rate: %f fps\n", (double)ITER/elapsed); - printf(" Dest. throughput: %f Megapixels/sec\n", - (double)(w*h)/1000000.*(double)ITER/elapsed); - } - if(yuv==YUVDECODE) - { - sprintf(tempstr, "%s_%sQ%d.yuv", filename, _subnames[jpegsub], qual); - if((outfile=fopen(tempstr, "wb"))==NULL) - _throwunix("opening YUV image for output"); - if(fwrite(rgbbuf, yuvsize, 1, outfile)!=1) - _throwunix("writing YUV image"); - fclose(outfile); outfile=NULL; - } - else - { - if(tilesizex==w && tilesizey==h) - sprintf(tempstr, "%s_%sQ%d_full.%s", filename, _subnames[jpegsub], qual, - useppm?"ppm":"bmp"); - else sprintf(tempstr, "%s_%sQ%d_%dx%d.%s", filename, _subnames[jpegsub], - qual, tilesizex, tilesizey, useppm?"ppm":"bmp"); - if(savebmp(tempstr, rgbbuf, w, h, pf, pitch, bu)==-1) - _throwbmp("saving bitmap"); - sprintf(strrchr(tempstr, '.'), "-err.%s", useppm?"ppm":"bmp"); - if(!quiet) - printf("Computing compression error and saving to %s.\n", tempstr); - if(jpegsub==TJ_GRAYSCALE) - { - for(j=0; j255) y=255; if(y<0) y=0; - rgbbuf[pitch*j+i+_rindex[pf]]=abs(rgbbuf[pitch*j+i+_rindex[pf]]-y); - rgbbuf[pitch*j+i+_gindex[pf]]=abs(rgbbuf[pitch*j+i+_gindex[pf]]-y); - rgbbuf[pitch*j+i+_bindex[pf]]=abs(rgbbuf[pitch*j+i+_bindex[pf]]-y); - } - } - } - else - { - for(j=0; j>>>> JPEG --> YUV %s <<<<<\n", _subnamel[jpegsub]); @@ -369,51 +405,12 @@ void dodecomptest(char *filename, int pf, int bu, int useppm, printf("\nImage size: %d x %d\n", w, h); } - memset(rgbbuf, 127, max(yuvsize, 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; - start=rrtime(); - do - { - if(tjDecompress(hnd, jpegbuf, jpgbufsize, rgbbuf, w, pitch, h, ps, flags) - ==-1) - _throwtj("executing tjDecompress()"); - ITER++; - } while((elapsed=rrtime()-start)<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(yuv==YUVDECODE) - { - sprintf(tempstr, "%s_%s.yuv", filename, _subnames[jpegsub]); - if((file=fopen(tempstr, "wb"))==NULL) - _throwunix("opening YUV image for output"); - if(fwrite(rgbbuf, yuvsize, 1, file)!=1) - _throwunix("writing YUV image"); - fclose(file); file=NULL; - } - else - { - if(savebmp(tempstr, rgbbuf, w, h, pf, pitch, bu)==-1) - _throwbmp("saving bitmap"); - } + decomptest(NULL, &jpegbuf, &jpgbufsize, NULL, w, h, jpegsub, 0, filename, w, + h); bailout: if(file) {fclose(file); file=NULL;} if(jpegbuf) {free(jpegbuf); jpegbuf=NULL;} - if(rgbbuf) {free(rgbbuf); rgbbuf=NULL;} if(hnd) {tjDestroy(hnd); hnd=NULL;} return; } @@ -447,10 +444,9 @@ void usage(char *progname) 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; - int pf=BMP_BGR; - int bu=0, minarg=2; + unsigned char *bmpbuf=NULL; int w, h, i; + int qual, hiqual=-1; char *temp; + int minarg=2; printf("\n"); @@ -553,20 +549,20 @@ int main(int argc, char *argv[]) if(decomponly) { - dodecomptest(argv[1], pf, bu, 1, quiet); + dodecomptest(argv[1]); goto bailout; } for(i=hiqual; i>=qual; i--) - dotest(bmpbuf, w, h, pf, bu, TJ_GRAYSCALE, i, argv[1], dotile, useppm, quiet); + dotest(bmpbuf, w, h, TJ_GRAYSCALE, i, argv[1]); if(quiet) printf("\n"); for(i=hiqual; i>=qual; i--) - dotest(bmpbuf, w, h, pf, bu, TJ_420, i, argv[1], dotile, useppm, quiet); + dotest(bmpbuf, w, h, TJ_420, i, argv[1]); if(quiet) printf("\n"); for(i=hiqual; i>=qual; i--) - dotest(bmpbuf, w, h, pf, bu, TJ_422, i, argv[1], dotile, useppm, quiet); + dotest(bmpbuf, w, h, TJ_422, i, argv[1]); if(quiet) printf("\n"); for(i=hiqual; i>=qual; i--) - dotest(bmpbuf, w, h, pf, bu, TJ_444, i, argv[1], dotile, useppm, quiet); + dotest(bmpbuf, w, h, TJ_444, i, argv[1]); bailout: if(bmpbuf) free(bmpbuf);