| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "rychkova_gauss/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <omp.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <cstdint> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "rychkova_gauss/common/include/common.hpp" | ||
| 11 | #include "util/include/util.hpp" | ||
| 12 | |||
| 13 | namespace rychkova_gauss { | ||
| 14 | |||
| 15 | namespace { | ||
| 16 | int Mirror(int x, int xmin, int xmax) { | ||
| 17 | 56849472 | if (x < xmin) { | |
| 18 | return 1; | ||
| 19 | } | ||
| 20 |
4/4✓ Branch 0 taken 31056 times.
✓ Branch 1 taken 28362624 times.
✓ Branch 2 taken 29124 times.
✓ Branch 3 taken 28366488 times.
|
56789292 | if (x >= xmax) { |
| 21 | 60180 | return xmax - 1; | |
| 22 | } | ||
| 23 | return x; | ||
| 24 | }; | ||
| 25 | |||
| 26 | 3158304 | Pixel ComputePixel(const Image &image, std::size_t x, std::size_t y, std::size_t width, std::size_t height) { | |
| 27 | Pixel result = {.R = 0, .G = 0, .B = 0}; | ||
| 28 |
2/2✓ Branch 0 taken 9474912 times.
✓ Branch 1 taken 3158304 times.
|
12633216 | for (int shift_x = -1; shift_x < 2; shift_x++) { |
| 29 |
2/2✓ Branch 0 taken 28424736 times.
✓ Branch 1 taken 9474912 times.
|
37899648 | for (int shift_y = -1; shift_y < 2; shift_y++) { |
| 30 |
2/2✓ Branch 0 taken 28393680 times.
✓ Branch 1 taken 31056 times.
|
28424736 | int xn = Mirror(static_cast<int>(x) + shift_x, 0, static_cast<int>(width)); |
| 31 |
2/2✓ Branch 0 taken 28395612 times.
✓ Branch 1 taken 29124 times.
|
28424736 | int yn = Mirror(static_cast<int>(y) + shift_y, 0, static_cast<int>(height)); |
| 32 | 28424736 | auto current = image[yn][xn]; | |
| 33 | 28424736 | result.R += static_cast<uint8_t>(static_cast<double>(current.R) * kKernel[shift_x + 1][shift_y + 1]); | |
| 34 | 28424736 | result.G += static_cast<uint8_t>(static_cast<double>(current.G) * kKernel[shift_x + 1][shift_y + 1]); | |
| 35 | 28424736 | result.B += static_cast<uint8_t>(static_cast<double>(current.B) * kKernel[shift_x + 1][shift_y + 1]); | |
| 36 | } | ||
| 37 | } | ||
| 38 | 3158304 | return result; | |
| 39 | } | ||
| 40 | } // namespace | ||
| 41 | |||
| 42 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | RychkovaGaussOMP::RychkovaGaussOMP(const InType &in) { |
| 43 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 44 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | GetInput() = in; |
| 45 | GetOutput() = {}; // cписок инициализации - пустой вектор - каждый вложенный вектор и пиксели внутри по умолчанию | ||
| 46 | 32 | } | |
| 47 | |||
| 48 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | bool RychkovaGaussOMP::ValidationImpl() { |
| 49 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | if (GetInput().empty()) { |
| 50 | return false; | ||
| 51 | } | ||
| 52 | const auto len = GetInput()[0].size(); | ||
| 53 | return std::ranges::all_of(GetInput(), [len](const auto &row) { return row.size() == len; }); | ||
| 54 | } | ||
| 55 | |||
| 56 | 32 | bool RychkovaGaussOMP::PreProcessingImpl() { | |
| 57 | 32 | return true; | |
| 58 | } | ||
| 59 | |||
| 60 | 32 | bool RychkovaGaussOMP::RunImpl() { | |
| 61 | const auto &image = GetInput(); // сохран.изоб. | ||
| 62 | const auto width = image[0].size(); | ||
| 63 | const auto height = image.size(); // сайз от имаге хранит количествo строк | ||
| 64 |
1/2✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
32 | GetOutput() = Image(height, std::vector<Pixel>(width, Pixel(0, 0, 0))); |
| 65 | auto &output = GetOutput(); | ||
| 66 | 32 | #pragma omp parallel for shared(width, height, image, output) default(none) num_threads(ppc::util::GetNumThreads()) | |
| 67 | for (std::size_t j = 0; j < height; j++) { | ||
| 68 | for (std::size_t i = 0; i < width; i++) { | ||
| 69 | output[j][i] = ComputePixel(image, i, j, width, height); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | 32 | return true; | |
| 73 | } | ||
| 74 | |||
| 75 | 32 | bool RychkovaGaussOMP::PostProcessingImpl() { | |
| 76 | 32 | return true; | |
| 77 | } | ||
| 78 | |||
| 79 | } // namespace rychkova_gauss | ||
| 80 |