| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "chaschin_vladimir_linear_image_filtration_seq/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <future> | ||
| 5 | #include <thread> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "chaschin_vladimir_linear_image_filtration_seq/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace { | ||
| 12 | |||
| 13 | 160 | inline void ProcessHorizontalSTL(int thread_idx, int num_threads, int m, int n, const std::vector<float> &image, | |
| 14 | std::vector<float> &temp) { | ||
| 15 |
2/2✓ Branch 0 taken 960 times.
✓ Branch 1 taken 160 times.
|
1120 | for (int yi = thread_idx; yi < m; yi += num_threads) { |
| 16 |
2/2✓ Branch 0 taken 39680 times.
✓ Branch 1 taken 960 times.
|
40640 | for (int xf = 0; xf < n; ++xf) { |
| 17 | 39680 | temp[(yi * n) + xf] = chaschin_v_linear_image_filtration_stl::HorizontalFilterAtSTL(image, n, xf, yi); | |
| 18 | } | ||
| 19 | } | ||
| 20 | 160 | } | |
| 21 | |||
| 22 | 160 | inline void ProcessVerticalSTL(int thread_idx, int num_threads, int m, int n, const std::vector<float> &temp, | |
| 23 | std::vector<float> &out) { | ||
| 24 |
2/2✓ Branch 0 taken 960 times.
✓ Branch 1 taken 160 times.
|
1120 | for (int yi = thread_idx; yi < m; yi += num_threads) { |
| 25 |
2/2✓ Branch 0 taken 39680 times.
✓ Branch 1 taken 960 times.
|
40640 | for (int xy = 0; xy < n; ++xy) { |
| 26 | 39680 | out[(yi * n) + xy] = chaschin_v_linear_image_filtration_stl::VerticalFilterAtSTL(temp, n, m, xy, yi); | |
| 27 | } | ||
| 28 | } | ||
| 29 | 160 | } | |
| 30 | |||
| 31 | } // namespace | ||
| 32 | |||
| 33 | namespace chaschin_v_linear_image_filtration_stl { | ||
| 34 | |||
| 35 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | ChaschinVLinearFiltrationSTL::ChaschinVLinearFiltrationSTL(const chaschin_v_linear_image_filtration_seq::InType &in) { |
| 36 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 37 | auto in_copy = in; | ||
| 38 | GetInput() = std::move(in_copy); | ||
| 39 | this->GetOutput().clear(); | ||
| 40 | 40 | } | |
| 41 | |||
| 42 | 40 | bool ChaschinVLinearFiltrationSTL::ValidationImpl() { | |
| 43 | const auto &in = GetInput(); | ||
| 44 | const auto &image = std::get<0>(in); | ||
| 45 | 40 | return !image.empty(); | |
| 46 | } | ||
| 47 | |||
| 48 | 40 | bool ChaschinVLinearFiltrationSTL::PreProcessingImpl() { | |
| 49 | 40 | return true; | |
| 50 | } | ||
| 51 | |||
| 52 | 39680 | inline float HorizontalFilterAtSTL(const std::vector<float> &img, int n, int x, int y) { | |
| 53 | 39680 | const int idx = (y * n) + x; | |
| 54 |
2/2✓ Branch 0 taken 960 times.
✓ Branch 1 taken 38720 times.
|
39680 | if (x == 0) { |
| 55 | 960 | return ((2.F * img[idx]) + img[idx + 1]) / 3.F; | |
| 56 | } | ||
| 57 |
2/2✓ Branch 0 taken 960 times.
✓ Branch 1 taken 37760 times.
|
38720 | if (x == n - 1) { |
| 58 | 960 | return (img[idx - 1] + (2.F * img[idx])) / 3.F; | |
| 59 | } | ||
| 60 | 37760 | return (img[idx - 1] + (2.F * img[idx]) + img[idx + 1]) / 4.F; | |
| 61 | } | ||
| 62 | |||
| 63 | 39680 | inline float VerticalFilterAtSTL(const std::vector<float> &temp, int n, int m, int x, int y) { | |
| 64 | 39680 | const int idx = (y * n) + x; | |
| 65 |
2/2✓ Branch 0 taken 960 times.
✓ Branch 1 taken 38720 times.
|
39680 | if (y == 0) { |
| 66 | 960 | return ((2.F * temp[idx]) + temp[idx + n]) / 3.F; | |
| 67 | } | ||
| 68 |
2/2✓ Branch 0 taken 960 times.
✓ Branch 1 taken 37760 times.
|
38720 | if (y == m - 1) { |
| 69 | 960 | return (temp[idx - n] + (2.F * temp[idx])) / 3.F; | |
| 70 | } | ||
| 71 | 37760 | return (temp[idx - n] + (2.F * temp[idx]) + temp[idx + n]) / 4.F; | |
| 72 | } | ||
| 73 | |||
| 74 | 40 | bool ChaschinVLinearFiltrationSTL::RunImpl() { | |
| 75 | const auto &in = GetInput(); | ||
| 76 | const auto &image = std::get<0>(in); | ||
| 77 | 40 | int n = std::get<1>(in); | |
| 78 | 40 | int m = std::get<2>(in); | |
| 79 | |||
| 80 | auto &out = GetOutput(); | ||
| 81 | 40 | out.resize(static_cast<size_t>(n) * m); | |
| 82 | |||
| 83 | 40 | std::vector<float> temp(static_cast<size_t>(n) * m); | |
| 84 | |||
| 85 | 40 | unsigned int hardware_threads = std::thread::hardware_concurrency(); | |
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (hardware_threads == 0) { |
| 87 | hardware_threads = 2; | ||
| 88 | } | ||
| 89 | 40 | int num_threads = static_cast<int>(hardware_threads); | |
| 90 | |||
| 91 | { | ||
| 92 | 40 | std::vector<std::future<void>> futures; | |
| 93 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | futures.reserve(static_cast<size_t>(num_threads)); |
| 94 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 40 times.
|
200 | for (int thread_idx = 0; thread_idx < num_threads; ++thread_idx) { |
| 95 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
320 | futures.push_back(std::async(std::launch::async, [thread_idx, num_threads, m, n, &image, &temp]() { |
| 96 | 160 | ProcessHorizontalSTL(thread_idx, num_threads, m, n, image, temp); | |
| 97 | 160 | })); | |
| 98 | } | ||
| 99 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 40 times.
|
200 | for (auto &f : futures) { |
| 100 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | f.wait(); |
| 101 | } | ||
| 102 | 40 | } | |
| 103 | |||
| 104 | { | ||
| 105 | 40 | std::vector<std::future<void>> futures; | |
| 106 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | futures.reserve(static_cast<size_t>(num_threads)); |
| 107 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 40 times.
|
200 | for (int thread_idx = 0; thread_idx < num_threads; ++thread_idx) { |
| 108 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
320 | futures.push_back(std::async(std::launch::async, [thread_idx, num_threads, m, n, &temp, &out]() { |
| 109 | 160 | ProcessVerticalSTL(thread_idx, num_threads, m, n, temp, out); | |
| 110 | 160 | })); | |
| 111 | } | ||
| 112 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 40 times.
|
200 | for (auto &f : futures) { |
| 113 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | f.wait(); |
| 114 | } | ||
| 115 | 40 | } | |
| 116 | |||
| 117 | 40 | return true; | |
| 118 | } | ||
| 119 | |||
| 120 | 40 | bool ChaschinVLinearFiltrationSTL::PostProcessingImpl() { | |
| 121 | 40 | return true; | |
| 122 | } | ||
| 123 | |||
| 124 | } // namespace chaschin_v_linear_image_filtration_stl | ||
| 125 |