1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #include <math.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 #include <unistd.h>
13 #include "raw.h"
14 
15 /* Compare the difference between two raw files */
16 
max(double a,double b)17 static inline double max(double a, double b)
18 {
19 	return (a > b) ? a : b;
20 }
21 
main(int argc,char ** argv)22 int main(int argc, char **argv)
23 {
24 	size_t frame1, frame2;
25 	float *data1, *data2;
26 	size_t i, n, changed;
27 	double diff = 0;
28 	double maxdiff = 0;
29 
30 	if (argc != 3) {
31 		fprintf(stderr, "usage: cmpraw 1.raw 2.raw\n");
32 		exit(1);
33 	}
34 
35 	data1 = read_raw(argv[1], &frame1);
36 	data2 = read_raw(argv[2], &frame2);
37 
38 	if (frame1 != frame2) {
39 		fprintf(stderr, "mismatch size (%zu vs %zu)\n", frame1, frame2);
40 		exit(1);
41 	}
42 
43 	n = frame1 * 2;
44 	changed = 0;
45 	for (i = 0; i < n; i++) {
46 		if (data1[i] != data2[i]) {
47 			changed++;
48 			diff += fabs(data1[i] - data2[i]);
49 			maxdiff = max(fabs(data1[i] - data2[i]), maxdiff);
50 		}
51 	}
52 	printf("avg diff = %g, max diff = %g, changed = %.3f%%\n",
53 	       diff / n, maxdiff * 32768, changed*100.0f/n);
54 
55 	free(data1);
56 	free(data2);
57 	return 0;
58 }
59