| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "chaschin_vladimir_linear_image_filtration_seq/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <cstddef> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "chaschin_vladimir_linear_image_filtration_seq/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace chaschin_v_linear_image_filtration_tbb { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | ChaschinVLinearFiltrationTBB::ChaschinVLinearFiltrationTBB(const chaschin_v_linear_image_filtration_seq::InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | auto in_copy = in; | ||
| 16 | GetInput() = std::move(in_copy); | ||
| 17 | this->GetOutput().clear(); | ||
| 18 | 20 | } | |
| 19 | |||
| 20 | 20 | bool ChaschinVLinearFiltrationTBB::ValidationImpl() { | |
| 21 | const auto &in = GetInput(); | ||
| 22 | const auto &image = std::get<0>(in); | ||
| 23 | 20 | return !image.empty(); | |
| 24 | } | ||
| 25 | |||
| 26 | 20 | bool ChaschinVLinearFiltrationTBB::PreProcessingImpl() { | |
| 27 | 20 | return true; | |
| 28 | } | ||
| 29 | |||
| 30 | 21824 | inline float HorizontalFilterAtTBB(const std::vector<float> &img, int n, int x, int y) { | |
| 31 | 21824 | const int idx = (y * n) + x; | |
| 32 |
2/2✓ Branch 0 taken 496 times.
✓ Branch 1 taken 21328 times.
|
21824 | if (x == 0) { |
| 33 | 496 | return ((2.F * img[idx]) + img[idx + 1]) / 3.F; | |
| 34 | } | ||
| 35 |
2/2✓ Branch 0 taken 496 times.
✓ Branch 1 taken 20832 times.
|
21328 | if (x == n - 1) { |
| 36 | 496 | return (img[idx - 1] + (2.F * img[idx])) / 3.F; | |
| 37 | } | ||
| 38 | 20832 | return (img[idx - 1] + (2.F * img[idx]) + img[idx + 1]) / 4.F; | |
| 39 | } | ||
| 40 | |||
| 41 | 21824 | inline float VerticalFilterAtTBB(const std::vector<float> &temp, int n, int m, int x, int y) { | |
| 42 | 21824 | const int idx = (y * n) + x; | |
| 43 |
2/2✓ Branch 0 taken 496 times.
✓ Branch 1 taken 21328 times.
|
21824 | if (y == 0) { |
| 44 | 496 | return ((2.F * temp[idx]) + temp[idx + n]) / 3.F; | |
| 45 | } | ||
| 46 |
2/2✓ Branch 0 taken 496 times.
✓ Branch 1 taken 20832 times.
|
21328 | if (y == m - 1) { |
| 47 | 496 | return (temp[idx - n] + (2.F * temp[idx])) / 3.F; | |
| 48 | } | ||
| 49 | 20832 | return (temp[idx - n] + (2.F * temp[idx]) + temp[idx + n]) / 4.F; | |
| 50 | } | ||
| 51 | |||
| 52 | 20 | bool ChaschinVLinearFiltrationTBB::RunImpl() { | |
| 53 | const auto &in = GetInput(); | ||
| 54 | const auto &image = std::get<0>(in); | ||
| 55 | 20 | int n = std::get<1>(in); | |
| 56 | 20 | int m = std::get<2>(in); | |
| 57 | |||
| 58 | auto &out = GetOutput(); | ||
| 59 | 20 | out.resize(static_cast<size_t>(n) * m); | |
| 60 | |||
| 61 | 20 | std::vector<float> temp(static_cast<size_t>(n) * m); | |
| 62 | |||
| 63 | // ---------- горизонтальная фильтрация ---------- | ||
| 64 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
516 | tbb::parallel_for(tbb::blocked_range<int>(0, m), [&](const tbb::blocked_range<int> &r) { |
| 65 | 992 | for (int yi = r.begin(); yi < r.end(); ++yi) { | |
| 66 |
2/2✓ Branch 0 taken 21824 times.
✓ Branch 1 taken 496 times.
|
22320 | for (int xf = 0; xf < n; ++xf) { |
| 67 | 21824 | temp[(yi * n) + xf] = HorizontalFilterAtTBB(image, n, xf, yi); | |
| 68 | } | ||
| 69 | } | ||
| 70 | 496 | }); | |
| 71 | |||
| 72 | // ---------- вертикальная фильтрация ---------- | ||
| 73 |
2/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
516 | tbb::parallel_for(tbb::blocked_range<int>(0, m), [&](const tbb::blocked_range<int> &r) { |
| 74 |
2/2✓ Branch 0 taken 496 times.
✓ Branch 1 taken 496 times.
|
992 | for (int yi = r.begin(); yi < r.end(); ++yi) { |
| 75 |
2/2✓ Branch 0 taken 21824 times.
✓ Branch 1 taken 496 times.
|
22320 | for (int xy = 0; xy < n; ++xy) { |
| 76 | 21824 | out[(yi * n) + xy] = VerticalFilterAtTBB(temp, n, m, xy, yi); | |
| 77 | } | ||
| 78 | } | ||
| 79 | 496 | }); | |
| 80 | |||
| 81 | 20 | return true; | |
| 82 | } | ||
| 83 | |||
| 84 | 20 | bool ChaschinVLinearFiltrationTBB::PostProcessingImpl() { | |
| 85 | 20 | return true; | |
| 86 | } | ||
| 87 | |||
| 88 | } // namespace chaschin_v_linear_image_filtration_tbb | ||
| 89 |