1 /*
2 * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <time.h>
15
16 #include "libyuv/basic_types.h"
17 #include "libyuv/compare.h"
18 #include "libyuv/version.h"
19
main(int argc,char ** argv)20 int main(int argc, char** argv) {
21 if (argc < 1) {
22 printf("libyuv compare v%d\n", LIBYUV_VERSION);
23 printf("compare file1.yuv file2.yuv\n");
24 return -1;
25 }
26 char* name1 = argv[1];
27 char* name2 = (argc > 2) ? argv[2] : NULL;
28 FILE* fin1 = fopen(name1, "rb");
29 FILE* fin2 = name2 ? fopen(name2, "rb") : NULL;
30
31 const int kBlockSize = 32768;
32 uint8 buf1[kBlockSize];
33 uint8 buf2[kBlockSize];
34 uint32 hash1 = 5381;
35 uint32 hash2 = 5381;
36 uint64 sum_square_err = 0;
37 uint64 size_min = 0;
38 int amt1 = 0;
39 int amt2 = 0;
40 do {
41 amt1 = static_cast<int>(fread(buf1, 1, kBlockSize, fin1));
42 if (amt1 > 0) hash1 = libyuv::HashDjb2(buf1, amt1, hash1);
43 if (fin2) {
44 amt2 = static_cast<int>(fread(buf2, 1, kBlockSize, fin2));
45 if (amt2 > 0) hash2 = libyuv::HashDjb2(buf2, amt2, hash2);
46 int amt_min = (amt1 < amt2) ? amt1 : amt2;
47 size_min += amt_min;
48 sum_square_err += libyuv::ComputeSumSquareError(buf1, buf2, amt_min);
49 }
50 } while (amt1 > 0 || amt2 > 0);
51
52 printf("hash1 %x", hash1);
53 if (fin2) {
54 printf(", hash2 %x", hash2);
55 double mse = static_cast<double>(sum_square_err) /
56 static_cast<double>(size_min);
57 printf(", mse %.2f", mse);
58 double psnr = libyuv::SumSquareErrorToPsnr(sum_square_err, size_min);
59 printf(", psnr %.2f\n", psnr);
60 fclose(fin2);
61 }
62 fclose(fin1);
63 }
64