| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "nikolaev_d_block_linear_image_filtering/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/blocked_range2d.h> | ||
| 4 | #include <tbb/parallel_for.h> | ||
| 5 | |||
| 6 | #include <algorithm> | ||
| 7 | #include <array> | ||
| 8 | #include <cstddef> | ||
| 9 | #include <cstdint> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | #include "nikolaev_d_block_linear_image_filtering/common/include/common.hpp" | ||
| 13 | |||
| 14 | namespace nikolaev_d_block_linear_image_filtering { | ||
| 15 | |||
| 16 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | NikolaevDBlockLinearImageFilteringTBB::NikolaevDBlockLinearImageFilteringTBB(const InType &in) { |
| 17 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 18 | GetInput() = in; | ||
| 19 | 20 | GetOutput() = std::vector<uint8_t>(); | |
| 20 | 20 | } | |
| 21 | |||
| 22 | 20 | bool NikolaevDBlockLinearImageFilteringTBB::ValidationImpl() { | |
| 23 | 20 | const auto img_width = get<0>(GetInput()); | |
| 24 | 20 | const auto img_height = get<1>(GetInput()); | |
| 25 | const auto &pixel_data = get<2>(GetInput()); | ||
| 26 | |||
| 27 | 20 | return static_cast<std::size_t>(img_width) * static_cast<std::size_t>(img_height) * 3 == pixel_data.size(); | |
| 28 | } | ||
| 29 | |||
| 30 | 20 | bool NikolaevDBlockLinearImageFilteringTBB::PreProcessingImpl() { | |
| 31 | 20 | return true; | |
| 32 | } | ||
| 33 | |||
| 34 | ✗ | std::uint8_t NikolaevDBlockLinearImageFilteringTBB::GetPixel(const std::vector<uint8_t> &data, int w, int h, int nx, | |
| 35 | int ny, int ch) { | ||
| 36 | 1944 | int ix = std::clamp(nx, 0, w - 1); | |
| 37 | 1944 | int iy = std::clamp(ny, 0, h - 1); | |
| 38 | 1944 | return data[((iy * w + ix) * 3) + ch]; | |
| 39 | } | ||
| 40 | |||
| 41 | 216 | std::uint8_t NikolaevDBlockLinearImageFilteringTBB::ApplyKernel(const std::vector<uint8_t> &src, int w, int h, int nx, | |
| 42 | int ny, int ch) { | ||
| 43 | static constexpr std::array<std::array<int, 3>, 3> kKernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}}; | ||
| 44 | int acc = 0; | ||
| 45 | |||
| 46 |
2/2✓ Branch 0 taken 648 times.
✓ Branch 1 taken 216 times.
|
864 | for (int ky = -1; ky <= 1; ++ky) { |
| 47 |
2/2✓ Branch 0 taken 1944 times.
✓ Branch 1 taken 648 times.
|
2592 | for (int kx = -1; kx <= 1; ++kx) { |
| 48 | 1944 | acc += GetPixel(src, w, h, nx + kx, ny + ky, ch) * kKernel.at(ky + 1).at(kx + 1); | |
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 |
1/2✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
|
216 | return static_cast<uint8_t>(std::clamp((acc + 8) / 16, 0, 255)); |
| 53 | } | ||
| 54 | |||
| 55 | 20 | bool NikolaevDBlockLinearImageFilteringTBB::RunImpl() { | |
| 56 | 20 | const int width = std::get<0>(GetInput()); | |
| 57 | 20 | const int height = std::get<1>(GetInput()); | |
| 58 | const auto &src = std::get<2>(GetInput()); | ||
| 59 | |||
| 60 | auto &dst = GetOutput(); | ||
| 61 | 20 | dst.assign(src.size(), 0); | |
| 62 | |||
| 63 | 92 | tbb::parallel_for(tbb::blocked_range2d<int>(0, height, 0, width), [&](const tbb::blocked_range2d<int> &r) { | |
| 64 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
|
144 | for (int ny = r.rows().begin(); ny < r.rows().end(); ++ny) { |
| 65 | 144 | for (int nx = r.cols().begin(); nx < r.cols().end(); ++nx) { | |
| 66 |
2/2✓ Branch 0 taken 216 times.
✓ Branch 1 taken 72 times.
|
288 | for (int ch = 0; ch < 3; ++ch) { |
| 67 | 216 | dst[((ny * width + nx) * 3) + ch] = ApplyKernel(src, width, height, nx, ny, ch); | |
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | 72 | }); | |
| 72 | |||
| 73 | 20 | return true; | |
| 74 | } | ||
| 75 | |||
| 76 | 20 | bool NikolaevDBlockLinearImageFilteringTBB::PostProcessingImpl() { | |
| 77 | 20 | return true; | |
| 78 | } | ||
| 79 | |||
| 80 | } // namespace nikolaev_d_block_linear_image_filtering | ||
| 81 |