2
0

compare.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <time.h>
  14. #include "libyuv/basic_types.h"
  15. #include "libyuv/compare.h"
  16. #include "libyuv/version.h"
  17. int main(int argc, char** argv) {
  18. if (argc < 1) {
  19. printf("libyuv compare v%d\n", LIBYUV_VERSION);
  20. printf("compare file1.yuv file2.yuv\n");
  21. return -1;
  22. }
  23. char* name1 = argv[1];
  24. char* name2 = (argc > 2) ? argv[2] : NULL;
  25. FILE* fin1 = fopen(name1, "rb");
  26. FILE* fin2 = name2 ? fopen(name2, "rb") : NULL;
  27. const int kBlockSize = 32768;
  28. uint8_t buf1[kBlockSize];
  29. uint8_t buf2[kBlockSize];
  30. uint32_t hash1 = 5381;
  31. uint32_t hash2 = 5381;
  32. uint64_t sum_square_err = 0;
  33. uint64_t size_min = 0;
  34. int amt1 = 0;
  35. int amt2 = 0;
  36. do {
  37. amt1 = static_cast<int>(fread(buf1, 1, kBlockSize, fin1));
  38. if (amt1 > 0) {
  39. hash1 = libyuv::HashDjb2(buf1, amt1, hash1);
  40. }
  41. if (fin2) {
  42. amt2 = static_cast<int>(fread(buf2, 1, kBlockSize, fin2));
  43. if (amt2 > 0) {
  44. hash2 = libyuv::HashDjb2(buf2, amt2, hash2);
  45. }
  46. int amt_min = (amt1 < amt2) ? amt1 : amt2;
  47. size_min += amt_min;
  48. sum_square_err += libyuv::ComputeSumSquareError(buf1, buf2, amt_min);
  49. }
  50. } while (amt1 > 0 || amt2 > 0);
  51. printf("hash1 %x", hash1);
  52. if (fin2) {
  53. printf(", hash2 %x", hash2);
  54. double mse =
  55. static_cast<double>(sum_square_err) / static_cast<double>(size_min);
  56. printf(", mse %.2f", mse);
  57. double psnr = libyuv::SumSquareErrorToPsnr(sum_square_err, size_min);
  58. printf(", psnr %.2f\n", psnr);
  59. fclose(fin2);
  60. }
  61. fclose(fin1);
  62. }