fclose(outfile); outfile=NULL;
if(!quiet) printf("Reference image written to %s\n", tempstr);
}
- if(yuv==YUVENCODE) goto bailout;
+ if(yuv==YUVENCODE)
+ {
+ if(quiet==1) printf("\n"); goto bailout;
+ }
// Decompression test
- if(yuv==YUVDECODE) flags |= TJ_YUV;
- memset(rgbbuf, 127, max(yuvsize, pitch*h)); // Grey image means decompressor did nothing
- if((hnd=tjInitDecompress())==NULL)
- _throwtj("executing tjInitDecompress()");
- if(tjDecompress(hnd, jpegbuf[0], jpgbufsize, rgbbuf, tilesizex, pitch,
- tilesizey, ps, flags)==-1)
- _throwtj("executing tjDecompress()");
- ITER=0;
- start=rrtime();
- do
- {
- int tilen=0;
- for(i=0; i<h; i+=tilesizey)
- {
- for(j=0; j<w; j+=tilesizex)
- {
- int tempw=min(tilesizex, w-j), temph=min(tilesizey, h-i);
- if(tjDecompress(hnd, jpegbuf[tilen], comptilesize[tilen],
- &rgbbuf[pitch*i+ps*j], tempw, pitch, temph, ps, flags)==-1)
- _throwtj("executing tjDecompress()");
- tilen++;
- }
- }
- 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);
- }
- 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; j<h; j++)
- {
- for(i=0; i<w*ps; i+=ps)
- {
- int y=(int)((double)srcbuf[w*ps*j+i+_rindex[pf]]*0.299
- + (double)srcbuf[w*ps*j+i+_gindex[pf]]*0.587
- + (double)srcbuf[w*ps*j+i+_bindex[pf]]*0.114 + 0.5);
- if(y>255) 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<h; j++) for(i=0; i<w*ps; i++)
- rgbbuf[pitch*j+i]=abs(rgbbuf[pitch*j+i]-srcbuf[w*ps*j+i]);
- }
- if(savebmp(tempstr, rgbbuf, w, h, pf, pitch, bu)==-1)
- _throwbmp("saving bitmap");
- }
+ if(decomptest(srcbuf, jpegbuf, comptilesize, rgbbuf, w, h, jpegsub, qual,
+ filename, tilesizex, tilesizey)==-1)
+ goto bailout;
// Cleanup
if(outfile) {fclose(outfile); outfile=NULL;}
if(quiet==1)
{
- printf("\nAll performance values in Mpixels/sec\n\n");
+ printf("All performance values in Mpixels/sec\n\n");
- printf("Bitmap\tBitmap\tImage Size\tDecomp\n"),
- printf("Format\tOrder\t X Y \tPerf\n\n");
- printf("%s\t%s\t%-4d %-4d\t", _pfname[pf], bu?"BU":"TD", w, h);
+ printf("Bitmap\tBitmap\tJPEG\tImage Size\tDecomp\n"),
+ printf("Format\tOrder\tFormat\t X Y \tPerf\n\n");
+ printf("%s\t%s\t%s\t%-4d %-4d\t", _pfname[pf], bu?"BU":"TD",
+ _subnamel[jpegsub], w, h);
}
-
- if((rgbbuf=(unsigned char *)malloc(max(yuvsize, pitch*h)))==NULL)
- _throwunix("allocating image buffer");
-
- if(!quiet)
+ else
{
if(yuv==YUVDECODE)
- printf("\n>>>>> JPEG --> YUV %s <<<<<\n", _subnamel[jpegsub]);
+ printf(">>>>> JPEG --> YUV %s <<<<<\n", _subnamel[jpegsub]);
else
- printf("\n>>>>> JPEG --> %s (%s) <<<<<\n", _pfname[pf],
+ printf(">>>>> JPEG --> %s (%s) <<<<<\n", _pfname[pf],
bu?"Bottom-up":"Top-down");
- 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("\nImage size: %d x %d", w, h);
+ if(scalefactor!=1) printf(" --> %d x %d", (w+scalefactor-1)/scalefactor,
+ (h+scalefactor-1)/scalefactor);
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(decomponly)
{
- dodecomptest(argv[1], pf, bu, 1, quiet);
+ dodecomptest(argv[1]);
+ printf("\n");
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");
+ 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");
+ 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");
+ 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]);
+ printf("\n");
bailout:
if(bmpbuf) free(bmpbuf);