| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "borunov_v_block_partitioning/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <array> | ||
| 5 | #include <cmath> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "borunov_v_block_partitioning/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace borunov_v_block_partitioning { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | BorunovVBlockPartitioningSEQ::BorunovVBlockPartitioningSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | GetInput() = in; |
| 16 | 112 | } | |
| 17 | |||
| 18 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | bool BorunovVBlockPartitioningSEQ::ValidationImpl() { |
| 19 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | if (GetInput().size() < 2) { |
| 20 | return false; | ||
| 21 | } | ||
| 22 | 112 | int w = GetInput()[0]; | |
| 23 | 112 | int h = GetInput()[1]; | |
| 24 | 112 | const std::size_t pixels = static_cast<std::size_t>(w) * static_cast<std::size_t>(h); | |
| 25 | 112 | const std::size_t expected_size = static_cast<std::size_t>(2) + pixels; | |
| 26 | 112 | return GetInput().size() == expected_size; | |
| 27 | } | ||
| 28 | |||
| 29 | 112 | bool BorunovVBlockPartitioningSEQ::PreProcessingImpl() { | |
| 30 | 112 | int w = GetInput()[0]; | |
| 31 | 112 | int h = GetInput()[1]; | |
| 32 | 112 | GetOutput().assign(static_cast<std::size_t>(w) * static_cast<std::size_t>(h), 0); | |
| 33 | 112 | return true; | |
| 34 | } | ||
| 35 | |||
| 36 | 112 | bool BorunovVBlockPartitioningSEQ::RunImpl() { | |
| 37 | 112 | int width = GetInput()[0]; | |
| 38 | 112 | int height = GetInput()[1]; | |
| 39 | 112 | const int *pixels = GetInput().data() + 2; | |
| 40 | |||
| 41 | const std::array<std::array<float, 3>, 3> kernel = {{ | ||
| 42 | {1.0F / 16.0F, 2.0F / 16.0F, 1.0F / 16.0F}, | ||
| 43 | {2.0F / 16.0F, 4.0F / 16.0F, 2.0F / 16.0F}, | ||
| 44 | {1.0F / 16.0F, 2.0F / 16.0F, 1.0F / 16.0F}, | ||
| 45 | }}; | ||
| 46 | |||
| 47 |
2/2✓ Branch 0 taken 7584 times.
✓ Branch 1 taken 112 times.
|
7696 | for (int i = 0; i < height; ++i) { |
| 48 |
2/2✓ Branch 0 taken 1201904 times.
✓ Branch 1 taken 7584 times.
|
1209488 | for (int j = 0; j < width; ++j) { |
| 49 | 1201904 | const int x0 = std::clamp(j - 1, 0, width - 1); | |
| 50 | const int x1 = j; | ||
| 51 | 1201904 | const int x2 = std::clamp(j + 1, 0, width - 1); | |
| 52 | |||
| 53 | 1201904 | const int y0 = std::clamp(i - 1, 0, height - 1); | |
| 54 | const int y1 = i; | ||
| 55 | 1201904 | const int y2 = std::clamp(i + 1, 0, height - 1); | |
| 56 | |||
| 57 | float sum = 0.0F; | ||
| 58 | |||
| 59 | 1201904 | sum += static_cast<float>(pixels[(y0 * width) + x0]) * kernel[0][0]; | |
| 60 | 1201904 | sum += static_cast<float>(pixels[(y0 * width) + x1]) * kernel[0][1]; | |
| 61 | 1201904 | sum += static_cast<float>(pixels[(y0 * width) + x2]) * kernel[0][2]; | |
| 62 | |||
| 63 | 1201904 | sum += static_cast<float>(pixels[(y1 * width) + x0]) * kernel[1][0]; | |
| 64 | 1201904 | sum += static_cast<float>(pixels[(y1 * width) + x1]) * kernel[1][1]; | |
| 65 | 1201904 | sum += static_cast<float>(pixels[(y1 * width) + x2]) * kernel[1][2]; | |
| 66 | |||
| 67 | 1201904 | sum += static_cast<float>(pixels[(y2 * width) + x0]) * kernel[2][0]; | |
| 68 | 1201904 | sum += static_cast<float>(pixels[(y2 * width) + x1]) * kernel[2][1]; | |
| 69 | 1201904 | sum += static_cast<float>(pixels[(y2 * width) + x2]) * kernel[2][2]; | |
| 70 | |||
| 71 | 1201904 | GetOutput()[(i * width) + j] = static_cast<int>(std::round(sum)); | |
| 72 | } | ||
| 73 | } | ||
| 74 | 112 | return true; | |
| 75 | } | ||
| 76 | |||
| 77 | 112 | bool BorunovVBlockPartitioningSEQ::PostProcessingImpl() { | |
| 78 | 112 | return true; | |
| 79 | } | ||
| 80 | |||
| 81 | } // namespace borunov_v_block_partitioning | ||
| 82 |