| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "nikolaev_d_block_linear_image_filtering/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <array> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "nikolaev_d_block_linear_image_filtering/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace nikolaev_d_block_linear_image_filtering { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | NikolaevDBlockLinearImageFilteringSEQ::NikolaevDBlockLinearImageFilteringSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 40 | GetOutput() = std::vector<uint8_t>(); | |
| 17 | 40 | } | |
| 18 | |||
| 19 | 40 | bool NikolaevDBlockLinearImageFilteringSEQ::ValidationImpl() { | |
| 20 | 40 | const auto img_width = get<0>(GetInput()); | |
| 21 | 40 | const auto img_height = get<1>(GetInput()); | |
| 22 | const auto &pixel_data = get<2>(GetInput()); | ||
| 23 | |||
| 24 | 40 | return static_cast<std::size_t>(img_width) * static_cast<std::size_t>(img_height) * 3 == pixel_data.size(); | |
| 25 | } | ||
| 26 | |||
| 27 | 40 | bool NikolaevDBlockLinearImageFilteringSEQ::PreProcessingImpl() { | |
| 28 | 40 | return true; | |
| 29 | } | ||
| 30 | |||
| 31 | ✗ | std::uint8_t NikolaevDBlockLinearImageFilteringSEQ::GetPixel(const std::vector<uint8_t> &data, int w, int h, int nx, | |
| 32 | int ny, int ch) { | ||
| 33 | 3888 | int ix = std::clamp(nx, 0, w - 1); | |
| 34 | 3888 | int iy = std::clamp(ny, 0, h - 1); | |
| 35 | 3888 | return data[((iy * w + ix) * 3) + ch]; | |
| 36 | } | ||
| 37 | |||
| 38 | 40 | bool NikolaevDBlockLinearImageFilteringSEQ::RunImpl() { | |
| 39 | 40 | const int width = std::get<0>(GetInput()); | |
| 40 | 40 | const int height = std::get<1>(GetInput()); | |
| 41 | const auto &src = std::get<2>(GetInput()); | ||
| 42 | |||
| 43 | auto &dst = GetOutput(); | ||
| 44 | 40 | dst.assign(src.size(), 0); | |
| 45 | |||
| 46 | 40 | const std::array<std::array<int, 3>, 3> kernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}}; | |
| 47 | const int sum = 16; | ||
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 40 times.
|
104 | for (int ny = 0; ny < height; ++ny) { |
| 50 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 64 times.
|
208 | for (int nx = 0; nx < width; ++nx) { |
| 51 |
2/2✓ Branch 0 taken 432 times.
✓ Branch 1 taken 144 times.
|
576 | for (int ch = 0; ch < 3; ++ch) { |
| 52 | int acc = 0; | ||
| 53 |
2/2✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 432 times.
|
1728 | for (int ky = -1; ky <= 1; ++ky) { |
| 54 |
2/2✓ Branch 0 taken 3888 times.
✓ Branch 1 taken 1296 times.
|
5184 | for (int kx = -1; kx <= 1; ++kx) { |
| 55 | 3888 | acc += GetPixel(src, width, height, nx + kx, ny + ky, ch) * kernel.at(ky + 1).at(kx + 1); | |
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 |
1/2✓ Branch 0 taken 432 times.
✗ Branch 1 not taken.
|
432 | int res = (acc + 8) / sum; |
| 60 | 432 | dst[((ny * width + nx) * 3) + ch] = static_cast<uint8_t>(std::clamp(res, 0, 255)); | |
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | 40 | return true; | |
| 65 | } | ||
| 66 | |||
| 67 | 40 | bool NikolaevDBlockLinearImageFilteringSEQ::PostProcessingImpl() { | |
| 68 | 40 | return true; | |
| 69 | } | ||
| 70 | |||
| 71 | } // namespace nikolaev_d_block_linear_image_filtering | ||
| 72 |