| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "rychkova_gauss/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <thread> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "rychkova_gauss/common/include/common.hpp" | ||
| 10 | #include "util/include/util.hpp" | ||
| 11 | |||
| 12 | namespace rychkova_gauss { | ||
| 13 | |||
| 14 | namespace { | ||
| 15 | int Mirror(int x, int xmin, int xmax) { | ||
| 16 | 113698944 | if (x < xmin) { | |
| 17 | return 1; | ||
| 18 | } | ||
| 19 |
4/4✓ Branch 0 taken 62112 times.
✓ Branch 1 taken 56725248 times.
✓ Branch 2 taken 58248 times.
✓ Branch 3 taken 56732976 times.
|
113578584 | if (x >= xmax) { |
| 20 | 120360 | return xmax - 1; | |
| 21 | } | ||
| 22 | return x; | ||
| 23 | }; | ||
| 24 | |||
| 25 | 6316608 | Pixel ComputePixel(const Image &image, std::size_t x, std::size_t y, std::size_t width, std::size_t height) { | |
| 26 | Pixel result = {.R = 0, .G = 0, .B = 0}; | ||
| 27 |
2/2✓ Branch 0 taken 18949824 times.
✓ Branch 1 taken 6316608 times.
|
25266432 | for (int shift_x = -1; shift_x < 2; shift_x++) { |
| 28 |
2/2✓ Branch 0 taken 56849472 times.
✓ Branch 1 taken 18949824 times.
|
75799296 | for (int shift_y = -1; shift_y < 2; shift_y++) { |
| 29 |
2/2✓ Branch 0 taken 56787360 times.
✓ Branch 1 taken 62112 times.
|
56849472 | int xn = Mirror(static_cast<int>(x) + shift_x, 0, static_cast<int>(width)); |
| 30 |
2/2✓ Branch 0 taken 56791224 times.
✓ Branch 1 taken 58248 times.
|
56849472 | int yn = Mirror(static_cast<int>(y) + shift_y, 0, static_cast<int>(height)); |
| 31 | 56849472 | auto current = image[yn][xn]; | |
| 32 | 56849472 | result.R += static_cast<uint8_t>(static_cast<double>(current.R) * kKernel[shift_x + 1][shift_y + 1]); | |
| 33 | 56849472 | result.G += static_cast<uint8_t>(static_cast<double>(current.G) * kKernel[shift_x + 1][shift_y + 1]); | |
| 34 | 56849472 | result.B += static_cast<uint8_t>(static_cast<double>(current.B) * kKernel[shift_x + 1][shift_y + 1]); | |
| 35 | } | ||
| 36 | } | ||
| 37 | 6316608 | return result; | |
| 38 | } | ||
| 39 | } // namespace | ||
| 40 | |||
| 41 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | RychkovaGaussSTL::RychkovaGaussSTL(const InType &in) { |
| 42 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 43 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | GetInput() = in; |
| 44 | GetOutput() = {}; // cписок инициализации - пустой вектор - каждый вложенный вектор и пиксели внутри по умолчанию | ||
| 45 | 64 | } | |
| 46 | |||
| 47 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | bool RychkovaGaussSTL::ValidationImpl() { |
| 48 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | if (GetInput().empty()) { |
| 49 | return false; | ||
| 50 | } | ||
| 51 | const auto len = GetInput()[0].size(); | ||
| 52 | return std::ranges::all_of(GetInput(), [len](const auto &row) { return row.size() == len; }); | ||
| 53 | } | ||
| 54 | |||
| 55 | 64 | bool RychkovaGaussSTL::PreProcessingImpl() { | |
| 56 | 64 | return true; | |
| 57 | } | ||
| 58 | |||
| 59 | 64 | bool RychkovaGaussSTL::RunImpl() { | |
| 60 | const auto &image = GetInput(); // сохран.изоб. | ||
| 61 | 64 | const auto width = image[0].size(); | |
| 62 | 64 | const auto height = image.size(); // сайз от имаге хранит количествo строк | |
| 63 |
1/2✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
|
64 | GetOutput() = Image(height, std::vector<Pixel>(width, Pixel(0, 0, 0))); |
| 64 | 64 | auto n = ppc::util::GetNumThreads(); | |
| 65 | 64 | std::vector<std::thread> threads; | |
| 66 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | threads.reserve(n); |
| 67 | 64 | size_t row_per_thread = height / n; | |
| 68 | 64 | size_t remainder = height % n; | |
| 69 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 64 times.
|
224 | for (int i = 0; i < n; i++) { |
| 70 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | size_t start = (i * row_per_thread) + std::min(static_cast<int>(remainder), i); |
| 71 | 160 | size_t end = ((i + 1) * row_per_thread) + std::min(static_cast<int>(remainder), i + 1); | |
| 72 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | threads.emplace_back([&](size_t start, size_t end) { |
| 73 |
2/2✓ Branch 0 taken 20704 times.
✓ Branch 1 taken 160 times.
|
20864 | for (std::size_t j = start; j < end; j++) { |
| 74 |
2/2✓ Branch 0 taken 6316608 times.
✓ Branch 1 taken 20704 times.
|
6337312 | for (std::size_t i = 0; i < width; i++) { |
| 75 | 6316608 | GetOutput()[j][i] = ComputePixel(image, i, j, width, height); | |
| 76 | } | ||
| 77 | } | ||
| 78 | 160 | }, start, end); | |
| 79 | } | ||
| 80 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 64 times.
|
224 | for (auto &thread : threads) { |
| 81 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | thread.join(); |
| 82 | } | ||
| 83 | 64 | return true; | |
| 84 | 64 | } | |
| 85 | |||
| 86 | 64 | bool RychkovaGaussSTL::PostProcessingImpl() { | |
| 87 | 64 | return true; | |
| 88 | } | ||
| 89 | |||
| 90 | } // namespace rychkova_gauss | ||
| 91 |