check quality too, not only md5 (but dont take the scores too serious, the different...
[libav.git] / tests / tiny_psnr.c
CommitLineData
67cbe681
MN
1/*
2 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20#include <stdio.h>
21#include <inttypes.h>
22
23#define F 100
24#define SIZE 2048
25
26static uint64_t int_sqrt(uint64_t a)
27{
28 uint64_t ret=0;
29 int s;
30 uint64_t ret_sq=0;
31
32 for(s=31; s>=0; s--){
33 uint64_t b= ret_sq + (1ULL<<(s*2)) + (ret<<s)*2;
34 if(b<=a){
35 ret_sq=b;
36 ret+= 1ULL<<s;
37 }
38 }
39 return ret;
40}
41
42int main(int argc,char* argv[]){
43 int i, j;
44 uint64_t sse=0;
45 uint64_t dev;
46 FILE *f[2];
47 uint8_t buf[2][SIZE];
48
49 if(argc!=3){
50 printf("tiny_psnr <file1> <file2>\n");
51 return -1;
52 }
53
54 f[0]= fopen(argv[1], "r");
55 f[1]= fopen(argv[2], "r");
56
57 for(i=0;;){
58 if( fread(buf[0], SIZE, 1, f[0]) != 1) break;
59 if( fread(buf[1], SIZE, 1, f[1]) != 1) break;
60
61 for(j=0; j<SIZE; i++,j++){
62 const int a= buf[0][j];
63 const int b= buf[1][j];
64 sse += (a-b) * (a-b);
65 }
66 }
67
68 dev= int_sqrt((sse*F*F)/i);
69
70 //FIXME someone should write a integer fixpoint log() function for bitexact PSNR scores ...
71 printf("stddev:%3d.%02d bytes:%d\n", (int)(dev/F), (int)(dev%F), i);
72
73 return 0;
74}