| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "iskhakov_d_vertical_gauss_filter/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <array> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <thread> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "iskhakov_d_vertical_gauss_filter/common/include/common.hpp" | ||
| 12 | #include "util/include/util.hpp" | ||
| 13 | |||
| 14 | namespace iskhakov_d_vertical_gauss_filter { | ||
| 15 | |||
| 16 | namespace { | ||
| 17 | const int kDivConst = 16; | ||
| 18 | const std::array<std::array<int, 3>, 3> kGaussKernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}}; | ||
| 19 | |||
| 20 | uint8_t IskhakovDGetPixelMirrorSTL(const std::vector<uint8_t> &src, int col, int row, int width, int height) { | ||
| 21 | 2808 | if (col < 0) { | |
| 22 | ✗ | col = -col - 1; | |
| 23 |
12/18✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 312 times.
✓ Branch 4 taken 104 times.
✓ Branch 5 taken 208 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 208 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 312 times.
✓ Branch 10 taken 104 times.
✓ Branch 11 taken 208 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 208 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 312 times.
✓ Branch 16 taken 104 times.
✓ Branch 17 taken 208 times.
|
2496 | } else if (col >= width) { |
| 24 | 312 | col = (2 * width) - col - 1; | |
| 25 | } | ||
| 26 | 936 | if (row < 0) { | |
| 27 | row = -row - 1; | ||
| 28 |
6/6✓ Branch 0 taken 104 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 104 times.
✓ Branch 3 taken 208 times.
✓ Branch 4 taken 104 times.
✓ Branch 5 taken 208 times.
|
936 | } else if (row >= height) { |
| 29 | 312 | row = (2 * height) - row - 1; | |
| 30 | } | ||
| 31 |
10/16✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 312 times.
✓ Branch 4 taken 104 times.
✓ Branch 5 taken 208 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 312 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 312 times.
✓ Branch 10 taken 104 times.
✓ Branch 11 taken 208 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 312 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 312 times.
|
2808 | return src[(row * width) + col]; |
| 32 | } | ||
| 33 | |||
| 34 | } // namespace | ||
| 35 | |||
| 36 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | IskhakovDVerticalGaussFilterSTL::IskhakovDVerticalGaussFilterSTL(const InType &in) { |
| 37 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 38 | GetInput() = in; | ||
| 39 | 40 | GetOutput() = OutType{}; | |
| 40 | 40 | } | |
| 41 | |||
| 42 | 40 | bool IskhakovDVerticalGaussFilterSTL::ValidationImpl() { | |
| 43 | const auto &in = GetInput(); | ||
| 44 |
2/4✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
40 | if (in.width <= 0 || in.height <= 0) { |
| 45 | return false; | ||
| 46 | } | ||
| 47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (in.data.size() != static_cast<size_t>(in.width) * static_cast<size_t>(in.height)) { |
| 48 | ✗ | return false; | |
| 49 | } | ||
| 50 | return true; | ||
| 51 | } | ||
| 52 | |||
| 53 | 40 | bool IskhakovDVerticalGaussFilterSTL::PreProcessingImpl() { | |
| 54 | 40 | return true; | |
| 55 | } | ||
| 56 | |||
| 57 | 40 | bool IskhakovDVerticalGaussFilterSTL::RunImpl() { | |
| 58 | const auto &in = GetInput(); | ||
| 59 | |||
| 60 | 40 | int width = in.width; | |
| 61 | 40 | int height = in.height; | |
| 62 | 40 | const std::vector<uint8_t> &matrix = in.data; | |
| 63 | 40 | std::vector<uint8_t> result(static_cast<size_t>(width) * static_cast<size_t>(height)); | |
| 64 | |||
| 65 |
2/4✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
|
40 | const int num_threads = ppc::util::GetNumThreads(); |
| 66 | const int actual_threads = std::min(num_threads, width); | ||
| 67 | 40 | std::vector<std::thread> threads; | |
| 68 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | threads.reserve(actual_threads); |
| 69 | |||
| 70 | 40 | const int cols_per_thread = width / actual_threads; | |
| 71 | 40 | const int remainder = width % actual_threads; | |
| 72 | int start_col = 0; | ||
| 73 | |||
| 74 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 40 times.
|
118 | for (int thread_id = 0; thread_id < actual_threads; ++thread_id) { |
| 75 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 6 times.
|
78 | int end_col = start_col + cols_per_thread + (thread_id < remainder ? 1 : 0); |
| 76 |
1/2✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
|
78 | threads.emplace_back([&, start_col, end_col]() { |
| 77 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 78 times.
|
182 | for (int horizontal_band = start_col; horizontal_band < end_col; ++horizontal_band) { |
| 78 |
2/2✓ Branch 0 taken 312 times.
✓ Branch 1 taken 104 times.
|
416 | for (int vertical_band = 0; vertical_band < height; ++vertical_band) { |
| 79 | int sum = 0; | ||
| 80 | |||
| 81 | sum += kGaussKernel[0][0] * | ||
| 82 |
3/4✓ Branch 0 taken 104 times.
✓ Branch 1 taken 208 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 312 times.
|
624 | IskhakovDGetPixelMirrorSTL(matrix, horizontal_band - 1, vertical_band - 1, width, height); |
| 83 | 312 | sum += kGaussKernel[0][1] * | |
| 84 | 312 | IskhakovDGetPixelMirrorSTL(matrix, horizontal_band, vertical_band - 1, width, height); | |
| 85 | 312 | sum += kGaussKernel[0][2] * | |
| 86 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
✓ Branch 2 taken 104 times.
✓ Branch 3 taken 208 times.
|
624 | IskhakovDGetPixelMirrorSTL(matrix, horizontal_band + 1, vertical_band - 1, width, height); |
| 87 | |||
| 88 | 312 | sum += kGaussKernel[1][0] * | |
| 89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
|
312 | IskhakovDGetPixelMirrorSTL(matrix, horizontal_band - 1, vertical_band, width, height); |
| 90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
|
312 | sum += kGaussKernel[1][1] * IskhakovDGetPixelMirrorSTL(matrix, horizontal_band, vertical_band, width, height); |
| 91 | 312 | sum += kGaussKernel[1][2] * | |
| 92 | 312 | IskhakovDGetPixelMirrorSTL(matrix, horizontal_band + 1, vertical_band, width, height); | |
| 93 | |||
| 94 | 312 | sum += kGaussKernel[2][0] * | |
| 95 |
3/4✓ Branch 0 taken 104 times.
✓ Branch 1 taken 208 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 312 times.
|
624 | IskhakovDGetPixelMirrorSTL(matrix, horizontal_band - 1, vertical_band + 1, width, height); |
| 96 | 312 | sum += kGaussKernel[2][1] * | |
| 97 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
|
312 | IskhakovDGetPixelMirrorSTL(matrix, horizontal_band, vertical_band + 1, width, height); |
| 98 | 312 | sum += kGaussKernel[2][2] * | |
| 99 | 312 | IskhakovDGetPixelMirrorSTL(matrix, horizontal_band + 1, vertical_band + 1, width, height); | |
| 100 | |||
| 101 | 312 | result[(vertical_band * width) + horizontal_band] = static_cast<uint8_t>(sum / kDivConst); | |
| 102 | } | ||
| 103 | } | ||
| 104 | 78 | }); | |
| 105 | start_col = end_col; | ||
| 106 | } | ||
| 107 | |||
| 108 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 40 times.
|
118 | for (auto &th : threads) { |
| 109 |
1/2✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
|
78 | th.join(); |
| 110 | } | ||
| 111 | |||
| 112 | 40 | GetOutput().width = width; | |
| 113 | 40 | GetOutput().height = height; | |
| 114 | 40 | GetOutput().data = std::move(result); | |
| 115 | 40 | return true; | |
| 116 | 40 | } | |
| 117 | |||
| 118 | 40 | bool IskhakovDVerticalGaussFilterSTL::PostProcessingImpl() { | |
| 119 | 40 | return true; | |
| 120 | } | ||
| 121 | |||
| 122 | } // namespace iskhakov_d_vertical_gauss_filter | ||
| 123 |