| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "fedoseev_linear_image_filtering_vertical/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/blocked_range.h> | ||
| 4 | #include <tbb/parallel_for.h> | ||
| 5 | |||
| 6 | #include <algorithm> | ||
| 7 | #include <array> | ||
| 8 | #include <cstddef> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "fedoseev_linear_image_filtering_vertical/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace fedoseev_linear_image_filtering_vertical { | ||
| 14 | |||
| 15 | namespace { | ||
| 16 | int GetPixel(const std::vector<int> &src, int w, int h, int col, int row) { | ||
| 17 | 63216 | col = std::clamp(col, 0, w - 1); | |
| 18 | 63216 | row = std::clamp(row, 0, h - 1); | |
| 19 | 63216 | return src[(static_cast<size_t>(row) * static_cast<size_t>(w)) + static_cast<size_t>(col)]; | |
| 20 | } | ||
| 21 | } // namespace | ||
| 22 | |||
| 23 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | LinearImageFilteringVerticalTBB::LinearImageFilteringVerticalTBB(const InType &in) { |
| 24 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 25 | GetInput() = in; | ||
| 26 | 80 | GetOutput() = InType{}; | |
| 27 | 80 | } | |
| 28 | |||
| 29 | 80 | bool LinearImageFilteringVerticalTBB::ValidationImpl() { | |
| 30 | const InType &input = GetInput(); | ||
| 31 |
2/4✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
|
80 | if (input.width < 3 || input.height < 3) { |
| 32 | return false; | ||
| 33 | } | ||
| 34 | 80 | return input.data.size() == static_cast<size_t>(input.width) * static_cast<size_t>(input.height); | |
| 35 | } | ||
| 36 | |||
| 37 | 80 | bool LinearImageFilteringVerticalTBB::PreProcessingImpl() { | |
| 38 | const InType &input = GetInput(); | ||
| 39 | 80 | OutType output; | |
| 40 | 80 | output.width = input.width; | |
| 41 | 80 | output.height = input.height; | |
| 42 |
2/6✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
80 | output.data.resize(static_cast<size_t>(input.width) * static_cast<size_t>(input.height), 0); |
| 43 | GetOutput() = output; | ||
| 44 | 80 | return true; | |
| 45 | } | ||
| 46 | |||
| 47 | 80 | bool LinearImageFilteringVerticalTBB::RunImpl() { | |
| 48 | const InType &input = GetInput(); | ||
| 49 | OutType &output = GetOutput(); | ||
| 50 | |||
| 51 | 80 | int w = input.width; | |
| 52 | 80 | int h = input.height; | |
| 53 | 80 | const std::vector<int> &src = input.data; | |
| 54 | 80 | std::vector<int> &dst = output.data; | |
| 55 | |||
| 56 | 80 | const std::array<std::array<int, 3>, 3> kernel = {{{{1, 2, 1}}, {{2, 4, 2}}, {{1, 2, 1}}}}; | |
| 57 | const int kernel_sum = 16; | ||
| 58 | const int block_width = 64; | ||
| 59 | |||
| 60 | 80 | tbb::parallel_for(tbb::blocked_range<int>(0, w, block_width), [&](const tbb::blocked_range<int> &range) { | |
| 61 |
2/2✓ Branch 0 taken 656 times.
✓ Branch 1 taken 80 times.
|
736 | for (int row = 0; row < h; ++row) { |
| 62 |
2/2✓ Branch 0 taken 7024 times.
✓ Branch 1 taken 656 times.
|
7680 | for (int col = range.begin(); col != range.end(); ++col) { |
| 63 | int sum = 0; | ||
| 64 |
2/2✓ Branch 0 taken 21072 times.
✓ Branch 1 taken 7024 times.
|
28096 | for (int ky = 0; ky < 3; ++ky) { |
| 65 |
2/2✓ Branch 0 taken 63216 times.
✓ Branch 1 taken 21072 times.
|
84288 | for (int kx = 0; kx < 3; ++kx) { |
| 66 | 63216 | int px = col + kx - 1; | |
| 67 | 63216 | int py = row + ky - 1; | |
| 68 | 63216 | sum += GetPixel(src, w, h, px, py) * kernel.at(ky).at(kx); | |
| 69 | } | ||
| 70 | } | ||
| 71 | 7024 | dst[(static_cast<size_t>(row) * static_cast<size_t>(w)) + static_cast<size_t>(col)] = sum / kernel_sum; | |
| 72 | } | ||
| 73 | } | ||
| 74 | 80 | }); | |
| 75 | |||
| 76 | 80 | return true; | |
| 77 | } | ||
| 78 | |||
| 79 | 80 | bool LinearImageFilteringVerticalTBB::PostProcessingImpl() { | |
| 80 | 80 | return true; | |
| 81 | } | ||
| 82 | |||
| 83 | } // namespace fedoseev_linear_image_filtering_vertical | ||
| 84 |