michael@0: /* michael@0: * Copyright 2012 The LibYuv Project Authors. All rights reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "libyuv/basic_types.h" michael@0: #include "libyuv/compare.h" michael@0: #include "libyuv/version.h" michael@0: michael@0: int main(int argc, char** argv) { michael@0: if (argc < 1) { michael@0: printf("libyuv compare v%d\n", LIBYUV_VERSION); michael@0: printf("compare file1.yuv file2.yuv\n"); michael@0: return -1; michael@0: } michael@0: char* name1 = argv[1]; michael@0: char* name2 = (argc > 2) ? argv[2] : NULL; michael@0: FILE* fin1 = fopen(name1, "rb"); michael@0: FILE* fin2 = name2 ? fopen(name2, "rb") : NULL; michael@0: michael@0: const int kBlockSize = 32768; michael@0: uint8 buf1[kBlockSize]; michael@0: uint8 buf2[kBlockSize]; michael@0: uint32 hash1 = 5381; michael@0: uint32 hash2 = 5381; michael@0: uint64 sum_square_err = 0; michael@0: uint64 size_min = 0; michael@0: int amt1 = 0; michael@0: int amt2 = 0; michael@0: do { michael@0: amt1 = static_cast(fread(buf1, 1, kBlockSize, fin1)); michael@0: if (amt1 > 0) hash1 = libyuv::HashDjb2(buf1, amt1, hash1); michael@0: if (fin2) { michael@0: amt2 = static_cast(fread(buf2, 1, kBlockSize, fin2)); michael@0: if (amt2 > 0) hash2 = libyuv::HashDjb2(buf2, amt2, hash2); michael@0: int amt_min = (amt1 < amt2) ? amt1 : amt2; michael@0: size_min += amt_min; michael@0: sum_square_err += libyuv::ComputeSumSquareError(buf1, buf2, amt_min); michael@0: } michael@0: } while (amt1 > 0 || amt2 > 0); michael@0: michael@0: printf("hash1 %x", hash1); michael@0: if (fin2) { michael@0: printf(", hash2 %x", hash2); michael@0: double mse = static_cast(sum_square_err) / michael@0: static_cast(size_min); michael@0: printf(", mse %.2f", mse); michael@0: double psnr = libyuv::SumSquareErrorToPsnr(sum_square_err, size_min); michael@0: printf(", psnr %.2f\n", psnr); michael@0: fclose(fin2); michael@0: } michael@0: fclose(fin1); michael@0: }