| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "fedoseev_linear_image_filtering_vertical/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <array> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <thread> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "fedoseev_linear_image_filtering_vertical/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace fedoseev_linear_image_filtering_vertical { | ||
| 12 | |||
| 13 | namespace { | ||
| 14 | int GetPixel(const std::vector<int> &src, int w, int h, int col, int row) { | ||
| 15 | 126432 | col = std::clamp(col, 0, w - 1); | |
| 16 | 126432 | row = std::clamp(row, 0, h - 1); | |
| 17 | 126432 | return src[(static_cast<size_t>(row) * static_cast<size_t>(w)) + static_cast<size_t>(col)]; | |
| 18 | } | ||
| 19 | |||
| 20 | 14048 | int ComputePixel(const std::vector<int> &src, int w, int h, int col, int row, | |
| 21 | const std::array<std::array<int, 3>, 3> &kernel, int kernel_sum) { | ||
| 22 | int sum = 0; | ||
| 23 |
2/2✓ Branch 0 taken 42144 times.
✓ Branch 1 taken 14048 times.
|
56192 | for (int ky = 0; ky < 3; ++ky) { |
| 24 |
2/2✓ Branch 0 taken 126432 times.
✓ Branch 1 taken 42144 times.
|
168576 | for (int kx = 0; kx < 3; ++kx) { |
| 25 | 126432 | int px = col + kx - 1; | |
| 26 | 126432 | int py = row + ky - 1; | |
| 27 | 126432 | sum += GetPixel(src, w, h, px, py) * kernel.at(ky).at(kx); | |
| 28 | } | ||
| 29 | } | ||
| 30 | 14048 | return sum / kernel_sum; | |
| 31 | } | ||
| 32 | |||
| 33 | 160 | void ProcessBlock(const std::vector<int> &src, std::vector<int> &dst, int w, int h, int col_start, int col_end, | |
| 34 | const std::array<std::array<int, 3>, 3> &kernel, int kernel_sum) { | ||
| 35 |
2/2✓ Branch 0 taken 1312 times.
✓ Branch 1 taken 160 times.
|
1472 | for (int row = 0; row < h; ++row) { |
| 36 |
2/2✓ Branch 0 taken 14048 times.
✓ Branch 1 taken 1312 times.
|
15360 | for (int col = col_start; col < col_end; ++col) { |
| 37 | 14048 | dst[(static_cast<size_t>(row) * static_cast<size_t>(w)) + static_cast<size_t>(col)] = | |
| 38 | 14048 | ComputePixel(src, w, h, col, row, kernel, kernel_sum); | |
| 39 | } | ||
| 40 | } | ||
| 41 | 160 | } | |
| 42 | } // namespace | ||
| 43 | |||
| 44 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | LinearImageFilteringVerticalSTL::LinearImageFilteringVerticalSTL(const InType &in) { |
| 45 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 46 | GetInput() = in; | ||
| 47 | 160 | GetOutput() = InType{}; | |
| 48 | 160 | } | |
| 49 | |||
| 50 | 160 | bool LinearImageFilteringVerticalSTL::ValidationImpl() { | |
| 51 | const InType &input = GetInput(); | ||
| 52 |
2/4✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 160 times.
✗ Branch 3 not taken.
|
160 | if (input.width < 3 || input.height < 3) { |
| 53 | return false; | ||
| 54 | } | ||
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 160 times.
|
160 | if (input.data.size() != static_cast<size_t>(input.width) * static_cast<size_t>(input.height)) { |
| 56 | ✗ | return false; | |
| 57 | } | ||
| 58 | return true; | ||
| 59 | } | ||
| 60 | |||
| 61 | 160 | bool LinearImageFilteringVerticalSTL::PreProcessingImpl() { | |
| 62 | const InType &input = GetInput(); | ||
| 63 | 160 | OutType output; | |
| 64 | 160 | output.width = input.width; | |
| 65 | 160 | output.height = input.height; | |
| 66 |
2/6✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 160 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
160 | output.data.resize(static_cast<size_t>(input.width) * static_cast<size_t>(input.height), 0); |
| 67 | GetOutput() = output; | ||
| 68 | 160 | return true; | |
| 69 | } | ||
| 70 | |||
| 71 | 160 | bool LinearImageFilteringVerticalSTL::RunImpl() { | |
| 72 | const InType &input = GetInput(); | ||
| 73 | OutType &output = GetOutput(); | ||
| 74 | |||
| 75 | 160 | int w = input.width; | |
| 76 | 160 | int h = input.height; | |
| 77 | 160 | const std::vector<int> &src = input.data; | |
| 78 | 160 | std::vector<int> &dst = output.data; | |
| 79 | |||
| 80 | 160 | const std::array<std::array<int, 3>, 3> kernel = {{{{1, 2, 1}}, {{2, 4, 2}}, {{1, 2, 1}}}}; | |
| 81 | const int block_width = 64; | ||
| 82 | 160 | const int num_blocks = (w + block_width - 1) / block_width; | |
| 83 | |||
| 84 | 160 | std::vector<std::thread> threads; | |
| 85 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | threads.reserve(static_cast<size_t>(num_blocks)); |
| 86 | |||
| 87 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 160 times.
|
320 | for (int block_idx = 0; block_idx < num_blocks; ++block_idx) { |
| 88 | 160 | int col_start = block_idx * block_width; | |
| 89 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | int col_end = std::min(col_start + block_width, w); |
| 90 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | threads.emplace_back([&src, &dst, w, h, col_start, col_end, &kernel]() { |
| 91 | 160 | ProcessBlock(src, dst, w, h, col_start, col_end, kernel, 16); | |
| 92 | 160 | }); | |
| 93 | } | ||
| 94 | |||
| 95 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 160 times.
|
320 | for (auto &t : threads) { |
| 96 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | t.join(); |
| 97 | } | ||
| 98 | 160 | return true; | |
| 99 | 160 | } | |
| 100 | |||
| 101 | 160 | bool LinearImageFilteringVerticalSTL::PostProcessingImpl() { | |
| 102 | 160 | return true; | |
| 103 | } | ||
| 104 | |||
| 105 | } // namespace fedoseev_linear_image_filtering_vertical | ||
| 106 |