media/libyuv/util/compare.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libyuv/util/compare.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +/*
     1.5 + *  Copyright 2012 The LibYuv Project Authors. All rights reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS. All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +#include <stdio.h>
    1.15 +#include <stdlib.h>
    1.16 +#include <string.h>
    1.17 +#include <time.h>
    1.18 +
    1.19 +#include "libyuv/basic_types.h"
    1.20 +#include "libyuv/compare.h"
    1.21 +#include "libyuv/version.h"
    1.22 +
    1.23 +int main(int argc, char** argv) {
    1.24 +  if (argc < 1) {
    1.25 +    printf("libyuv compare v%d\n", LIBYUV_VERSION);
    1.26 +    printf("compare file1.yuv file2.yuv\n");
    1.27 +    return -1;
    1.28 +  }
    1.29 +  char* name1 = argv[1];
    1.30 +  char* name2 = (argc > 2) ? argv[2] : NULL;
    1.31 +  FILE* fin1 = fopen(name1, "rb");
    1.32 +  FILE* fin2 = name2 ? fopen(name2, "rb") : NULL;
    1.33 +
    1.34 +  const int kBlockSize = 32768;
    1.35 +  uint8 buf1[kBlockSize];
    1.36 +  uint8 buf2[kBlockSize];
    1.37 +  uint32 hash1 = 5381;
    1.38 +  uint32 hash2 = 5381;
    1.39 +  uint64 sum_square_err = 0;
    1.40 +  uint64 size_min = 0;
    1.41 +  int amt1 = 0;
    1.42 +  int amt2 = 0;
    1.43 +  do {
    1.44 +    amt1 = static_cast<int>(fread(buf1, 1, kBlockSize, fin1));
    1.45 +    if (amt1 > 0) hash1 = libyuv::HashDjb2(buf1, amt1, hash1);
    1.46 +    if (fin2) {
    1.47 +      amt2 = static_cast<int>(fread(buf2, 1, kBlockSize, fin2));
    1.48 +      if (amt2 > 0) hash2 = libyuv::HashDjb2(buf2, amt2, hash2);
    1.49 +      int amt_min = (amt1 < amt2) ? amt1 : amt2;
    1.50 +      size_min += amt_min;
    1.51 +      sum_square_err += libyuv::ComputeSumSquareError(buf1, buf2, amt_min);
    1.52 +    }
    1.53 +  } while (amt1 > 0 || amt2 > 0);
    1.54 +
    1.55 +  printf("hash1 %x", hash1);
    1.56 +  if (fin2) {
    1.57 +    printf(", hash2 %x", hash2);
    1.58 +    double mse = static_cast<double>(sum_square_err) /
    1.59 +                 static_cast<double>(size_min);
    1.60 +    printf(", mse %.2f", mse);
    1.61 +    double psnr = libyuv::SumSquareErrorToPsnr(sum_square_err, size_min);
    1.62 +    printf(", psnr %.2f\n", psnr);
    1.63 +    fclose(fin2);
    1.64 +  }
    1.65 +  fclose(fin1);
    1.66 +}

mercurial