--- trunk/xvidcore/examples/xvid_stat.c 2002/09/14 23:54:17 483 +++ trunk/xvidcore/examples/xvid_stat.c 2002/09/15 20:22:01 484 @@ -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.7 2002-09-15 20:22:01 edgomez Exp $ * ****************************************************************************/ @@ -150,6 +150,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 @@ -271,17 +272,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 +315,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 +422,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, in_buffer, XDIM, out_buffer, XDIM); printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]); @@ -657,6 +651,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 +661,7 @@ if ( (XDIM==0) || (YDIM==0) ) { XDIM=xsize; - YDIM=ysize; + YDIM=ysize*2/3; } return 0; @@ -677,29 +672,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