react-native-vision-camera-spoof-detector 1.1.23 → 1.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/android/CMakeLists.txt +12 -0
  2. package/android/build.gradle +10 -9
  3. package/android/src/main/cpp/cpp-adapter.cpp +6 -3
  4. package/ios/HybridSpoofDetectorOutput.swift +112 -72
  5. package/package.json +1 -1
  6. package/android/src/main/cpp/CMakeLists.txt +0 -33
  7. package/android/src/main/cpp/FaceAntiSpoofJSI.cpp +0 -142
  8. package/android/src/main/cpp/FastYuvJni.cpp +0 -111
  9. package/android/src/main/cpp/fast_yuv.cpp +0 -342
  10. package/android/src/main/cpp/fast_yuv.h +0 -23
  11. package/android/src/main/cpp/libyuv/.clang-format +0 -6
  12. package/android/src/main/cpp/libyuv/.gn +0 -40
  13. package/android/src/main/cpp/libyuv/.vpython3 +0 -410
  14. package/android/src/main/cpp/libyuv/AUTHORS +0 -7
  15. package/android/src/main/cpp/libyuv/Android.bp +0 -202
  16. package/android/src/main/cpp/libyuv/Android.mk +0 -106
  17. package/android/src/main/cpp/libyuv/BUILD.gn +0 -490
  18. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +0 -70
  19. package/android/src/main/cpp/libyuv/CMakeLists.txt +0 -259
  20. package/android/src/main/cpp/libyuv/DEPS +0 -935
  21. package/android/src/main/cpp/libyuv/DIR_METADATA +0 -3
  22. package/android/src/main/cpp/libyuv/LICENSE +0 -29
  23. package/android/src/main/cpp/libyuv/OWNERS +0 -11
  24. package/android/src/main/cpp/libyuv/PATENTS +0 -24
  25. package/android/src/main/cpp/libyuv/PRESUBMIT.py +0 -65
  26. package/android/src/main/cpp/libyuv/README.chromium +0 -11
  27. package/android/src/main/cpp/libyuv/README.md +0 -19
  28. package/android/src/main/cpp/libyuv/build_overrides/build.gni +0 -60
  29. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +0 -19
  30. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +0 -17
  31. package/android/src/main/cpp/libyuv/codereview.settings +0 -5
  32. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +0 -409
  33. package/android/src/main/cpp/libyuv/docs/environment_variables.md +0 -64
  34. package/android/src/main/cpp/libyuv/docs/feature_detection.md +0 -108
  35. package/android/src/main/cpp/libyuv/docs/filtering.md +0 -196
  36. package/android/src/main/cpp/libyuv/docs/formats.md +0 -208
  37. package/android/src/main/cpp/libyuv/docs/getting_started.md +0 -296
  38. package/android/src/main/cpp/libyuv/docs/rotation.md +0 -107
  39. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +0 -29
  40. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +0 -68
  41. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +0 -111
  42. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +0 -112
  43. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +0 -1117
  44. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +0 -2335
  45. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +0 -203
  46. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +0 -394
  47. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +0 -147
  48. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +0 -99
  49. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +0 -1949
  50. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +0 -195
  51. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +0 -1131
  52. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +0 -296
  53. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +0 -37
  54. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +0 -265
  55. package/android/src/main/cpp/libyuv/include/libyuv/row.h +0 -6738
  56. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +0 -2154
  57. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +0 -336
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +0 -76
  59. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +0 -42
  60. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +0 -1726
  61. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +0 -51
  62. package/android/src/main/cpp/libyuv/include/libyuv/version.h +0 -16
  63. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +0 -222
  64. package/android/src/main/cpp/libyuv/include/libyuv.h +0 -33
  65. package/android/src/main/cpp/libyuv/infra/config/OWNERS +0 -3
  66. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +0 -17
  67. package/android/src/main/cpp/libyuv/infra/config/README.md +0 -2
  68. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +0 -6
  69. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +0 -144
  70. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +0 -1185
  71. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +0 -9
  72. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +0 -246
  73. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +0 -385
  74. package/android/src/main/cpp/libyuv/infra/config/main.star +0 -402
  75. package/android/src/main/cpp/libyuv/infra/config/project.cfg +0 -16
  76. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +0 -111
  77. package/android/src/main/cpp/libyuv/libyuv.gni +0 -34
  78. package/android/src/main/cpp/libyuv/libyuv.gyp +0 -149
  79. package/android/src/main/cpp/libyuv/libyuv.gypi +0 -87
  80. package/android/src/main/cpp/libyuv/linux.mk +0 -96
  81. package/android/src/main/cpp/libyuv/public.mk +0 -13
  82. package/android/src/main/cpp/libyuv/pylintrc +0 -49
  83. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +0 -74
  84. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +0 -56
  85. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +0 -15
  86. package/android/src/main/cpp/libyuv/source/compare.cc +0 -435
  87. package/android/src/main/cpp/libyuv/source/compare_common.cc +0 -74
  88. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +0 -362
  89. package/android/src/main/cpp/libyuv/source/compare_neon.cc +0 -96
  90. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +0 -223
  91. package/android/src/main/cpp/libyuv/source/compare_win.cc +0 -241
  92. package/android/src/main/cpp/libyuv/source/convert.cc +0 -4746
  93. package/android/src/main/cpp/libyuv/source/convert_argb.cc +0 -9179
  94. package/android/src/main/cpp/libyuv/source/convert_from.cc +0 -866
  95. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +0 -3671
  96. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +0 -602
  97. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +0 -391
  98. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +0 -288
  99. package/android/src/main/cpp/libyuv/source/cpu_id.cc +0 -496
  100. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +0 -580
  101. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +0 -71
  102. package/android/src/main/cpp/libyuv/source/planar_functions.cc +0 -5663
  103. package/android/src/main/cpp/libyuv/source/rotate.cc +0 -1241
  104. package/android/src/main/cpp/libyuv/source/rotate_any.cc +0 -76
  105. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +0 -259
  106. package/android/src/main/cpp/libyuv/source/rotate_common.cc +0 -208
  107. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +0 -505
  108. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +0 -233
  109. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +0 -219
  110. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +0 -273
  111. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +0 -174
  112. package/android/src/main/cpp/libyuv/source/rotate_win.cc +0 -253
  113. package/android/src/main/cpp/libyuv/source/row_any.cc +0 -2519
  114. package/android/src/main/cpp/libyuv/source/row_common.cc +0 -4461
  115. package/android/src/main/cpp/libyuv/source/row_gcc.cc +0 -9570
  116. package/android/src/main/cpp/libyuv/source/row_lasx.cc +0 -2343
  117. package/android/src/main/cpp/libyuv/source/row_lsx.cc +0 -3030
  118. package/android/src/main/cpp/libyuv/source/row_neon.cc +0 -4026
  119. package/android/src/main/cpp/libyuv/source/row_neon64.cc +0 -5617
  120. package/android/src/main/cpp/libyuv/source/row_rvv.cc +0 -2599
  121. package/android/src/main/cpp/libyuv/source/row_sme.cc +0 -1183
  122. package/android/src/main/cpp/libyuv/source/row_sve.cc +0 -1088
  123. package/android/src/main/cpp/libyuv/source/row_win.cc +0 -6453
  124. package/android/src/main/cpp/libyuv/source/scale.cc +0 -2710
  125. package/android/src/main/cpp/libyuv/source/scale_any.cc +0 -991
  126. package/android/src/main/cpp/libyuv/source/scale_argb.cc +0 -1158
  127. package/android/src/main/cpp/libyuv/source/scale_common.cc +0 -1977
  128. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +0 -2947
  129. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +0 -739
  130. package/android/src/main/cpp/libyuv/source/scale_neon.cc +0 -1449
  131. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +0 -1552
  132. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +0 -82
  133. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +0 -1971
  134. package/android/src/main/cpp/libyuv/source/scale_sme.cc +0 -555
  135. package/android/src/main/cpp/libyuv/source/scale_uv.cc +0 -1159
  136. package/android/src/main/cpp/libyuv/source/scale_win.cc +0 -1392
  137. package/android/src/main/cpp/libyuv/source/test.sh +0 -35
  138. package/android/src/main/cpp/libyuv/source/video_common.cc +0 -62
  139. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +0 -4
  140. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +0 -931
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +0 -164
  142. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +0 -21
  143. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +0 -13
  144. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +0 -13
  145. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +0 -38
  146. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +0 -3
  147. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +0 -9
  148. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +0 -3
  149. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +0 -15
  150. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +0 -25
  151. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +0 -43
  152. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +0 -848
  153. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +0 -739
  154. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +0 -2867
  155. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +0 -2133
  156. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +0 -427
  157. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +0 -63
  158. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +0 -160
  159. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +0 -4731
  160. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +0 -334
  161. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +0 -962
  162. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +0 -590
  163. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +0 -465
  164. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +0 -280
  165. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +0 -1135
  166. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +0 -249
  167. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +0 -12
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +0 -7
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +0 -5
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +0 -10
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +0 -7
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +0 -4
  173. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +0 -4
  174. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +0 -4
  175. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +0 -23
  176. package/android/src/main/cpp/libyuv/unit_test/testdata/test0.jpg +0 -0
  177. package/android/src/main/cpp/libyuv/unit_test/testdata/test1.jpg +0 -0
  178. package/android/src/main/cpp/libyuv/unit_test/testdata/test2.jpg +0 -0
  179. package/android/src/main/cpp/libyuv/unit_test/testdata/test3.jpg +0 -0
  180. package/android/src/main/cpp/libyuv/unit_test/testdata/test4.jpg +0 -0
  181. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +0 -581
  182. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +0 -232
  183. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +0 -112
  184. package/android/src/main/cpp/libyuv/util/Makefile +0 -9
  185. package/android/src/main/cpp/libyuv/util/color.cc +0 -120
  186. package/android/src/main/cpp/libyuv/util/compare.cc +0 -67
  187. package/android/src/main/cpp/libyuv/util/cpuid.c +0 -211
  188. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +0 -28
  189. package/android/src/main/cpp/libyuv/util/psnr.cc +0 -291
  190. package/android/src/main/cpp/libyuv/util/psnr.h +0 -47
  191. package/android/src/main/cpp/libyuv/util/psnr_main.cc +0 -620
  192. package/android/src/main/cpp/libyuv/util/ssim.cc +0 -364
  193. package/android/src/main/cpp/libyuv/util/ssim.h +0 -38
  194. package/android/src/main/cpp/libyuv/util/yuvconstants.c +0 -114
  195. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +0 -367
  196. package/android/src/main/cpp/libyuv/winarm.mk +0 -47
  197. package/android/src/main/java/com/faceantispoof/ByteBufferPool.kt +0 -68
  198. package/android/src/main/java/com/faceantispoof/FastYuv.kt +0 -51
  199. package/android/src/main/java/com/faceantispoof/YuvToFloatArrayConverter.kt +0 -584
  200. package/android/src/main/java/com/faceantispoof/YuvToRgbConverter.kt +0 -73
