| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "zhurin_i_gauss_kernel_seq/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <utility> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "zhurin_i_gauss_kernel_seq/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace zhurin_i_gauss_kernel_seq { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | ZhurinIGaussKernelSEQ::ZhurinIGaussKernelSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 | GetInput() = in; | ||
| 14 | 48 | GetOutput() = OutType{}; | |
| 15 | 48 | } | |
| 16 | |||
| 17 | 48 | bool ZhurinIGaussKernelSEQ::ValidationImpl() { | |
| 18 | const auto &in = GetInput(); | ||
| 19 | 48 | int w = std::get<0>(in); | |
| 20 | 48 | int h = std::get<1>(in); | |
| 21 | 48 | int parts = std::get<2>(in); | |
| 22 | const auto &img = std::get<3>(in); | ||
| 23 | |||
| 24 |
2/4✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
|
48 | if (w <= 0 || h <= 0 || parts <= 0 || parts > w) { |
| 25 | return false; | ||
| 26 | } | ||
| 27 | if (std::cmp_not_equal(img.size(), h)) { | ||
| 28 | return false; | ||
| 29 | } | ||
| 30 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 48 times.
|
176 | for (int i = 0; i < h; ++i) { |
| 31 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
|
128 | if (std::cmp_not_equal(img[i].size(), w)) { |
| 32 | return false; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | return true; | ||
| 36 | } | ||
| 37 | |||
| 38 | 48 | bool ZhurinIGaussKernelSEQ::PreProcessingImpl() { | |
| 39 | const auto &in = GetInput(); | ||
| 40 | 48 | width_ = std::get<0>(in); | |
| 41 | 48 | height_ = std::get<1>(in); | |
| 42 | 48 | num_parts_ = std::get<2>(in); | |
| 43 | 48 | image_ = std::get<3>(in); | |
| 44 | |||
| 45 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | padded_.assign(height_ + 2, std::vector<int>(width_ + 2, 0)); |
| 46 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 48 times.
|
176 | for (int i = 0; i < height_; ++i) { |
| 47 | 128 | std::copy(image_[i].begin(), image_[i].end(), padded_[i + 1].begin() + 1); | |
| 48 | } | ||
| 49 | |||
| 50 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | result_.assign(height_, std::vector<int>(width_, 0)); |
| 51 | 48 | output_written_ = false; | |
| 52 | 48 | return true; | |
| 53 | } | ||
| 54 | |||
| 55 | 48 | bool ZhurinIGaussKernelSEQ::RunImpl() { | |
| 56 | 48 | int base_width = width_ / num_parts_; | |
| 57 | 48 | int remainder = width_ % num_parts_; | |
| 58 | int x_start = 0; | ||
| 59 | |||
| 60 | 384 | auto convolve_at = [&](int row, int col) -> int { | |
| 61 | int sum = 0; | ||
| 62 | 384 | sum += padded_[row - 1][col - 1] * kKernel[0][0]; | |
| 63 | 384 | sum += padded_[row - 1][col] * kKernel[0][1]; | |
| 64 | 384 | sum += padded_[row - 1][col + 1] * kKernel[0][2]; | |
| 65 | 384 | sum += padded_[row][col - 1] * kKernel[1][0]; | |
| 66 | 384 | sum += padded_[row][col] * kKernel[1][1]; | |
| 67 | 384 | sum += padded_[row][col + 1] * kKernel[1][2]; | |
| 68 | 384 | sum += padded_[row + 1][col - 1] * kKernel[2][0]; | |
| 69 | 384 | sum += padded_[row + 1][col] * kKernel[2][1]; | |
| 70 | 384 | sum += padded_[row + 1][col + 1] * kKernel[2][2]; | |
| 71 | 384 | return sum >> kShift; | |
| 72 | 48 | }; | |
| 73 | |||
| 74 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 48 times.
|
128 | for (int part = 0; part < num_parts_; ++part) { |
| 75 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 8 times.
|
80 | int part_width = base_width + (part < remainder ? 1 : 0); |
| 76 | 80 | int x_end = x_start + part_width; | |
| 77 | |||
| 78 |
2/2✓ Branch 0 taken 248 times.
✓ Branch 1 taken 80 times.
|
328 | for (int i = 1; i <= height_; ++i) { |
| 79 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 248 times.
|
632 | for (int j = x_start + 1; j <= x_end; ++j) { |
| 80 | 384 | result_[i - 1][j - 1] = convolve_at(i, j); | |
| 81 | } | ||
| 82 | } | ||
| 83 | x_start = x_end; | ||
| 84 | } | ||
| 85 | 48 | return true; | |
| 86 | } | ||
| 87 | |||
| 88 | 48 | bool ZhurinIGaussKernelSEQ::PostProcessingImpl() { | |
| 89 | 48 | GetOutput() = result_; | |
| 90 | 48 | output_written_ = true; | |
| 91 | 48 | return true; | |
| 92 | } | ||
| 93 | |||
| 94 | } // namespace zhurin_i_gauss_kernel_seq | ||
| 95 |