From b792e0dbc152dbeea6f4a5ba59dccd05c32eb3c2 Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Tue, 6 Feb 2018 17:03:31 -0800 Subject: [PATCH] tidy applied with all cppcoreguidelines and google TBR=braveyao@chromium.org Bug: libyuv:750 Test: builds and runs and passes more tidy tests Change-Id: I1400a915ee5734c38d19dab9cf1f210ca43d17fc Reviewed-on: https://chromium-review.googlesource.com/905810 Reviewed-by: Frank Barchard --- source/compare.cc | 3 ++- unit_test/compare_test.cc | 9 ++++++--- unit_test/convert_test.cc | 36 ++++++++++++++++++++++++------------ unit_test/planar_test.cc | 3 ++- unit_test/unit_test.h | 7 ------- util/compare.cc | 6 ++++-- util/psnr.cc | 3 ++- util/psnr_main.cc | 25 ++++++++++++++++--------- util/ssim.cc | 9 ++++++--- util/yuvconvert.cc | 15 ++++++++++----- 10 files changed, 72 insertions(+), 44 deletions(-) diff --git a/source/compare.cc b/source/compare.cc index 02dd5f7a8..50e3abd05 100644 --- a/source/compare.cc +++ b/source/compare.cc @@ -263,8 +263,9 @@ double SumSquareErrorToPsnr(uint64_t sse, uint64_t count) { psnr = kMaxPsnr; // Limit to prevent divide by 0 } - if (psnr > kMaxPsnr) + if (psnr > kMaxPsnr) { psnr = kMaxPsnr; + } return psnr; } diff --git a/unit_test/compare_test.cc b/unit_test/compare_test.cc index c8546b023..136254e16 100644 --- a/unit_test/compare_test.cc +++ b/unit_test/compare_test.cc @@ -504,9 +504,10 @@ TEST_F(LibYUVCompareTest, BenchmarkPsnr_Opt) { MaskCpuFlags(benchmark_cpu_info_); double opt_time = get_time(); - for (int i = 0; i < benchmark_iterations_; ++i) + for (int i = 0; i < benchmark_iterations_; ++i) { CalcFramePsnr(src_a, benchmark_width_, src_b, benchmark_width_, benchmark_width_, benchmark_height_); + } opt_time = (get_time() - opt_time) / benchmark_iterations_; printf("BenchmarkPsnr_Opt - %8.2f us opt\n", opt_time * 1e6); @@ -528,9 +529,10 @@ TEST_F(LibYUVCompareTest, BenchmarkPsnr_Unaligned) { MaskCpuFlags(benchmark_cpu_info_); double opt_time = get_time(); - for (int i = 0; i < benchmark_iterations_; ++i) + for (int i = 0; i < benchmark_iterations_; ++i) { CalcFramePsnr(src_a + 1, benchmark_width_, src_b, benchmark_width_, benchmark_width_, benchmark_height_); + } opt_time = (get_time() - opt_time) / benchmark_iterations_; printf("BenchmarkPsnr_Opt - %8.2f us opt\n", opt_time * 1e6); @@ -629,9 +631,10 @@ TEST_F(LibYUVCompareTest, DISABLED_BenchmarkSsim_Opt) { MaskCpuFlags(benchmark_cpu_info_); double opt_time = get_time(); - for (int i = 0; i < benchmark_iterations_; ++i) + for (int i = 0; i < benchmark_iterations_; ++i) { CalcFrameSsim(src_a, benchmark_width_, src_b, benchmark_width_, benchmark_width_, benchmark_height_); + } opt_time = (get_time() - opt_time) / benchmark_iterations_; printf("BenchmarkSsim_Opt - %8.2f us opt\n", opt_time * 1e6); diff --git a/unit_test/convert_test.cc b/unit_test/convert_test.cc index 0f7c1dfb1..221eecd5b 100644 --- a/unit_test/convert_test.cc +++ b/unit_test/convert_test.cc @@ -2191,12 +2191,15 @@ TEST_F(LibYUVConvertTest, TestH420ToARGB) { int count_g = 0; int count_r = 0; for (int i = 0; i < kSize; ++i) { - if (histogram_b[i]) + if (histogram_b[i]) { ++count_b; - if (histogram_g[i]) + } + if (histogram_g[i]) { ++count_g; - if (histogram_r[i]) + } + if (histogram_r[i]) { ++count_r; + } } printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); @@ -2249,12 +2252,15 @@ TEST_F(LibYUVConvertTest, TestH010ToARGB) { int count_g = 0; int count_r = 0; for (int i = 0; i < kSize; ++i) { - if (histogram_b[i]) + if (histogram_b[i]) { ++count_b; - if (histogram_g[i]) + } + if (histogram_g[i]) { ++count_g; - if (histogram_r[i]) + } + if (histogram_r[i]) { ++count_r; + } } printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); @@ -2309,12 +2315,15 @@ TEST_F(LibYUVConvertTest, TestH010ToAR30) { int count_g = 0; int count_r = 0; for (int i = 0; i < kSize; ++i) { - if (histogram_b[i]) + if (histogram_b[i]) { ++count_b; - if (histogram_g[i]) + } + if (histogram_g[i]) { ++count_g; - if (histogram_r[i]) + } + if (histogram_r[i]) { ++count_r; + } } printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); @@ -2368,12 +2377,15 @@ TEST_F(LibYUVConvertTest, TestH420ToAR30) { int count_g = 0; int count_r = 0; for (int i = 0; i < kHistSize; ++i) { - if (histogram_b[i]) + if (histogram_b[i]) { ++count_b; - if (histogram_g[i]) + } + if (histogram_g[i]) { ++count_g; - if (histogram_r[i]) + } + if (histogram_r[i]) { ++count_r; + } } printf("uniques: B %d, G, %d, R %d\n", count_b, count_g, count_r); diff --git a/unit_test/planar_test.cc b/unit_test/planar_test.cc index c55234ba2..b52c0f491 100644 --- a/unit_test/planar_test.cc +++ b/unit_test/planar_test.cc @@ -1390,8 +1390,9 @@ TEST_F(LibYUVPlanarTest, TestCopyPlane) { } for (i = 0; i < y_plane_size; ++i) { - if (dst_c[i] != dst_opt[i]) + if (dst_c[i] != dst_opt[i]) { ++err; + } } free_aligned_buffer_page_end(orig_y); diff --git a/unit_test/unit_test.h b/unit_test/unit_test.h index aec5b8d25..dee3952fd 100644 --- a/unit_test/unit_test.h +++ b/unit_test/unit_test.h @@ -129,7 +129,6 @@ class LibYUVColorTest : public ::testing::Test { int benchmark_iterations_; // Default 1. Use 1000 for benchmarking. int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA. int benchmark_height_; // Default 720. Use 360 for benchmarking VGA. - int benchmark_pixels_div256_; // Total pixels to benchmark / 256. int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280. int disable_cpu_flags_; // Default 1. Use -1 for benchmarking. int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD. @@ -142,7 +141,6 @@ class LibYUVConvertTest : public ::testing::Test { int benchmark_iterations_; // Default 1. Use 1000 for benchmarking. int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA. int benchmark_height_; // Default 720. Use 360 for benchmarking VGA. - int benchmark_pixels_div256_; // Total pixels to benchmark / 256. int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280. int disable_cpu_flags_; // Default 1. Use -1 for benchmarking. int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD. @@ -155,7 +153,6 @@ class LibYUVScaleTest : public ::testing::Test { int benchmark_iterations_; // Default 1. Use 1000 for benchmarking. int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA. int benchmark_height_; // Default 720. Use 360 for benchmarking VGA. - int benchmark_pixels_div256_; // Total pixels to benchmark / 256. int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280. int disable_cpu_flags_; // Default 1. Use -1 for benchmarking. int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD. @@ -168,7 +165,6 @@ class LibYUVRotateTest : public ::testing::Test { int benchmark_iterations_; // Default 1. Use 1000 for benchmarking. int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA. int benchmark_height_; // Default 720. Use 360 for benchmarking VGA. - int benchmark_pixels_div256_; // Total pixels to benchmark / 256. int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280. int disable_cpu_flags_; // Default 1. Use -1 for benchmarking. int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD. @@ -181,7 +177,6 @@ class LibYUVPlanarTest : public ::testing::Test { int benchmark_iterations_; // Default 1. Use 1000 for benchmarking. int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA. int benchmark_height_; // Default 720. Use 360 for benchmarking VGA. - int benchmark_pixels_div256_; // Total pixels to benchmark / 256. int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280. int disable_cpu_flags_; // Default 1. Use -1 for benchmarking. int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD. @@ -194,7 +189,6 @@ class LibYUVBaseTest : public ::testing::Test { int benchmark_iterations_; // Default 1. Use 1000 for benchmarking. int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA. int benchmark_height_; // Default 720. Use 360 for benchmarking VGA. - int benchmark_pixels_div256_; // Total pixels to benchmark / 256. int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280. int disable_cpu_flags_; // Default 1. Use -1 for benchmarking. int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD. @@ -207,7 +201,6 @@ class LibYUVCompareTest : public ::testing::Test { int benchmark_iterations_; // Default 1. Use 1000 for benchmarking. int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA. int benchmark_height_; // Default 720. Use 360 for benchmarking VGA. - int benchmark_pixels_div256_; // Total pixels to benchmark / 256. int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280. int disable_cpu_flags_; // Default 1. Use -1 for benchmarking. int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD. diff --git a/util/compare.cc b/util/compare.cc index 249db6586..a16613ee2 100644 --- a/util/compare.cc +++ b/util/compare.cc @@ -39,12 +39,14 @@ int main(int argc, char** argv) { int amt2 = 0; do { amt1 = static_cast(fread(buf1, 1, kBlockSize, fin1)); - if (amt1 > 0) + if (amt1 > 0) { hash1 = libyuv::HashDjb2(buf1, amt1, hash1); + } if (fin2) { amt2 = static_cast(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/util/psnr.cc b/util/psnr.cc index 0196a3939..f54015bab 100644 --- a/util/psnr.cc +++ b/util/psnr.cc @@ -280,8 +280,9 @@ double ComputeSumSquareError(const uint8_t* 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/util/psnr_main.cc b/util/psnr_main.cc index cfdf8ff68..a930b202e 100644 --- a/util/psnr_main.cc +++ b/util/psnr_main.cc @@ -109,10 +109,12 @@ bool ExtractResolutionFromFilename(const char* name, // This can be useful when comparing codecs that are inconsistant about 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(ny); } @@ -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; @@ -301,12 +304,15 @@ bool UpdateMetrics(uint8_t* 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; @@ -429,8 +435,9 @@ 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_t), total_size, file_org); if (bytes_org < 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/util/ssim.cc b/util/ssim.cc index 126c436a7..096fbcf06 100644 --- a/util/ssim.cc +++ b/util/ssim.cc @@ -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); @@ -122,8 +124,9 @@ double GetSSIM(const uint8_t* org, 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_]; diff --git a/util/yuvconvert.cc b/util/yuvconvert.cc index 38712daf3..27cdfe9e3 100644 --- a/util/yuvconvert.cc +++ b/util/yuvconvert.cc @@ -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; @@ -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_t), static_cast(org_size), file_org); - if (bytes_org < static_cast(org_size)) + if (bytes_org < static_cast(org_size)) { break; + } // TODO(fbarchard): Attenuate doesnt need to know dimensions. // ARGB attenuate frame @@ -331,14 +334,16 @@ int main(int argc, const char* argv[]) { size_t bytes_rec = fwrite(ch_rec, sizeof(uint8_t), static_cast(total_size), file_rec[cur_rec]); - if (bytes_rec < static_cast(total_size)) + if (bytes_rec < static_cast(total_size)) { break; + } } else { size_t bytes_rec = fwrite(ch_dst, sizeof(uint8_t), static_cast(dst_size), file_rec[cur_rec]); - if (bytes_rec < static_cast(dst_size)) + if (bytes_rec < static_cast(dst_size)) { break; + } } if (verbose) { printf("%5d", number_of_frames);