| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "kolotukhin_a_gaussian_blur/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <omp.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <array> | ||
| 7 | #include <cstddef> | ||
| 8 | #include <cstdint> | ||
| 9 | #include <tuple> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | #include "kolotukhin_a_gaussian_blur/common/include/common.hpp" | ||
| 13 | |||
| 14 | namespace kolotukhin_a_gaussian_blur { | ||
| 15 | |||
| 16 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | KolotukhinAGaussinBlureOMP::KolotukhinAGaussinBlureOMP(const InType &in) { |
| 17 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 18 | GetInput() = in; | ||
| 19 | GetOutput().clear(); | ||
| 20 | 16 | } | |
| 21 | |||
| 22 | 16 | bool KolotukhinAGaussinBlureOMP::ValidationImpl() { | |
| 23 | const auto &pixel_data = std::get<0>(GetInput()); | ||
| 24 | 16 | const auto img_width = std::get<1>(GetInput()); | |
| 25 | 16 | const auto img_height = std::get<2>(GetInput()); | |
| 26 | |||
| 27 | 16 | return static_cast<std::size_t>(img_height) * static_cast<std::size_t>(img_width) == pixel_data.size(); | |
| 28 | } | ||
| 29 | |||
| 30 | 16 | bool KolotukhinAGaussinBlureOMP::PreProcessingImpl() { | |
| 31 | 16 | const auto img_width = std::get<1>(GetInput()); | |
| 32 | 16 | const auto img_height = std::get<2>(GetInput()); | |
| 33 | |||
| 34 | 16 | GetOutput().assign(static_cast<std::size_t>(img_height) * static_cast<std::size_t>(img_width), 0); | |
| 35 | 16 | return true; | |
| 36 | } | ||
| 37 | |||
| 38 | 16 | bool KolotukhinAGaussinBlureOMP::RunImpl() { | |
| 39 | const auto &pixel_data = std::get<0>(GetInput()); | ||
| 40 | 16 | const auto img_width = std::get<1>(GetInput()); | |
| 41 | 16 | const auto img_height = std::get<2>(GetInput()); | |
| 42 | |||
| 43 | const static std::array<int, 9> kKernel = {1, 2, 1, 2, 4, 2, 1, 2, 1}; | ||
| 44 | const static int kSum = 16; | ||
| 45 | |||
| 46 | auto &output = GetOutput(); | ||
| 47 | |||
| 48 | 16 | #pragma omp parallel for collapse(2) schedule(static) default(none) \ | |
| 49 | shared(pixel_data, img_width, img_height, output, kKernel, kSum) | ||
| 50 | for (int row = 0; row < img_height; row++) { | ||
| 51 | for (int col = 0; col < img_width; col++) { | ||
| 52 | int acc = 0; | ||
| 53 | for (int dy = -1; dy <= 1; dy++) { | ||
| 54 | for (int dx = -1; dx <= 1; dx++) { | ||
| 55 | std::uint8_t pixel = GetPixel(pixel_data, img_width, img_height, col + dx, row + dy); | ||
| 56 | int idx = ((dy + 1) * 3) + (dx + 1); | ||
| 57 | acc += kKernel.at(idx) * static_cast<int>(pixel); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | output[(static_cast<std::size_t>(row) * static_cast<std::size_t>(img_width)) + static_cast<std::size_t>(col)] = | ||
| 61 | static_cast<std::uint8_t>(acc / kSum); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | 16 | return true; | |
| 65 | } | ||
| 66 | |||
| 67 | 1404 | std::uint8_t KolotukhinAGaussinBlureOMP::GetPixel(const std::vector<std::uint8_t> &pixel_data, int img_width, | |
| 68 | int img_height, int pos_x, int pos_y) { | ||
| 69 |
4/4✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1260 times.
✓ Branch 2 taken 972 times.
✓ Branch 3 taken 432 times.
|
1548 | std::size_t x = static_cast<std::size_t>(std::max(0, std::min(pos_x, img_width - 1))); |
| 70 |
4/4✓ Branch 0 taken 156 times.
✓ Branch 1 taken 1248 times.
✓ Branch 2 taken 936 times.
✓ Branch 3 taken 468 times.
|
1560 | std::size_t y = static_cast<std::size_t>(std::max(0, std::min(pos_y, img_height - 1))); |
| 71 | 1404 | return pixel_data[(y * static_cast<std::size_t>(img_width)) + x]; | |
| 72 | } | ||
| 73 | |||
| 74 | 16 | bool KolotukhinAGaussinBlureOMP::PostProcessingImpl() { | |
| 75 | 16 | return true; | |
| 76 | } | ||
| 77 | |||
| 78 | } // namespace kolotukhin_a_gaussian_blur | ||
| 79 |