diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..b0c1f1e --- /dev/null +++ b/.clang-tidy @@ -0,0 +1 @@ +Checks: 'performance-*,portability-*,readability-*,clang-analyzer-*,bugprone-*,modernize-*' \ No newline at end of file diff --git a/HDRI/debevec_weight.hpp b/HDRI/debevec_weight.hpp index 29112ca..6543781 100644 --- a/HDRI/debevec_weight.hpp +++ b/HDRI/debevec_weight.hpp @@ -7,7 +7,7 @@ namespace HDRI { class debevec_weight final { public: debevec_weight() = delete; - [[nodiscard]] static double get_weight(const int index) noexcept; + [[nodiscard]] static double get_weight(const int z_value) noexcept; [[nodiscard]] static std::size_t get_size() noexcept; }; diff --git a/HDRI/hdr_image.cpp b/HDRI/hdr_image.cpp index f22bffe..d226c97 100644 --- a/HDRI/hdr_image.cpp +++ b/HDRI/hdr_image.cpp @@ -12,8 +12,8 @@ namespace { template -cv::Mat construct_radiance(const std::vector &image_files, const std::array &curves, - weight_function &&weighting, const std::vector &expo) noexcept { +auto construct_radiance(const std::vector &image_files, const std::array &curves, + weight_function &&weighting, const std::vector &expo) noexcept -> cv::Mat { // Size const auto width = image_files[0UL].get_width(); const auto height = image_files[0UL].get_height(); @@ -21,26 +21,26 @@ cv::Mat construct_radiance(const std::vector &image_files, cons // Radiance cv::Mat radiance(height, width, CV_32FC3); - for (auto idx = 0UL; idx < std::size(curves); ++idx) { // r, g, b - for (auto y = 0UL; y < height; ++y) { - for (auto x = 0UL; x < width; ++x) { - double weighted_sum = 0.0; - double result = 0.0; + for (int idx = 0; idx < std::size(curves); ++idx) { // r, g, b + for (auto y = 0; y < height; ++y) { + for (auto x = 0; x < width; ++x) { + auto weighted_sum = 0.0; + auto result = 0.0; // loop over all images for (auto k = 0UL; k < std::size(image_files); ++k) { const auto color = static_cast(image_files[k].get_image_data().at(y, x)[idx]); const double w = std::invoke(std::forward(weighting), color); - result += static_cast(w * (curves[idx].at(color, 0) - std::log(expo[k]))); + result += w * (curves[idx].at(color, 0) - std::log(expo[k])); weighted_sum += w; } if (weighted_sum < std::numeric_limits::epsilon() && weighted_sum > -std::numeric_limits::epsilon()) { // near 0.0 - radiance.at(y, x)[idx] = 0; + radiance.at(y, x)[idx] = 0.0F; } else { - radiance.at(y, x)[idx] = std::exp(result / weighted_sum); + radiance.at(y, x)[idx] = static_cast(std::exp(result / weighted_sum)); } } } @@ -49,24 +49,24 @@ cv::Mat construct_radiance(const std::vector &image_files, cons return radiance; } -std::vector shrink_images(const std::vector &input) noexcept { +auto shrink_images(const std::vector &input) noexcept -> std::vector { std::vector out; out.reserve(std::size(input)); - constexpr size_t ratio = 50UL; + constexpr auto ratio = 50; for (const auto &img : input) { const auto &image_data = img.get_image_data(); - size_t resized_col = image_data.cols / ratio; - size_t resized_row = image_data.rows / ratio; + auto resized_col = image_data.cols / ratio; + auto resized_row = image_data.rows / ratio; - if (resized_col < 15UL) { - resized_col = 15UL; + if (resized_col < 15) { + resized_col = 15; } - if (resized_row < 15UL) { - resized_row = 15UL; + if (resized_row < 15) { + resized_row = 15; } cv::Mat shrink_mat; @@ -79,17 +79,17 @@ std::vector shrink_images(const std::vector &input) no return out; } -std::vector> generate_raw_pixel(const std::vector &shrink_mat) noexcept { +auto generate_raw_pixel(const std::vector &shrink_mat) noexcept -> std::vector> { const auto width = shrink_mat[0UL].size().width; const auto height = shrink_mat[0UL].size().height; std::vector> pixels(shrink_mat.size()); for (auto idx = 0UL; idx < shrink_mat.size(); ++idx) { - pixels[idx].resize(width * height); + pixels[idx].resize(static_cast(width) * height); - for (auto y = 0UL; y < height; ++y) { - for (auto x = 0UL; x < width; ++x) { + for (auto y = 0; y < height; ++y) { + for (auto x = 0; x < width; ++x) { pixels[idx][y * width + x].b = shrink_mat[idx].at(y, x)[0UL]; pixels[idx][y * width + x].g = shrink_mat[idx].at(y, x)[1UL]; pixels[idx][y * width + x].r = shrink_mat[idx].at(y, x)[2UL]; @@ -100,8 +100,8 @@ std::vector> generate_raw_pixel(const std::vector &s return pixels; } -std::array>, 3UL> convert_to_z(const std::vector> &pixel, - const size_t image_size, const size_t num_images) noexcept { +auto convert_to_z(const std::vector> &pixel, const size_t image_size, + const size_t num_images) noexcept -> std::array>, 3UL> { std::array>, 3UL> z_values; // r, g, b for (auto &z_colors : z_values) { @@ -141,12 +141,12 @@ hdr_image::hdr_image(const std::vector &raw_images) { compute_radiance(raw_images, exposure); } -const std::array &hdr_image::get_curves() const noexcept { return curves; } +auto hdr_image::get_curves() const noexcept -> const std::array & { return curves; } void hdr_image::compute_curves(const std::vector &raw_images, const std::vector &exposure) noexcept { const auto shrink_mat = shrink_images(raw_images); - std::vector> raw_pixel = generate_raw_pixel(shrink_mat); + const auto raw_pixel = generate_raw_pixel(shrink_mat); // convert const auto z_values = convert_to_z(raw_pixel, shrink_mat[0UL].total(), shrink_mat.size()); @@ -171,6 +171,6 @@ void hdr_image::compute_radiance(const std::vector &raw_images, radiance = construct_radiance(raw_images, curves, debevec_weight::get_weight, exposure); } -const cv::Mat &hdr_image::get_radiance() const noexcept { return radiance; } +auto hdr_image::get_radiance() const noexcept -> const cv::Mat & { return radiance; } } // namespace HDRI \ No newline at end of file diff --git a/HDRI/main.cpp b/HDRI/main.cpp index b1854be..81d0d7a 100644 --- a/HDRI/main.cpp +++ b/HDRI/main.cpp @@ -26,14 +26,15 @@ void output_curve(const cv::Mat &curve) noexcept { std::ofstream fout("out_curve.txt"); - for (auto q = 0UL; q < height; ++q) { - for (auto p = 0UL; p < width; ++p) { + for (auto q = 0; q < height; ++q) { + for (auto p = 0; p < width; ++p) { fout << curve.at(q, p) << std::endl; } } } -std::vector load_raw_images(const std::string &base_path, const std::string &file_name) noexcept { +auto load_raw_images(const std::string &base_path, const std::string &file_name) noexcept + -> std::vector { const auto full_path = base_path + file_name; std::ifstream input(full_path); @@ -93,7 +94,7 @@ std::vector load_raw_images(const std::string &base_path, const } // namespace -int main(int argc, char *argv[]) { +auto main(int argc, char *argv[]) -> int { constexpr auto default_base_path{"../InputImage/"}; constexpr auto default_files{"list.txt"}; diff --git a/HDRI/raw_image.cpp b/HDRI/raw_image.cpp index bdc1baf..f52d308 100644 --- a/HDRI/raw_image.cpp +++ b/HDRI/raw_image.cpp @@ -5,8 +5,8 @@ namespace HDRI { -raw_image::raw_image(std::string file_name, const double shutter_speed) - : image_data{cv::imread(file_name)}, expo{1.0 / shutter_speed}, name{std::move(file_name)} { +raw_image::raw_image(const std::string& file_name, const double shutter_speed) + : image_data{cv::imread(file_name)}, expo{1.0 / shutter_speed} { if (image_data.empty()) { std::cerr << "Fail to load: " + file_name << std::endl; throw std::runtime_error("Fail to load" + file_name); diff --git a/HDRI/raw_image.hpp b/HDRI/raw_image.hpp index c1d5998..f5ac676 100644 --- a/HDRI/raw_image.hpp +++ b/HDRI/raw_image.hpp @@ -8,7 +8,7 @@ namespace HDRI { class raw_image final { public: - explicit raw_image(std::string file_name, const double shutter_speed); + explicit raw_image(const std::string &file_name, const double shutter_speed); raw_image(const raw_image &) noexcept = default; raw_image(raw_image &&) noexcept = default; @@ -27,7 +27,6 @@ class raw_image final { private: cv::Mat image_data; - std::string name; double expo; }; diff --git a/HDRI/tone_map_algo.cpp b/HDRI/tone_map_algo.cpp index c549dfe..1e1bf26 100644 --- a/HDRI/tone_map_algo.cpp +++ b/HDRI/tone_map_algo.cpp @@ -4,8 +4,8 @@ namespace { -constexpr float rgb_to_luminance(const float r, const float g, const float b) noexcept { - return 0.2126f * r + 0.7152f * g + 0.0722f * b; +constexpr auto rgb_to_luminance(const float r, const float g, const float b) noexcept -> float { + return 0.2126F * r + 0.7152F * g + 0.0722F * b; } } // namespace @@ -13,47 +13,47 @@ constexpr float rgb_to_luminance(const float r, const float g, const float b) no namespace HDRI { auto reinhard_tone_map_algo(const cv::Mat &input_radiance) noexcept -> cv::Mat { - constexpr float epsilon = 0.00001f; - constexpr float a = 0.18f; // from paper + constexpr auto epsilon = 0.00001F; + constexpr auto a = 0.18F; // from paper // color space transform cv::Mat lumi(input_radiance.size(), CV_32FC1); - for (auto y = 0U; y < input_radiance.size().height; ++y) { - for (auto x = 0U; x < input_radiance.size().width; ++x) { + for (auto y = 0; y < input_radiance.size().height; ++y) { + for (auto x = 0; x < input_radiance.size().width; ++x) { lumi.at(y, x) = rgb_to_luminance(input_radiance.at(y, x)[2], input_radiance.at(y, x)[1], input_radiance.at(y, x)[0]); } } - double Lw_bar = 0.0; + auto Lw_bar = 0.0F; // loop over all values in the Mat - for (auto y = 0U; y < input_radiance.size().height; ++y) { - for (auto x = 0U; x < input_radiance.size().width; ++x) { + for (auto y = 0; y < input_radiance.size().height; ++y) { + for (auto x = 0; x < input_radiance.size().width; ++x) { Lw_bar += std::log(lumi.at(y, x) + epsilon); // from paper } } std::cerr << "Lw_bar: " << Lw_bar << std::endl; - const size_t N = input_radiance.total(); + const auto N = static_cast(input_radiance.total()); // Equation 1 in the paper is wrong. The division by N should be placed // before the summation, not outside the exponentiation. Lw_bar = std::exp(Lw_bar / N); - const float coeff = a / Lw_bar; + const auto coeff = a / Lw_bar; - const float L_white = 1.7f; // test + const auto L_white = 1.7F; // test // compute Ld cv::Mat Ld(input_radiance.size(), CV_32FC1); for (auto y = 0; y < input_radiance.size().height; ++y) { for (auto x = 0; x < input_radiance.size().width; ++x) { - float L = coeff * lumi.at(y, x); // Ld = (a / Lw_bar ) * (Lw(x,y)) - Ld.at(y, x) = L * (1.0f + L / (L_white * L_white)) / (1.0f + L); + auto L = coeff * lumi.at(y, x); // Ld = (a / Lw_bar ) * (Lw(x,y)) + Ld.at(y, x) = L * (1.0F + L / (L_white * L_white)) / (1.0F + L); if (L > L_white) { Ld.at(y, x) = 1; @@ -62,7 +62,7 @@ auto reinhard_tone_map_algo(const cv::Mat &input_radiance) noexcept -> cv::Mat { } cv::Mat output_image(input_radiance.size(), CV_8UC3); - for (auto idx = 0U; idx < 3U; ++idx) { // rgb + for (auto idx = 0; idx < 3; ++idx) { // rgb for (auto y = 0; y < input_radiance.size().height; ++y) { for (auto x = 0; x < input_radiance.size().width; ++x) { output_image.at(y, x)[idx] = cv::saturate_cast(