/* qcifpsnr.c this program will take two qcif files as input and calculate the PSNR based only on the Y component (illuminance) author: Leiming Qian version: 1.0 alpha date: Jul 30th, 1999 */ #define ROW 144 #define COL 176 #define FSIZE 38016 #define SQUARE(x) ( (x) * (x) ) #include #include #include #include int main(int argc, char* argv[]) { FILE *file1, *file2; /* input two files pointers */ double mse, psnr; /* mse and psnr */ struct stat file1_status; /* file1 status */ struct stat file2_status; /* file2 status */ unsigned char buf1[FSIZE], buf2[FSIZE]; int num_frms; int i, j, k; /* parse the command line */ if (argc!=3) { fprintf(stderr, "Usage: qcifpsnr file1 file2\n"); exit(1); } else { if ( (stat(argv[1], &file1_status)) || (stat(argv[2], &file2_status)) ) { fprintf(stderr, "Can't open one of the input files!\n"); exit(2); } } /* get the size of these two files and open these two files */ if (file1_status.st_size != file2_status.st_size) { fprintf(stderr, "Files are of different length!\n"); exit(3); } else { if ( !(file1=fopen(argv[1], "rb")) || !(file2=fopen(argv[2], "rb")) ) { fprintf(stderr, "Can't open files for input!\n"); exit(4); } } /* calculate the number of frames */ num_frms = file1_status.st_size/FSIZE; /* calculate mse and psnr */ mse = psnr = 0; for (i=0;i