--- trunk/xvidcore/examples/xvid_stat.c 2002/09/14 23:54:17 483 +++ trunk/xvidcore/examples/xvid_stat.c 2002/09/27 20:58:02 550 @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid_stat.c,v 1.6 2002-09-14 23:54:17 edgomez Exp $ + * $Id: xvid_stat.c,v 1.13 2002-09-27 20:58:02 edgomez Exp $ * ****************************************************************************/ @@ -44,7 +44,7 @@ * -q integer : quality ([0..5]) * -d boolean : save decoder output (0 False*, !=0 True) * -m boolean : save mpeg4 raw stream (0 False*, !=0 True) - * -h, -help : prints this help message + * -help : prints this help message * -quant integer : fixed quantizer (disables -b setting) * (* means default) * @@ -65,9 +65,13 @@ #include #include #include +#ifndef _MSC_VER +#include +#else #include +#endif -#include "../src/xvid.h" +#include "xvid.h" /**************************************************************************** * Prototypes @@ -150,6 +154,7 @@ static int ARG_SAVEMPEGSTREAM = 0; static int XDIM = 0; static int YDIM = 0; +#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) #define SMALL_EPS 1e-10 @@ -256,7 +261,7 @@ i++; ARG_SAVEMPEGSTREAM = atoi(argv[i]); } - else if (strcmp("-h", argv[i]) == 0 || strcmp("-help", argv[i])) { + else if (strcmp("-help", argv[i])) { usage(); return(0); } @@ -271,17 +276,13 @@ * Arguments checking ****************************************************************************/ - if ( ARG_INPUTTYPE == 0 && - ((XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048)) ) { + if (XDIM <= 0 || XDIM >= 2048 || YDIM <=0 || YDIM >= 2048 ) { fprintf(stderr, - "Wrong frame sizes width=%d height=%d, trying PGM header infos\n", + "Trying to retreive width and height from PGM header\n", XDIM, YDIM); ARG_INPUTTYPE = 1; /* pgm */ } - else { - YDIM = YDIM*3/2; /* YUV */ - } if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) { fprintf(stderr,"Wrong Quality\n"); @@ -318,25 +319,22 @@ if (ARG_INPUTTYPE) { if (read_pgmheader(in_file)) { fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n"); - return -11; + return -1; } } /* now we know the sizes, so allocate memory */ - in_buffer = (unsigned char *) malloc(XDIM*YDIM); + in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)); if (!in_buffer) goto free_all_memory; /* this should really be enough memory ! */ - divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2); + divx_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*2); if (!divx_buffer) goto free_all_memory; - /* PGM is YUV 4:2:0 format, so real image height is *2/3 of PGM picture */ - YDIM = YDIM*2/3; - - out_buffer = (unsigned char *) malloc(XDIM*YDIM*4); + out_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*4); if (!out_buffer) goto free_all_memory; @@ -428,7 +426,7 @@ * Analyse the decoded frame and compare to original ****************************************************************************/ - framepsnr[filenr] = PSNR(XDIM,YDIM, in_buffer, XDIM, out_buffer, XDIM ); + framepsnr[filenr] = PSNR(XDIM,YDIM*3/2, in_buffer, XDIM, out_buffer, XDIM); printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]); @@ -503,12 +501,12 @@ /* Print all statistics */ printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br")); - printf("%04d ",MAX(ARG_QUANTI,ARG_BITRATE)); + printf("%04d ",(ARG_QUANTI)?ARG_QUANTI:ARG_BITRATE); printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE); printf("size %6d ",totalsize); printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000)); printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM); - printf("enc: %6.1f fps, dec: %6.1f fps \n",1/totalenctime, 1/totaldectime); + printf("enc: %6.1f fps, dec: %6.1f fps \n",1000/totalenctime, 1000/totaldectime); printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr)); printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr)); printf("\n"); @@ -557,12 +555,15 @@ /* Return time elapsed time in miliseconds since the program started */ static double msecond() { +#ifndef _MSC_VER + struct timeval tv; + gettimeofday(&tv, 0); + return tv.tv_sec*1.0e3 + tv.tv_usec * 1.0e-3; +#else clock_t clk; - clk = clock(); - return clk * 1000 / CLOCKS_PER_SEC; - +#endif } @@ -634,7 +635,7 @@ fprintf(stderr, " -q integer : quality ([0..5])\n"); fprintf(stderr, " -d boolean : save decoder output (0 False*, !=0 True)\n"); fprintf(stderr, " -m boolean : save mpeg4 raw stream (0 False*, !=0 True)\n"); - fprintf(stderr, " -h, -help : prints this help message\n"); + fprintf(stderr, " -help : prints this help message\n"); fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); fprintf(stderr, " (* means default)\n"); @@ -657,6 +658,7 @@ if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' )) return 1; + fscanf(handle,"%d %d %d",&xsize,&ysize,&depth); if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) ) { @@ -666,7 +668,7 @@ if ( (XDIM==0) || (YDIM==0) ) { XDIM=xsize; - YDIM=ysize; + YDIM=ysize*2/3; } return 0; @@ -677,29 +679,36 @@ int i; char dummy; - unsigned char* buff1_ptr2 = image + XDIM*YDIM; - unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2; + unsigned char *y = image; + unsigned char *u = image + XDIM*YDIM; + unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2; - fread(image,XDIM*YDIM,1, handle); // read Y component of picture + /* read Y component of picture */ + fread(y, 1, XDIM*YDIM, handle); for (i=0;i