diff options
author | Chong Zhang <chz@google.com> | 2019-06-27 14:28:37 -0700 |
---|---|---|
committer | Chong Zhang <chz@google.com> | 2019-06-27 16:38:44 -0700 |
commit | ab123ac62c872f89e20f10c96e651ead21414ffc (patch) | |
tree | 61f45a95ef42e952ec121583ed73b8649e058bc1 /files/util | |
parent | ad97fd58c110036d9dfcdce8bf98282e92707a89 (diff) | |
download | libyuv-ab123ac62c872f89e20f10c96e651ead21414ffc.tar.gz |
libyuv roll to r1722 to pick up a few methods
that we've been manually cherry-picking.
bug: 132357297
test: MediaMetadataRetriever test; manual testing
thumbnails in Photos.
Exempt-From-Owner-Approval:
files/infra/config/OWNERS owner names are not in android
gerrit, CL fail to push with these. Delete of file need
to bypass owner.
Change-Id: Ic22346e45671452429716be8b0a1999eeaea0d7b
Diffstat (limited to 'files/util')
-rw-r--r-- | files/util/Makefile | 3 | ||||
-rw-r--r-- | files/util/compare.cc | 18 | ||||
-rw-r--r-- | files/util/cpuid.c | 29 | ||||
-rw-r--r-- | files/util/psnr.cc | 61 | ||||
-rw-r--r-- | files/util/psnr.h | 6 | ||||
-rw-r--r-- | files/util/psnr_main.cc | 57 | ||||
-rw-r--r-- | files/util/ssim.cc | 39 | ||||
-rw-r--r-- | files/util/ssim.h | 6 | ||||
-rw-r--r-- | files/util/yuvconvert.cc | 33 |
9 files changed, 146 insertions, 106 deletions
diff --git a/files/util/Makefile b/files/util/Makefile index 6044d2ad..40e74b65 100644 --- a/files/util/Makefile +++ b/files/util/Makefile @@ -4,3 +4,6 @@ ifeq ($(CXX),icl) else $(CXX) -msse2 -O3 -fopenmp -static -o psnr psnr.cc ssim.cc psnr_main.cc -Wl,--strip-all endif + +# for MacOS +# /usr/local/bin/g++-7 -msse2 -O3 -fopenmp -Bstatic -o psnr psnr.cc ssim.cc psnr_main.cc diff --git a/files/util/compare.cc b/files/util/compare.cc index ef0beefa..a16613ee 100644 --- a/files/util/compare.cc +++ b/files/util/compare.cc @@ -29,22 +29,24 @@ int main(int argc, char** argv) { FILE* fin2 = name2 ? fopen(name2, "rb") : NULL; const int kBlockSize = 32768; - uint8 buf1[kBlockSize]; - uint8 buf2[kBlockSize]; - uint32 hash1 = 5381; - uint32 hash2 = 5381; - uint64 sum_square_err = 0; - uint64 size_min = 0; + uint8_t buf1[kBlockSize]; + uint8_t buf2[kBlockSize]; + uint32_t hash1 = 5381; + uint32_t hash2 = 5381; + uint64_t sum_square_err = 0; + uint64_t size_min = 0; int amt1 = 0; int amt2 = 0; do { amt1 = static_cast<int>(fread(buf1, 1, kBlockSize, fin1)); - if (amt1 > 0) + if (amt1 > 0) { hash1 = libyuv::HashDjb2(buf1, amt1, hash1); + } if (fin2) { amt2 = static_cast<int>(fread(buf2, 1, kBlockSize, fin2)); - if (amt2 > 0) + if (amt2 > 0) { hash2 = libyuv::HashDjb2(buf2, amt2, hash2); + } int amt_min = (amt1 < amt2) ? amt1 : amt2; size_min += amt_min; sum_square_err += libyuv::ComputeSumSquareError(buf1, buf2, amt_min); diff --git a/files/util/cpuid.c b/files/util/cpuid.c index 9716f115..84c06022 100644 --- a/files/util/cpuid.c +++ b/files/util/cpuid.c @@ -22,10 +22,13 @@ int main(int argc, const char* argv[]) { int has_arm = TestCpuFlag(kCpuHasARM); int has_mips = TestCpuFlag(kCpuHasMIPS); int has_x86 = TestCpuFlag(kCpuHasX86); + (void)argc; + (void)argv; + #if defined(__i386__) || defined(__x86_64__) || \ defined(_M_IX86) || defined(_M_X64) if (has_x86) { - uint32 family, model, cpu_info[4]; + int family, model, cpu_info[4]; // Vendor ID: // AuthenticAMD AMD processor // CentaurHauls Centaur processor @@ -66,8 +69,10 @@ int main(int argc, const char* argv[]) { printf("Has NEON %x\n", has_neon); } if (has_mips) { - int has_dspr2 = TestCpuFlag(kCpuHasDSPR2); - printf("Has DSPR2 %x\n", has_dspr2); + int has_msa = TestCpuFlag(kCpuHasMSA); + printf("Has MSA %x\n", has_msa); + int has_mmi = TestCpuFlag(kCpuHasMMI); + printf("Has MMI %x\n", has_mmi); } if (has_x86) { int has_sse2 = TestCpuFlag(kCpuHasSSE2); @@ -76,20 +81,32 @@ int main(int argc, const char* argv[]) { int has_sse42 = TestCpuFlag(kCpuHasSSE42); int has_avx = TestCpuFlag(kCpuHasAVX); int has_avx2 = TestCpuFlag(kCpuHasAVX2); - int has_avx3 = TestCpuFlag(kCpuHasAVX3); int has_erms = TestCpuFlag(kCpuHasERMS); int has_fma3 = TestCpuFlag(kCpuHasFMA3); - int has_f16c = TestCpuFlag(kCpuHasF16C); + int has_f16c = TestCpuFlag(kCpuHasF16C); + int has_gfni = TestCpuFlag(kCpuHasGFNI); + int has_avx512bw = TestCpuFlag(kCpuHasAVX512BW); + int has_avx512vl = TestCpuFlag(kCpuHasAVX512VL); + int has_avx512vbmi = TestCpuFlag(kCpuHasAVX512VBMI); + int has_avx512vbmi2 = TestCpuFlag(kCpuHasAVX512VBMI2); + int has_avx512vbitalg = TestCpuFlag(kCpuHasAVX512VBITALG); + int has_avx512vpopcntdq = TestCpuFlag(kCpuHasAVX512VPOPCNTDQ); printf("Has SSE2 %x\n", has_sse2); printf("Has SSSE3 %x\n", has_ssse3); printf("Has SSE4.1 %x\n", has_sse41); printf("Has SSE4.2 %x\n", has_sse42); printf("Has AVX %x\n", has_avx); printf("Has AVX2 %x\n", has_avx2); - printf("Has AVX3 %x\n", has_avx3); printf("Has ERMS %x\n", has_erms); printf("Has FMA3 %x\n", has_fma3); printf("Has F16C %x\n", has_f16c); + printf("Has GFNI %x\n", has_gfni); + printf("Has AVX512BW %x\n", has_avx512bw); + printf("Has AVX512VL %x\n", has_avx512vl); + printf("Has AVX512VBMI %x\n", has_avx512vbmi); + printf("Has AVX512VBMI2 %x\n", has_avx512vbmi2); + printf("Has AVX512VBITALG %x\n", has_avx512vbitalg); + printf("Has AVX512VPOPCNTDQ %x\n", has_avx512vpopcntdq); } return 0; } diff --git a/files/util/psnr.cc b/files/util/psnr.cc index 27f876c0..f54015ba 100644 --- a/files/util/psnr.cc +++ b/files/util/psnr.cc @@ -21,14 +21,14 @@ extern "C" { #endif -typedef unsigned int uint32; // NOLINT +typedef unsigned int uint32_t; // NOLINT #ifdef _MSC_VER -typedef unsigned __int64 uint64; +typedef unsigned __int64 uint64_t; #else // COMPILER_MSVC #if defined(__LP64__) && !defined(__OpenBSD__) && !defined(__APPLE__) -typedef unsigned long uint64; // NOLINT +typedef unsigned long uint64_t; // NOLINT #else // defined(__LP64__) && !defined(__OpenBSD__) && !defined(__APPLE__) -typedef unsigned long long uint64; // NOLINT +typedef unsigned long long uint64_t; // NOLINT #endif // __LP64__ #endif // _MSC_VER @@ -38,10 +38,10 @@ typedef unsigned long long uint64; // NOLINT #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__) && \ !defined(__aarch64__) #define HAS_SUMSQUAREERROR_NEON -static uint32 SumSquareError_NEON(const uint8* src_a, - const uint8* src_b, - int count) { - volatile uint32 sse; +static uint32_t SumSquareError_NEON(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + volatile uint32_t sse; asm volatile( "vmov.u8 q7, #0 \n" "vmov.u8 q9, #0 \n" @@ -73,10 +73,10 @@ static uint32 SumSquareError_NEON(const uint8* src_a, } #elif !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__) #define HAS_SUMSQUAREERROR_NEON -static uint32 SumSquareError_NEON(const uint8* src_a, - const uint8* src_b, - int count) { - volatile uint32 sse; +static uint32_t SumSquareError_NEON(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + volatile uint32_t sse; asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "eor v18.16b, v18.16b, v18.16b \n" @@ -107,9 +107,9 @@ static uint32 SumSquareError_NEON(const uint8* src_a, } #elif !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) #define HAS_SUMSQUAREERROR_SSE2 -__declspec(naked) static uint32 SumSquareError_SSE2(const uint8* /*src_a*/, - const uint8* /*src_b*/, - int /*count*/) { +__declspec(naked) static uint32_t SumSquareError_SSE2(const uint8_t* /*src_a*/, + const uint8_t* /*src_b*/, + int /*count*/) { __asm { mov eax, [esp + 4] // src_a mov edx, [esp + 8] // src_b @@ -146,10 +146,10 @@ __declspec(naked) static uint32 SumSquareError_SSE2(const uint8* /*src_a*/, } #elif !defined(LIBYUV_DISABLE_X86) && (defined(__x86_64__) || defined(__i386__)) #define HAS_SUMSQUAREERROR_SSE2 -static uint32 SumSquareError_SSE2(const uint8* src_a, - const uint8* src_b, - int count) { - uint32 sse; +static uint32_t SumSquareError_SSE2(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t sse; asm volatile( // NOLINT "pxor %%xmm0,%%xmm0 \n" "pxor %%xmm5,%%xmm5 \n" @@ -228,22 +228,22 @@ static int CpuHasSSE2() { } #endif // HAS_SUMSQUAREERROR_SSE2 -static uint32 SumSquareError_C(const uint8* src_a, - const uint8* src_b, - int count) { - uint32 sse = 0u; +static uint32_t SumSquareError_C(const uint8_t* src_a, + const uint8_t* src_b, + int count) { + uint32_t sse = 0u; for (int x = 0; x < count; ++x) { int diff = src_a[x] - src_b[x]; - sse += static_cast<uint32>(diff * diff); + sse += static_cast<uint32_t>(diff * diff); } return sse; } -double ComputeSumSquareError(const uint8* src_a, - const uint8* src_b, +double ComputeSumSquareError(const uint8_t* src_a, + const uint8_t* src_b, int count) { - uint32 (*SumSquareError)(const uint8* src_a, const uint8* src_b, int count) = - SumSquareError_C; + uint32_t (*SumSquareError)(const uint8_t* src_a, const uint8_t* src_b, + int count) = SumSquareError_C; #if defined(HAS_SUMSQUAREERROR_NEON) SumSquareError = SumSquareError_NEON; #endif @@ -253,7 +253,7 @@ double ComputeSumSquareError(const uint8* src_a, } #endif const int kBlockSize = 1 << 15; - uint64 sse = 0; + uint64_t sse = 0; #ifdef _OPENMP #pragma omp parallel for reduction(+ : sse) #endif @@ -280,8 +280,9 @@ double ComputeSumSquareError(const uint8* src_a, // Returns 128.0 (kMaxPSNR) if sse is 0 (perfect match). double ComputePSNR(double sse, double size) { const double kMINSSE = 255.0 * 255.0 * size / pow(10.0, kMaxPSNR / 10.0); - if (sse <= kMINSSE) + if (sse <= kMINSSE) { sse = kMINSSE; // Produces max PSNR of 128 + } return 10.0 * log10(255.0 * 255.0 * size / sse); } diff --git a/files/util/psnr.h b/files/util/psnr.h index 0816b976..aac128cb 100644 --- a/files/util/psnr.h +++ b/files/util/psnr.h @@ -20,7 +20,7 @@ extern "C" { #endif #if !defined(INT_TYPES_DEFINED) && !defined(UINT8_TYPE_DEFINED) -typedef unsigned char uint8; +typedef unsigned char uint8_t; #define UINT8_TYPE_DEFINED #endif @@ -31,7 +31,9 @@ static const double kMaxPSNR = 128.0; #if !defined(HAVE_JPEG) // Computer Sum of Squared Error (SSE). // Pass this to ComputePSNR for final result. -double ComputeSumSquareError(const uint8* org, const uint8* rec, int size); +double ComputeSumSquareError(const uint8_t* src_a, + const uint8_t* src_b, + int count); #endif // PSNR formula: psnr = 10 * log10 (Peak Signal^2 * size / sse) diff --git a/files/util/psnr_main.cc b/files/util/psnr_main.cc index 4d930be4..a930b202 100644 --- a/files/util/psnr_main.cc +++ b/files/util/psnr_main.cc @@ -90,9 +90,9 @@ bool ExtractResolutionFromFilename(const char* name, fseek(file_org, 0, SEEK_END); size_t total_size = ftell(file_org); fseek(file_org, 0, SEEK_SET); - uint8* const ch_org = new uint8[total_size]; + uint8_t* const ch_org = new uint8_t[total_size]; memset(ch_org, 0, total_size); - size_t bytes_org = fread(ch_org, sizeof(uint8), total_size, file_org); + size_t bytes_org = fread(ch_org, sizeof(uint8_t), total_size, file_org); fclose(file_org); if (bytes_org == total_size) { if (0 == libyuv::MJPGSize(ch_org, total_size, width_ptr, height_ptr)) { @@ -107,13 +107,15 @@ bool ExtractResolutionFromFilename(const char* name, // Scale Y channel from 16..240 to 0..255. // This can be useful when comparing codecs that are inconsistant about Y -uint8 ScaleY(uint8 y) { +uint8_t ScaleY(uint8_t y) { int ny = (y - 16) * 256 / 224; - if (ny < 0) + if (ny < 0) { ny = 0; - if (ny > 255) + } + if (ny > 255) { ny = 255; - return static_cast<uint8>(ny); + } + return static_cast<uint8_t>(ny); } // MSE = Mean Square Error @@ -150,8 +152,9 @@ void PrintHelp(const char* program) { } void ParseOptions(int argc, const char* argv[]) { - if (argc <= 1) + if (argc <= 1) { PrintHelp(argv[0]); + } for (int c = 1; c < argc; ++c) { if (!strcmp(argv[c], "-v")) { verbose = true; @@ -237,8 +240,8 @@ void ParseOptions(int argc, const char* argv[]) { } } -bool UpdateMetrics(uint8* ch_org, - uint8* ch_rec, +bool UpdateMetrics(uint8_t* ch_org, + uint8_t* ch_rec, const int y_size, const int uv_size, const size_t total_size, @@ -247,10 +250,10 @@ bool UpdateMetrics(uint8* ch_org, metric* distorted_frame, bool do_psnr) { const int uv_offset = (do_swap_uv ? uv_size : 0); - const uint8* const u_org = ch_org + y_size + uv_offset; - const uint8* const u_rec = ch_rec + y_size; - const uint8* const v_org = ch_org + y_size + (uv_size - uv_offset); - const uint8* const v_rec = ch_rec + y_size + uv_size; + const uint8_t* const u_org = ch_org + y_size + uv_offset; + const uint8_t* const u_rec = ch_rec + y_size; + const uint8_t* const v_org = ch_org + y_size + (uv_size - uv_offset); + const uint8_t* const v_rec = ch_rec + y_size + uv_size; if (do_psnr) { #ifdef HAVE_JPEG double y_err = static_cast<double>( @@ -301,12 +304,15 @@ bool UpdateMetrics(uint8* ch_org, cur_distortion_psnr->all += distorted_frame->all; bool ismin = false; - if (distorted_frame->y < cur_distortion_psnr->min_y) + if (distorted_frame->y < cur_distortion_psnr->min_y) { cur_distortion_psnr->min_y = distorted_frame->y; - if (distorted_frame->u < cur_distortion_psnr->min_u) + } + if (distorted_frame->u < cur_distortion_psnr->min_u) { cur_distortion_psnr->min_u = distorted_frame->u; - if (distorted_frame->v < cur_distortion_psnr->min_v) + } + if (distorted_frame->v < cur_distortion_psnr->min_v) { cur_distortion_psnr->min_v = distorted_frame->v; + } if (distorted_frame->all < cur_distortion_psnr->min_all) { cur_distortion_psnr->min_all = distorted_frame->all; cur_distortion_psnr->min_frame = number_of_frames; @@ -374,8 +380,8 @@ int main(int argc, const char* argv[]) { #endif } - uint8* const ch_org = new uint8[total_size]; - uint8* const ch_rec = new uint8[total_size]; + uint8_t* const ch_org = new uint8_t[total_size]; + uint8_t* const ch_rec = new uint8_t[total_size]; if (ch_org == NULL || ch_rec == NULL) { fprintf(stderr, "No memory available\n"); fclose(file_org); @@ -429,14 +435,15 @@ int main(int argc, const char* argv[]) { int number_of_frames; for (number_of_frames = 0;; ++number_of_frames) { - if (num_frames && number_of_frames >= num_frames) + if (num_frames && number_of_frames >= num_frames) { break; + } - size_t bytes_org = fread(ch_org, sizeof(uint8), total_size, file_org); + size_t bytes_org = fread(ch_org, sizeof(uint8_t), total_size, file_org); if (bytes_org < total_size) { #ifdef HAVE_JPEG // Try parsing file as a jpeg. - uint8* const ch_jpeg = new uint8[bytes_org]; + uint8_t* const ch_jpeg = new uint8_t[bytes_org]; memcpy(ch_jpeg, ch_org, bytes_org); memset(ch_org, 0, total_size); @@ -456,11 +463,11 @@ int main(int argc, const char* argv[]) { for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) { size_t bytes_rec = - fread(ch_rec, sizeof(uint8), total_size, file_rec[cur_rec]); + fread(ch_rec, sizeof(uint8_t), total_size, file_rec[cur_rec]); if (bytes_rec < total_size) { #ifdef HAVE_JPEG // Try parsing file as a jpeg. - uint8* const ch_jpeg = new uint8[bytes_rec]; + uint8_t* const ch_jpeg = new uint8_t[bytes_rec]; memcpy(ch_jpeg, ch_rec, bytes_rec); memset(ch_rec, 0, total_size); @@ -482,7 +489,7 @@ int main(int argc, const char* argv[]) { printf("%5d", number_of_frames); } if (do_psnr) { - metric distorted_frame; + metric distorted_frame = {}; metric* cur_distortion_psnr = &distortion_psnr[cur_rec]; bool ismin = UpdateMetrics(ch_org, ch_rec, y_size, uv_size, total_size, number_of_frames, cur_distortion_psnr, @@ -496,7 +503,7 @@ int main(int argc, const char* argv[]) { } } if (do_ssim) { - metric distorted_frame; + metric distorted_frame = {}; metric* cur_distortion_ssim = &distortion_ssim[cur_rec]; bool ismin = UpdateMetrics(ch_org, ch_rec, y_size, uv_size, total_size, number_of_frames, cur_distortion_ssim, diff --git a/files/util/ssim.cc b/files/util/ssim.cc index 43e725d8..096fbcf0 100644 --- a/files/util/ssim.cc +++ b/files/util/ssim.cc @@ -16,8 +16,8 @@ extern "C" { #endif -typedef unsigned int uint32; // NOLINT -typedef unsigned short uint16; // NOLINT +typedef unsigned int uint32_t; // NOLINT +typedef unsigned short uint16_t; // NOLINT #if !defined(LIBYUV_DISABLE_X86) && !defined(__SSE2__) && \ (defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP >= 2))) @@ -50,7 +50,7 @@ static const double kiW[KERNEL + 1 + 1] = { #if !defined(LIBYUV_DISABLE_X86) && defined(__SSE2__) -#define PWEIGHT(A, B) static_cast<uint16>(K[(A)] * K[(B)]) // weight product +#define PWEIGHT(A, B) static_cast<uint16_t>(K[(A)] * K[(B)]) // weight product #define MAKE_WEIGHT(L) \ { \ { \ @@ -66,7 +66,7 @@ static const double kiW[KERNEL + 1 + 1] = { // values. We can't call _mm_set_epi16() for static compile-time initialization. static const struct { union { - uint16 i16_[8]; + uint16_t i16_[8]; __m128i m_; } values_; } W0 = MAKE_WEIGHT(0), W1 = MAKE_WEIGHT(1), W2 = MAKE_WEIGHT(2), @@ -88,10 +88,12 @@ static double FinalizeSSIM(double iw, double sxx = xxm * iw - iwx * iwx; double syy = yym * iw - iwy * iwy; // small errors are possible, due to rounding. Clamp to zero. - if (sxx < 0.) + if (sxx < 0.) { sxx = 0.; - if (syy < 0.) + } + if (syy < 0.) { syy = 0.; + } const double sxsy = sqrt(sxx * syy); const double sxy = xym * iw - iwx * iwy; static const double C11 = (0.01 * 0.01) * (255 * 255); @@ -109,21 +111,22 @@ static double FinalizeSSIM(double iw, // Note: worst case of accumulation is a weight of 33 = 11 + 2 * (7 + 3 + 1) // with a diff of 255, squared. The maximum error is thus 0x4388241, // which fits into 32 bits integers. -double GetSSIM(const uint8* org, - const uint8* rec, +double GetSSIM(const uint8_t* org, + const uint8_t* rec, int xo, int yo, int W, int H, int stride) { - uint32 ws = 0, xm = 0, ym = 0, xxm = 0, xym = 0, yym = 0; + uint32_t ws = 0, xm = 0, ym = 0, xxm = 0, xym = 0, yym = 0; org += (yo - KERNEL) * stride; org += (xo - KERNEL); rec += (yo - KERNEL) * stride; rec += (xo - KERNEL); for (int y_ = 0; y_ < KERNEL_SIZE; ++y_, org += stride, rec += stride) { - if (((yo - KERNEL + y_) < 0) || ((yo - KERNEL + y_) >= H)) + if (((yo - KERNEL + y_) < 0) || ((yo - KERNEL + y_) >= H)) { continue; + } const int Wy = K[y_]; for (int x_ = 0; x_ < KERNEL_SIZE; ++x_) { const int Wxy = Wy * K[x_]; @@ -142,13 +145,13 @@ double GetSSIM(const uint8* org, return FinalizeSSIM(1. / ws, xm, ym, xxm, xym, yym); } -double GetSSIMFullKernel(const uint8* org, - const uint8* rec, +double GetSSIMFullKernel(const uint8_t* org, + const uint8_t* rec, int xo, int yo, int stride, double area_weight) { - uint32 xm = 0, ym = 0, xxm = 0, xym = 0, yym = 0; + uint32_t xm = 0, ym = 0, xxm = 0, xym = 0, yym = 0; #if defined(LIBYUV_DISABLE_X86) || !defined(__SSE2__) @@ -262,7 +265,7 @@ double GetSSIMFullKernel(const uint8* org, #define ADD_AND_STORE_FOUR_EPI32(M, OUT) \ do { \ - uint32 tmp[4]; \ + uint32_t tmp[4]; \ _mm_storeu_si128(reinterpret_cast<__m128i*>(tmp), (M)); \ (OUT) = tmp[3] + tmp[2] + tmp[1] + tmp[0]; \ } while (0) @@ -292,8 +295,8 @@ static int start_max(int x, int y) { return (x > y) ? x : y; } -double CalcSSIM(const uint8* org, - const uint8* rec, +double CalcSSIM(const uint8_t* org, + const uint8_t* rec, const int image_width, const int image_height) { double SSIM = 0.; @@ -328,8 +331,8 @@ double CalcSSIM(const uint8* org, // NOTE: we could use similar method for the left-most pixels too. const int kScratchWidth = 8; const int kScratchStride = kScratchWidth + KERNEL + 1; - uint8 scratch_org[KERNEL_SIZE * kScratchStride] = {0}; - uint8 scratch_rec[KERNEL_SIZE * kScratchStride] = {0}; + uint8_t scratch_org[KERNEL_SIZE * kScratchStride] = {0}; + uint8_t scratch_rec[KERNEL_SIZE * kScratchStride] = {0}; for (int k = 0; k < KERNEL_SIZE; ++k) { const int offset = diff --git a/files/util/ssim.h b/files/util/ssim.h index 4647f45d..a855f1d1 100644 --- a/files/util/ssim.h +++ b/files/util/ssim.h @@ -20,12 +20,12 @@ extern "C" { #endif #if !defined(INT_TYPES_DEFINED) && !defined(UINT8_TYPE_DEFINED) -typedef unsigned char uint8; +typedef unsigned char uint8_t; #define UINT8_TYPE_DEFINED #endif -double CalcSSIM(const uint8* org, - const uint8* rec, +double CalcSSIM(const uint8_t* org, + const uint8_t* rec, const int image_width, const int image_height); diff --git a/files/util/yuvconvert.cc b/files/util/yuvconvert.cc index bc01d9ff..27cdfe9e 100644 --- a/files/util/yuvconvert.cc +++ b/files/util/yuvconvert.cc @@ -37,7 +37,7 @@ int num_skip_org = 0; // Number of frames to skip in original. int num_frames = 0; // Number of frames to convert. int filter = 1; // Bilinear filter for scaling. -static __inline uint32 Abs(int32 v) { +static __inline uint32_t Abs(int32_t v) { return v >= 0 ? v : -v; } @@ -79,8 +79,9 @@ void PrintHelp(const char* program) { } void ParseOptions(int argc, const char* argv[]) { - if (argc <= 1) + if (argc <= 1) { PrintHelp(argv[0]); + } for (int c = 1; c < argc; ++c) { if (!strcmp(argv[c], "-v")) { verbose = true; @@ -158,11 +159,11 @@ void ParseOptions(int argc, const char* argv[]) { static const int kTileX = 32; static const int kTileY = 32; -static int TileARGBScale(const uint8* src_argb, +static int TileARGBScale(const uint8_t* src_argb, int src_stride_argb, int src_width, int src_height, - uint8* dst_argb, + uint8_t* dst_argb, int dst_stride_argb, int dst_width, int dst_height, @@ -242,9 +243,9 @@ int main(int argc, const char* argv[]) { fseek(file_org, num_skip_org * total_size, SEEK_SET); #endif - uint8* const ch_org = new uint8[org_size]; - uint8* const ch_dst = new uint8[dst_size]; - uint8* const ch_rec = new uint8[total_size]; + uint8_t* const ch_org = new uint8_t[org_size]; + uint8_t* const ch_dst = new uint8_t[dst_size]; + uint8_t* const ch_rec = new uint8_t[total_size]; if (ch_org == NULL || ch_rec == NULL) { fprintf(stderr, "No memory available\n"); fclose(file_org); @@ -265,14 +266,16 @@ int main(int argc, const char* argv[]) { int number_of_frames; for (number_of_frames = 0;; ++number_of_frames) { - if (num_frames && number_of_frames >= num_frames) + if (num_frames && number_of_frames >= num_frames) { break; + } // Load original YUV or ARGB frame. size_t bytes_org = - fread(ch_org, sizeof(uint8), static_cast<size_t>(org_size), file_org); - if (bytes_org < static_cast<size_t>(org_size)) + fread(ch_org, sizeof(uint8_t), static_cast<size_t>(org_size), file_org); + if (bytes_org < static_cast<size_t>(org_size)) { break; + } // TODO(fbarchard): Attenuate doesnt need to know dimensions. // ARGB attenuate frame @@ -329,16 +332,18 @@ int main(int argc, const char* argv[]) { // Output YUV or ARGB frame. if (rec_is_yuv) { size_t bytes_rec = - fwrite(ch_rec, sizeof(uint8), static_cast<size_t>(total_size), + fwrite(ch_rec, sizeof(uint8_t), static_cast<size_t>(total_size), file_rec[cur_rec]); - if (bytes_rec < static_cast<size_t>(total_size)) + if (bytes_rec < static_cast<size_t>(total_size)) { break; + } } else { size_t bytes_rec = - fwrite(ch_dst, sizeof(uint8), static_cast<size_t>(dst_size), + fwrite(ch_dst, sizeof(uint8_t), static_cast<size_t>(dst_size), file_rec[cur_rec]); - if (bytes_rec < static_cast<size_t>(dst_size)) + if (bytes_rec < static_cast<size_t>(dst_size)) { break; + } } if (verbose) { printf("%5d", number_of_frames); |