From 565a5bd5f57629f1ec74b982ed8c9dbbba483d51 Mon Sep 17 00:00:00 2001 From: DRC Date: Wed, 25 May 2011 02:58:21 +0000 Subject: [PATCH] Add dynamic allocation test; Fix compression ratio output in quiet mode; Fix memory leak git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@641 632fc199-4ca6-4c93-a231-07263d6284db --- jpgtest.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/jpgtest.c b/jpgtest.c index 2c2dd5c..c58afa9 100644 --- a/jpgtest.c +++ b/jpgtest.c @@ -45,7 +45,8 @@ #define _throwbmp(m) _throw(m, bmpgeterr()) enum {YUVENCODE=1, YUVDECODE}; -int flags=0, decomponly=0, yuv=0, quiet=0, dotile=0, pf=TJPF_BGR; +int flags=TJFLAG_NOREALLOC, decomponly=0, yuv=0, quiet=0, dotile=0, + pf=TJPF_BGR; char *ext="ppm"; const char *pixFormatStr[TJ_NUMPF]= { @@ -305,7 +306,7 @@ void dotestyuv(unsigned char *srcbuf, int w, int h, int subsamp, void dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual, char *filename) { - char tempstr[1024]; + char tempstr[1024], tempstr2[80]; FILE *file=NULL; tjhandle handle=NULL; unsigned char **jpegbuf=NULL, *tmpbuf=NULL, *srcptr, *srcptr2; double start, elapsed; @@ -331,16 +332,18 @@ void dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual, if((jpegbuf=(unsigned char **)malloc(sizeof(unsigned char *) *ntilesw*ntilesh))==NULL) _throwunix("allocating JPEG tile array"); + memset(jpegbuf, 0, sizeof(unsigned char *)*ntilesw*ntilesh); if((jpegsize=(unsigned long *)malloc(sizeof(unsigned long) *ntilesw*ntilesh))==NULL) _throwunix("allocating JPEG size array"); - memset(jpegbuf, 0, sizeof(unsigned char *)*ntilesw*ntilesh); + memset(jpegsize, 0, sizeof(unsigned long)*ntilesw*ntilesh); - for(i=0; i [options]\n\n"); printf("Options:\n\n"); + printf("-alloc = Dynamically allocate JPEG image buffers\n"); printf("-bmp = Generate output images in Windows Bitmap format (default=PPM)\n"); printf("-bottomup = Test bottom-up compression/decompression\n"); printf("-tile = Test performance of the codec when the image is encoded as separate\n"); @@ -806,6 +814,7 @@ int main(int argc, char *argv[]) else usage(argv[0]); } if(!strcmp(argv[i], "-?")) usage(argv[0]); + if(!strcasecmp(argv[i], "-alloc")) flags&=(~TJFLAG_NOREALLOC); } } -- 2.40.0