| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "otcheskov_s_gauss_filter_vert_split/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <utility> | ||
| 8 | |||
| 9 | #include "otcheskov_s_gauss_filter_vert_split/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace otcheskov_s_gauss_filter_vert_split { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | OtcheskovSGaussFilterVertSplitSEQ::OtcheskovSGaussFilterVertSplitSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 120 | } | |
| 17 | |||
| 18 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 8 times.
|
120 | bool OtcheskovSGaussFilterVertSplitSEQ::ValidationImpl() { |
| 19 | const auto &[metadata, data] = GetInput(); | ||
| 20 | |||
| 21 |
8/8✓ Branch 0 taken 112 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 104 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 96 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 88 times.
|
120 | is_valid_ = !data.empty() && (metadata.height > 0 && metadata.width > 0 && metadata.channels > 0) && |
| 22 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 80 times.
|
88 | (data.size() == metadata.height * metadata.width * metadata.channels); |
| 23 | |||
| 24 | 120 | return is_valid_; | |
| 25 | } | ||
| 26 | |||
| 27 | 120 | bool OtcheskovSGaussFilterVertSplitSEQ::PreProcessingImpl() { | |
| 28 | 120 | return true; | |
| 29 | } | ||
| 30 | |||
| 31 | 120 | bool OtcheskovSGaussFilterVertSplitSEQ::RunImpl() { | |
| 32 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 40 times.
|
120 | if (!is_valid_) { |
| 33 | return false; | ||
| 34 | } | ||
| 35 | |||
| 36 | const auto &[in_meta, in_data] = GetInput(); | ||
| 37 | auto &[out_meta, out_data] = GetOutput(); | ||
| 38 | 80 | out_meta = in_meta; | |
| 39 | 80 | out_data.resize(in_data.size()); | |
| 40 | const auto &[height, width, channels] = in_meta; | ||
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 2152 times.
✓ Branch 1 taken 80 times.
|
2232 | for (size_t row = 0; row < height; ++row) { |
| 43 |
2/2✓ Branch 0 taken 165240 times.
✓ Branch 1 taken 2152 times.
|
167392 | for (size_t col = 0; col < width; ++col) { |
| 44 |
2/2✓ Branch 0 taken 492184 times.
✓ Branch 1 taken 165240 times.
|
657424 | for (size_t ch = 0; ch < channels; ++ch) { |
| 45 | 492184 | size_t out_idx = (((row * width) + col) * channels) + ch; | |
| 46 | 492184 | out_data[out_idx] = ProcessPixel(row, col, ch); | |
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | return true; | ||
| 51 | } | ||
| 52 | |||
| 53 | 492184 | uint8_t OtcheskovSGaussFilterVertSplitSEQ::ProcessPixel(size_t row, size_t col, size_t ch) { | |
| 54 | const auto &[in_meta, in_data] = GetInput(); | ||
| 55 | const auto &[height, width, channels] = in_meta; | ||
| 56 | |||
| 57 | auto mirror_coord = [&](const size_t ¤t, const int &off, const size_t &size) -> size_t { | ||
| 58 | 5906208 | int64_t pos = static_cast<int64_t>(current) + off; | |
| 59 | 5906208 | if (pos < 0) { | |
| 60 | 23328 | return static_cast<size_t>(-pos - 1); | |
| 61 | } | ||
| 62 |
4/4✓ Branch 0 taken 5928 times.
✓ Branch 1 taken 1464696 times.
✓ Branch 2 taken 17400 times.
✓ Branch 3 taken 4394856 times.
|
5882880 | if (std::cmp_greater_equal(static_cast<size_t>(pos), size)) { |
| 63 | 23328 | return (2 * size) - static_cast<size_t>(pos) - 1; | |
| 64 | } | ||
| 65 | return static_cast<size_t>(pos); | ||
| 66 | }; | ||
| 67 | |||
| 68 | double sum = 0.0; | ||
| 69 |
2/2✓ Branch 0 taken 1476552 times.
✓ Branch 1 taken 492184 times.
|
1968736 | for (int dy = 0; dy < 3; ++dy) { |
| 70 |
2/2✓ Branch 0 taken 5928 times.
✓ Branch 1 taken 1470624 times.
|
1476552 | size_t src_y = mirror_coord(row, dy - 1, height); |
| 71 |
2/2✓ Branch 0 taken 4429656 times.
✓ Branch 1 taken 1476552 times.
|
5906208 | for (int dx = 0; dx < 3; ++dx) { |
| 72 |
2/2✓ Branch 0 taken 17400 times.
✓ Branch 1 taken 4412256 times.
|
4429656 | size_t src_x = mirror_coord(col, dx - 1, width); |
| 73 | 4429656 | double weight = kGaussianKernel.at(dy).at(dx); | |
| 74 | 4429656 | size_t src_idx = (((src_y * width) + src_x) * channels) + ch; | |
| 75 | 4429656 | sum += weight * in_data[src_idx]; | |
| 76 | } | ||
| 77 | } | ||
| 78 | 492184 | return static_cast<uint8_t>(std::clamp(std::round(sum), 0.0, 255.0)); | |
| 79 | } | ||
| 80 | |||
| 81 | 120 | bool OtcheskovSGaussFilterVertSplitSEQ::PostProcessingImpl() { | |
| 82 | 120 | return true; | |
| 83 | } | ||
| 84 | |||
| 85 | } // namespace otcheskov_s_gauss_filter_vert_split | ||
| 86 |