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