media/libyuv/util/compare.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial