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