@@ -1,620 +0,0 @@
1
- /*
2
- * Copyright 2013 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
-
11
- // Get PSNR or SSIM for video sequence. Assuming RAW 4:2:0 Y:Cb:Cr format
12
- // To build: g++ -O3 -o psnr psnr.cc ssim.cc psnr_main.cc
13
- // or VisualC: cl /Ox psnr.cc ssim.cc psnr_main.cc
14
- //
15
- // To enable OpenMP and SSE2
16
- // gcc: g++ -msse2 -O3 -fopenmp -o psnr psnr.cc ssim.cc psnr_main.cc
17
- // vc: cl /arch:SSE2 /Ox /openmp psnr.cc ssim.cc psnr_main.cc
18
- //
19
- // Usage: psnr org_seq rec_seq -s width height [-skip skip_org skip_rec]
20
-
21
- #ifndef _CRT_SECURE_NO_WARNINGS
22
- #define _CRT_SECURE_NO_WARNINGS
23
- #endif
24
-
25
- #include <stddef.h>
26
- #include <stdio.h>
27
- #include <stdlib.h>
28
- #include <string.h>
29
- #ifdef _OPENMP
30
- #include <omp.h>
31
- #endif
32
-
33
- #include "./psnr.h"
34
- #include "./ssim.h"
35
- #ifdef HAVE_JPEG
36
- #include "libyuv/compare.h"
37
- #include "libyuv/convert.h"
38
- #endif
39
-
40
- struct metric {
41
- double y, u, v, all;
42
- double min_y, min_u, min_v, min_all;
43
- double global_y, global_u, global_v, global_all;
44
- int min_frame;
45
- };
46
-
47
- // options
48
- bool verbose = false;
49
- bool quiet = false;
50
- bool show_name = false;
51
- bool do_swap_uv = false;
52
- bool do_psnr = false;
53
- bool do_ssim = false;
54
- bool do_mse = false;
55
- bool do_lssim = false;
56
- int image_width = 0, image_height = 0;
57
- int fileindex_org = 0; // argv argument contains the source file name.
58
- int fileindex_rec = 0; // argv argument contains the destination file name.
59
- int num_rec = 0;
60
- int num_skip_org = 0;
61
- int num_skip_rec = 0;
62
- int num_frames = 0;
63
- #ifdef _OPENMP
64
- int num_threads = 0;
65
- #endif
66
-
67
- // Parse PYUV format. ie name.1920x800_24Hz_P420.yuv
68
- static bool ExtractResolutionFromFilename(const char* name,
69
- int* width_ptr,
70
- int* height_ptr) {
71
- // Isolate the .width_height. section of the filename by searching for a
72
- // dot or underscore followed by a digit.
73
- for (int i = 0; name[i]; ++i) {
74
- if ((name[i] == '.' || name[i] == '_') && name[i + 1] >= '0' &&
75
- name[i + 1] <= '9') {
76
- int n = sscanf(name + i + 1, "%dx%d", width_ptr, height_ptr); // NOLINT
77
- if (2 == n) {
78
- return true;
79
- }
80
- }
81
- }
82
-
83
- #ifdef HAVE_JPEG
84
- // Try parsing file as a jpeg.
85
- FILE* const file_org = fopen(name, "rb");
86
- if (file_org == NULL) {
87
- fprintf(stderr, "Cannot open %s\n", name);
88
- return false;
89
- }
90
- fseek(file_org, 0, SEEK_END);
91
- size_t total_size = ftell(file_org);
92
- fseek(file_org, 0, SEEK_SET);
93
- uint8_t* const ch_org = new uint8_t[total_size];
94
- memset(ch_org, 0, total_size);
95
- size_t bytes_org = fread(ch_org, sizeof(uint8_t), total_size, file_org);
96
- fclose(file_org);
97
- if (bytes_org == total_size) {
98
- if (0 == libyuv::MJPGSize(ch_org, total_size, width_ptr, height_ptr)) {
99
- delete[] ch_org;
100
- return true;
101
- }
102
- }
103
- delete[] ch_org;
104
- #endif // HAVE_JPEG
105
- return false;
106
- }
107
-
108
- // MSE = Mean Square Error
109
- static double GetMSE(double sse, double size) {
110
- return sse / size;
111
- }
112
-
113
- static void PrintHelp(const char* program) {
114
- printf("%s [-options] org_seq rec_seq [rec_seq2.. etc]\n", program);
115
- #ifdef HAVE_JPEG
116
- printf("jpeg or raw YUV 420 supported.\n");
117
- #endif
118
- printf("options:\n");
119
- printf(
120
- " -s <width> <height> .... specify YUV size, mandatory if none of the "
121
- "sequences have the\n");
122
- printf(
123
- " resolution embedded in their filename (ie. "
124
- "name.1920x800_24Hz_P420.yuv)\n");
125
- printf(" -psnr .................. compute PSNR (default)\n");
126
- printf(" -ssim .................. compute SSIM\n");
127
- printf(" -mse ................... compute MSE\n");
128
- printf(" -swap .................. Swap U and V plane\n");
129
- printf(" -skip <org> <rec> ...... Number of frame to skip of org and rec\n");
130
- printf(" -frames <num> .......... Number of frames to compare\n");
131
- #ifdef _OPENMP
132
- printf(" -t <num> ............... Number of threads\n");
133
- #endif
134
- printf(" -n ..................... Show file name\n");
135
- printf(" -v ..................... verbose++\n");
136
- printf(" -q ..................... quiet\n");
137
- printf(" -h ..................... this help\n");
138
- exit(0);
139
- }
140
-
141
- static void ParseOptions(int argc, const char* argv[]) {
142
- if (argc <= 1) {
143
- PrintHelp(argv[0]);
144
- }
145
- for (int c = 1; c < argc; ++c) {
146
- if (!strcmp(argv[c], "-v")) {
147
- verbose = true;
148
- } else if (!strcmp(argv[c], "-q")) {
149
- quiet = true;
150
- } else if (!strcmp(argv[c], "-n")) {
151
- show_name = true;
152
- } else if (!strcmp(argv[c], "-psnr")) {
153
- do_psnr = true;
154
- } else if (!strcmp(argv[c], "-mse")) {
155
- do_mse = true;
156
- } else if (!strcmp(argv[c], "-ssim")) {
157
- do_ssim = true;
158
- } else if (!strcmp(argv[c], "-lssim")) {
159
- do_ssim = true;
160
- do_lssim = true;
161
- } else if (!strcmp(argv[c], "-swap")) {
162
- do_swap_uv = true;
163
- } else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
164
- PrintHelp(argv[0]);
165
- } else if (!strcmp(argv[c], "-s") && c + 2 < argc) {
166
- image_width = atoi(argv[++c]); // NOLINT
167
- image_height = atoi(argv[++c]); // NOLINT
168
- } else if (!strcmp(argv[c], "-skip") && c + 2 < argc) {
169
- num_skip_org = atoi(argv[++c]); // NOLINT
170
- num_skip_rec = atoi(argv[++c]); // NOLINT
171
- } else if (!strcmp(argv[c], "-frames") && c + 1 < argc) {
172
- num_frames = atoi(argv[++c]); // NOLINT
173
- #ifdef _OPENMP
174
- } else if (!strcmp(argv[c], "-t") && c + 1 < argc) {
175
- num_threads = atoi(argv[++c]); // NOLINT
176
- #endif
177
- } else if (argv[c][0] == '-') {
178
- fprintf(stderr, "Unknown option. %s\n", argv[c]);
179
- } else if (fileindex_org == 0) {
180
- fileindex_org = c;
181
- } else if (fileindex_rec == 0) {
182
- fileindex_rec = c;
183
- num_rec = 1;
184
- } else {
185
- ++num_rec;
186
- }
187
- }
188
- if (fileindex_org == 0 || fileindex_rec == 0) {
189
- fprintf(stderr, "Missing filenames\n");
190
- PrintHelp(argv[0]);
191
- }
192
- if (num_skip_org < 0 || num_skip_rec < 0) {
193
- fprintf(stderr, "Skipped frames incorrect\n");
194
- PrintHelp(argv[0]);
195
- }
196
- if (num_frames < 0) {
197
- fprintf(stderr, "Number of frames incorrect\n");
198
- PrintHelp(argv[0]);
199
- }
200
- if (image_width == 0 || image_height == 0) {
201
- int org_width, org_height;
202
- int rec_width, rec_height;
203
- bool org_res_avail = ExtractResolutionFromFilename(argv[fileindex_org],
204
- &org_width, &org_height);
205
- bool rec_res_avail = ExtractResolutionFromFilename(argv[fileindex_rec],
206
- &rec_width, &rec_height);
207
- if (org_res_avail) {
208
- if (rec_res_avail) {
209
- if ((org_width == rec_width) && (org_height == rec_height)) {
210
- image_width = org_width;
211
- image_height = org_height;
212
- } else {
213
- fprintf(stderr, "Sequences have different resolutions.\n");
214
- PrintHelp(argv[0]);
215
- }
216
- } else {
217
- image_width = org_width;
218
- image_height = org_height;
219
- }
220
- } else if (rec_res_avail) {
221
- image_width = rec_width;
222
- image_height = rec_height;
223
- } else {
224
- fprintf(stderr, "Missing dimensions.\n");
225
- PrintHelp(argv[0]);
226
- }
227
- }
228
- }
229
-
230
- static bool UpdateMetrics(uint8_t* ch_org,
231
- uint8_t* ch_rec,
232
- const int y_size,
233
- const int uv_size,
234
- const size_t total_size,
235
- int number_of_frames,
236
- metric* cur_distortion_psnr,
237
- metric* distorted_frame,
238
- bool compute_psnr) {
239
- const int uv_offset = (do_swap_uv ? uv_size : 0);
240
- const uint8_t* const u_org = ch_org + y_size + uv_offset;
241
- const uint8_t* const u_rec = ch_rec + y_size;
242
- const uint8_t* const v_org = ch_org + y_size + (uv_size - uv_offset);
243
- const uint8_t* const v_rec = ch_rec + y_size + uv_size;
244
- if (compute_psnr) {
245
- #ifdef HAVE_JPEG
246
- double y_err = static_cast<double>(
247
- libyuv::ComputeSumSquareError(ch_org, ch_rec, y_size));
248
- double u_err = static_cast<double>(
249
- libyuv::ComputeSumSquareError(u_org, u_rec, uv_size));
250
- double v_err = static_cast<double>(
251
- libyuv::ComputeSumSquareError(v_org, v_rec, uv_size));
252
- #else
253
- double y_err = ComputeSumSquareError(ch_org, ch_rec, y_size);
254
- double u_err = ComputeSumSquareError(u_org, u_rec, uv_size);
255
- double v_err = ComputeSumSquareError(v_org, v_rec, uv_size);
256
- #endif
257
- const double total_err = y_err + u_err + v_err;
258
- cur_distortion_psnr->global_y += y_err;
259
- cur_distortion_psnr->global_u += u_err;
260
- cur_distortion_psnr->global_v += v_err;
261
- cur_distortion_psnr->global_all += total_err;
262
- distorted_frame->y = ComputePSNR(y_err, static_cast<double>(y_size));
263
- distorted_frame->u = ComputePSNR(u_err, static_cast<double>(uv_size));
264
- distorted_frame->v = ComputePSNR(v_err, static_cast<double>(uv_size));
265
- distorted_frame->all =
266
- ComputePSNR(total_err, static_cast<double>(total_size));
267
- } else {
268
- distorted_frame->y = CalcSSIM(ch_org, ch_rec, image_width, image_height);
269
- distorted_frame->u =
270
- CalcSSIM(u_org, u_rec, (image_width + 1) / 2, (image_height + 1) / 2);
271
- distorted_frame->v =
272
- CalcSSIM(v_org, v_rec, (image_width + 1) / 2, (image_height + 1) / 2);
273
- distorted_frame->all =
274
- (distorted_frame->y + distorted_frame->u + distorted_frame->v) /
275
- total_size;
276
- distorted_frame->y /= y_size;
277
- distorted_frame->u /= uv_size;
278
- distorted_frame->v /= uv_size;
279
-
280
- if (do_lssim) {
281
- distorted_frame->all = CalcLSSIM(distorted_frame->all);
282
- distorted_frame->y = CalcLSSIM(distorted_frame->y);
283
- distorted_frame->u = CalcLSSIM(distorted_frame->u);
284
- distorted_frame->v = CalcLSSIM(distorted_frame->v);
285
- }
286
- }
287
-
288
- cur_distortion_psnr->y += distorted_frame->y;
289
- cur_distortion_psnr->u += distorted_frame->u;
290
- cur_distortion_psnr->v += distorted_frame->v;
291
- cur_distortion_psnr->all += distorted_frame->all;
292
-
293
- bool ismin = false;
294
- if (distorted_frame->y < cur_distortion_psnr->min_y) {
295
- cur_distortion_psnr->min_y = distorted_frame->y;
296
- }
297
- if (distorted_frame->u < cur_distortion_psnr->min_u) {
298
- cur_distortion_psnr->min_u = distorted_frame->u;
299
- }
300
- if (distorted_frame->v < cur_distortion_psnr->min_v) {
301
- cur_distortion_psnr->min_v = distorted_frame->v;
302
- }
303
- if (distorted_frame->all < cur_distortion_psnr->min_all) {
304
- cur_distortion_psnr->min_all = distorted_frame->all;
305
- cur_distortion_psnr->min_frame = number_of_frames;
306
- ismin = true;
307
- }
308
- return ismin;
309
- }
310
-
311
- int main(int argc, const char* argv[]) {
312
- ParseOptions(argc, argv);
313
- if (!do_psnr && !do_ssim) {
314
- do_psnr = true;
315
- }
316
-
317
- #ifdef _OPENMP
318
- if (num_threads) {
319
- omp_set_num_threads(num_threads);
320
- }
321
- if (verbose) {
322
- printf("OpenMP %d procs\n", omp_get_num_procs());
323
- }
324
- #endif
325
- // Open original file (first file argument)
326
- FILE* const file_org = fopen(argv[fileindex_org], "rb");
327
- if (file_org == NULL) {
328
- fprintf(stderr, "Cannot open %s\n", argv[fileindex_org]);
329
- exit(1);
330
- }
331
-
332
- // Open all files to compare to
333
- FILE** file_rec = new FILE*[num_rec];
334
- memset(file_rec, 0, num_rec * sizeof(FILE*)); // NOLINT
335
- for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
336
- file_rec[cur_rec] = fopen(argv[fileindex_rec + cur_rec], "rb");
337
- if (file_rec[cur_rec] == NULL) {
338
- fprintf(stderr, "Cannot open %s\n", argv[fileindex_rec + cur_rec]);
339
- fclose(file_org);
340
- for (int i = 0; i < cur_rec; ++i) {
341
- fclose(file_rec[i]);
342
- }
343
- delete[] file_rec;
344
- exit(1);
345
- }
346
- }
347
-
348
- const int y_size = image_width * image_height;
349
- const int uv_size = ((image_width + 1) / 2) * ((image_height + 1) / 2);
350
- const size_t total_size = y_size + 2 * uv_size; // NOLINT
351
- #if defined(_MSC_VER)
352
- _fseeki64(
353
- file_org,
354
- static_cast<__int64>(num_skip_org) * static_cast<__int64>(total_size),
355
- SEEK_SET);
356
- #else
357
- fseek(file_org, num_skip_org * total_size, SEEK_SET);
358
- #endif
359
- for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
360
- #if defined(_MSC_VER)
361
- _fseeki64(
362
- file_rec[cur_rec],
363
- static_cast<__int64>(num_skip_rec) * static_cast<__int64>(total_size),
364
- SEEK_SET);
365
- #else
366
- fseek(file_rec[cur_rec], num_skip_rec * total_size, SEEK_SET);
367
- #endif
368
- }
369
-
370
- uint8_t* const ch_org = new uint8_t[total_size];
371
- uint8_t* const ch_rec = new uint8_t[total_size];
372
- if (ch_org == NULL || ch_rec == NULL) {
373
- fprintf(stderr, "No memory available\n");
374
- fclose(file_org);
375
- for (int i = 0; i < num_rec; ++i) {
376
- fclose(file_rec[i]);
377
- }
378
- delete[] ch_org;
379
- delete[] ch_rec;
380
- delete[] file_rec;
381
- exit(1);
382
- }
383
-
384
- metric* const distortion_psnr = new metric[num_rec];
385
- metric* const distortion_ssim = new metric[num_rec];
386
- for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
387
- metric* cur_distortion_psnr = &distortion_psnr[cur_rec];
388
- cur_distortion_psnr->y = 0.0;
389
- cur_distortion_psnr->u = 0.0;
390
- cur_distortion_psnr->v = 0.0;
391
- cur_distortion_psnr->all = 0.0;
392
- cur_distortion_psnr->min_y = kMaxPSNR;
393
- cur_distortion_psnr->min_u = kMaxPSNR;
394
- cur_distortion_psnr->min_v = kMaxPSNR;
395
- cur_distortion_psnr->min_all = kMaxPSNR;
396
- cur_distortion_psnr->min_frame = 0;
397
- cur_distortion_psnr->global_y = 0.0;
398
- cur_distortion_psnr->global_u = 0.0;
399
- cur_distortion_psnr->global_v = 0.0;
400
- cur_distortion_psnr->global_all = 0.0;
401
- distortion_ssim[cur_rec] = cur_distortion_psnr[cur_rec];
402
- }
403
-
404
- if (verbose) {
405
- printf("Size: %dx%d\n", image_width, image_height);
406
- }
407
-
408
- if (!quiet) {
409
- printf("Frame");
410
- if (do_psnr) {
411
- printf("\t PSNR-Y \t PSNR-U \t PSNR-V \t PSNR-All \t Frame");
412
- }
413
- if (do_ssim) {
414
- printf("\t SSIM-Y\t SSIM-U\t SSIM-V\t SSIM-All\t Frame");
415
- }
416
- if (show_name) {
417
- printf("\tName\n");
418
- } else {
419
- printf("\n");
420
- }
421
- }
422
-
423
- int number_of_frames;
424
- for (number_of_frames = 0;; ++number_of_frames) {
425
- if (num_frames && number_of_frames >= num_frames) {
426
- break;
427
- }
428
-
429
- size_t bytes_org = fread(ch_org, sizeof(uint8_t), total_size, file_org);
430
- if (bytes_org < total_size) {
431
- #ifdef HAVE_JPEG
432
- // Try parsing file as a jpeg.
433
- uint8_t* const ch_jpeg = new uint8_t[bytes_org];
434
- memcpy(ch_jpeg, ch_org, bytes_org);
435
- memset(ch_org, 0, total_size);
436
-
437
- if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_org, ch_org, image_width,
438
- ch_org + y_size, (image_width + 1) / 2,
439
- ch_org + y_size + uv_size,
440
- (image_width + 1) / 2, image_width,
441
- image_height, image_width, image_height)) {
442
- delete[] ch_jpeg;
443
- break;
444
- }
445
- delete[] ch_jpeg;
446
- #else
447
- break;
448
- #endif // HAVE_JPEG
449
- }
450
-
451
- for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
452
- size_t bytes_rec =
453
- fread(ch_rec, sizeof(uint8_t), total_size, file_rec[cur_rec]);
454
- if (bytes_rec < total_size) {
455
- #ifdef HAVE_JPEG
456
- // Try parsing file as a jpeg.
457
- uint8_t* const ch_jpeg = new uint8_t[bytes_rec];
458
- memcpy(ch_jpeg, ch_rec, bytes_rec);
459
- memset(ch_rec, 0, total_size);
460
-
461
- if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_rec, ch_rec, image_width,
462
- ch_rec + y_size, (image_width + 1) / 2,
463
- ch_rec + y_size + uv_size,
464
- (image_width + 1) / 2, image_width,
465
- image_height, image_width, image_height)) {
466
- delete[] ch_jpeg;
467
- break;
468
- }
469
- delete[] ch_jpeg;
470
- #else
471
- break;
472
- #endif // HAVE_JPEG
473
- }
474
-
475
- if (verbose) {
476
- printf("%5d", number_of_frames);
477
- }
478
- if (do_psnr) {
479
- metric distorted_frame = {};
480
- metric* cur_distortion_psnr = &distortion_psnr[cur_rec];
481
- bool ismin = UpdateMetrics(ch_org, ch_rec, y_size, uv_size, total_size,
482
- number_of_frames, cur_distortion_psnr,
483
- &distorted_frame, true);
484
- if (verbose) {
485
- printf("\t%10.6f", distorted_frame.y);
486
- printf("\t%10.6f", distorted_frame.u);
487
- printf("\t%10.6f", distorted_frame.v);
488
- printf("\t%10.6f", distorted_frame.all);
489
- printf("\t%5s", ismin ? "min" : "");
490
- }
491
- }
492
- if (do_ssim) {
493
- metric distorted_frame = {};
494
- metric* cur_distortion_ssim = &distortion_ssim[cur_rec];
495
- bool ismin = UpdateMetrics(ch_org, ch_rec, y_size, uv_size, total_size,
496
- number_of_frames, cur_distortion_ssim,
497
- &distorted_frame, false);
498
- if (verbose) {
499
- printf("\t%10.6f", distorted_frame.y);
500
- printf("\t%10.6f", distorted_frame.u);
501
- printf("\t%10.6f", distorted_frame.v);
502
- printf("\t%10.6f", distorted_frame.all);
503
- printf("\t%5s", ismin ? "min" : "");
504
- }
505
- }
506
- if (verbose) {
507
- if (show_name) {
508
- printf("\t%s", argv[fileindex_rec + cur_rec]);
509
- }
510
- printf("\n");
511
- }
512
- }
513
- }
514
-
515
- // Final PSNR computation.
516
- for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
517
- metric* cur_distortion_psnr = &distortion_psnr[cur_rec];
518
- metric* cur_distortion_ssim = &distortion_ssim[cur_rec];
519
- if (number_of_frames > 0) {
520
- const double norm = 1. / static_cast<double>(number_of_frames);
521
- cur_distortion_psnr->y *= norm;
522
- cur_distortion_psnr->u *= norm;
523
- cur_distortion_psnr->v *= norm;
524
- cur_distortion_psnr->all *= norm;
525
- cur_distortion_ssim->y *= norm;
526
- cur_distortion_ssim->u *= norm;
527
- cur_distortion_ssim->v *= norm;
528
- cur_distortion_ssim->all *= norm;
529
- }
530
-
531
- if (do_psnr) {
532
- const double global_psnr_y =
533
- ComputePSNR(cur_distortion_psnr->global_y,
534
- static_cast<double>(y_size) * number_of_frames);
535
- const double global_psnr_u =
536
- ComputePSNR(cur_distortion_psnr->global_u,
537
- static_cast<double>(uv_size) * number_of_frames);
538
- const double global_psnr_v =
539
- ComputePSNR(cur_distortion_psnr->global_v,
540
- static_cast<double>(uv_size) * number_of_frames);
541
- const double global_psnr_all =
542
- ComputePSNR(cur_distortion_psnr->global_all,
543
- static_cast<double>(total_size) * number_of_frames);
544
- printf("Global:\t%10.6f\t%10.6f\t%10.6f\t%10.6f\t%5d", global_psnr_y,
545
- global_psnr_u, global_psnr_v, global_psnr_all, number_of_frames);
546
- if (show_name) {
547
- printf("\t%s", argv[fileindex_rec + cur_rec]);
548
- }
549
- printf("\n");
550
- }
551
-
552
- if (!quiet) {
553
- printf("Avg:");
554
- if (do_psnr) {
555
- printf("\t%10.6f\t%10.6f\t%10.6f\t%10.6f\t%5d", cur_distortion_psnr->y,
556
- cur_distortion_psnr->u, cur_distortion_psnr->v,
557
- cur_distortion_psnr->all, number_of_frames);
558
- }
559
- if (do_ssim) {
560
- printf("\t%10.6f\t%10.6f\t%10.6f\t%10.6f\t%5d", cur_distortion_ssim->y,
561
- cur_distortion_ssim->u, cur_distortion_ssim->v,
562
- cur_distortion_ssim->all, number_of_frames);
563
- }
564
- if (show_name) {
565
- printf("\t%s", argv[fileindex_rec + cur_rec]);
566
- }
567
- printf("\n");
568
- }
569
- if (!quiet) {
570
- printf("Min:");
571
- if (do_psnr) {
572
- printf("\t%10.6f\t%10.6f\t%10.6f\t%10.6f\t%5d",
573
- cur_distortion_psnr->min_y, cur_distortion_psnr->min_u,
574
- cur_distortion_psnr->min_v, cur_distortion_psnr->min_all,
575
- cur_distortion_psnr->min_frame);
576
- }
577
- if (do_ssim) {
578
- printf("\t%10.6f\t%10.6f\t%10.6f\t%10.6f\t%5d",
579
- cur_distortion_ssim->min_y, cur_distortion_ssim->min_u,
580
- cur_distortion_ssim->min_v, cur_distortion_ssim->min_all,
581
- cur_distortion_ssim->min_frame);
582
- }
583
- if (show_name) {
584
- printf("\t%s", argv[fileindex_rec + cur_rec]);
585
- }
586
- printf("\n");
587
- }
588
-
589
- if (do_mse) {
590
- double global_mse_y =
591
- GetMSE(cur_distortion_psnr->global_y,
592
- static_cast<double>(y_size) * number_of_frames);
593
- double global_mse_u =
594
- GetMSE(cur_distortion_psnr->global_u,
595
- static_cast<double>(uv_size) * number_of_frames);
596
- double global_mse_v =
597
- GetMSE(cur_distortion_psnr->global_v,
598
- static_cast<double>(uv_size) * number_of_frames);
599
- double global_mse_all =
600
- GetMSE(cur_distortion_psnr->global_all,
601
- static_cast<double>(total_size) * number_of_frames);
602
- printf("MSE:\t%10.6f\t%10.6f\t%10.6f\t%10.6f\t%5d", global_mse_y,
603
- global_mse_u, global_mse_v, global_mse_all, number_of_frames);
604
- if (show_name) {
605
- printf("\t%s", argv[fileindex_rec + cur_rec]);
606
- }
607
- printf("\n");
608
- }
609
- }
610
- fclose(file_org);
611
- for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
612
- fclose(file_rec[cur_rec]);
613
- }
614
- delete[] distortion_psnr;
615
- delete[] distortion_ssim;
616
- delete[] ch_org;
617
- delete[] ch_rec;
618
- delete[] file_rec;
619
- return 0;
620
- }