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)
43 hash1 = libyuv::HashDjb2(buf1, amt1, hash1);
44 if (fin2) {
45 amt2 = static_cast<int>(fread(buf2, 1, kBlockSize, fin2));
46 if (amt2 > 0)
47 hash2 = libyuv::HashDjb2(buf2, amt2, hash2);
48 int amt_min = (amt1 < amt2) ? amt1 : amt2;
49 size_min += amt_min;
50 sum_square_err += libyuv::ComputeSumSquareError(buf1, buf2, amt_min);
51 }
52 } while (amt1 > 0 || amt2 > 0);
53
54 printf("hash1 %x", hash1);
55 if (fin2) {
56 printf(", hash2 %x", hash2);
57 double mse =
58 static_cast<double>(sum_square_err) / static_cast<double>(size_min);
59 printf(", mse %.2f", mse);
60 double psnr = libyuv::SumSquareErrorToPsnr(sum_square_err, size_min);
61 printf(", psnr %.2f\n", psnr);
62 fclose(fin2);
63 }
64 fclose(fin1);
65 }
66