| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "belov_e_sobel/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <thread> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "belov_e_sobel/common/include/common.hpp" | ||
| 11 | #include "util/include/util.hpp" | ||
| 12 | |||
| 13 | namespace belov_e_sobel { | ||
| 14 | |||
| 15 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | BelovESobelSTL::BelovESobelSTL(const InType &in) { |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 | GetInput() = in; | ||
| 18 | GetOutput() = in; | ||
| 19 | 16 | } | |
| 20 | |||
| 21 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | bool BelovESobelSTL::ValidationImpl() { |
| 22 |
3/6✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 16 times.
|
16 | return !std::get<0>(GetInput()).empty() && (std::get<1>(GetInput()) > 0) && (std::get<2>(GetInput()) > 0); |
| 23 | } | ||
| 24 | |||
| 25 | 16 | bool BelovESobelSTL::PreProcessingImpl() { | |
| 26 | 16 | return true; | |
| 27 | } | ||
| 28 | |||
| 29 | 16 | bool BelovESobelSTL::RunImpl() { | |
| 30 | const std::vector<uint8_t> &input = std::get<0>(GetInput()); | ||
| 31 | std::vector<uint8_t> &output = std::get<0>(GetOutput()); | ||
| 32 | 16 | int width = std::get<1>(GetInput()); | |
| 33 | 16 | int height = std::get<2>(GetInput()); | |
| 34 | |||
| 35 | auto get_px = [&](int col, int row) -> float { | ||
| 36 | 6628064 | int clamped_x = std::clamp(col, 0, width - 1); | |
| 37 | 6628064 | int clamped_y = std::clamp(row, 0, height - 1); | |
| 38 | 6628064 | return static_cast<float>(input[(static_cast<std::size_t>(clamped_y) * width) + clamped_x]); | |
| 39 | 16 | }; | |
| 40 | |||
| 41 | 16 | int num_threads = ppc::util::GetNumThreads(); | |
| 42 | |||
| 43 | 16 | std::vector<std::thread> threads; | |
| 44 | 16 | int rows_per_thread = height / num_threads; | |
| 45 | |||
| 46 | 40 | auto worker = [&](int start_y, int end_y) { | |
| 47 |
2/2✓ Branch 0 taken 9592 times.
✓ Branch 1 taken 40 times.
|
9632 | for (int row = start_y; row < end_y; ++row) { |
| 48 |
2/2✓ Branch 0 taken 6628064 times.
✓ Branch 1 taken 9592 times.
|
6637656 | for (int col = 0; col < width; ++col) { |
| 49 | 6628064 | float gx = (-1 * get_px(col - 1, row - 1)) + (1 * get_px(col + 1, row - 1)) + (-2 * get_px(col - 1, row)) + | |
| 50 | 6628064 | (2 * get_px(col + 1, row)) + (-1 * get_px(col - 1, row + 1)) + (1 * get_px(col + 1, row + 1)); | |
| 51 | |||
| 52 | 6628064 | float gy = (-1 * get_px(col - 1, row - 1)) - (2 * get_px(col, row - 1)) - (1 * get_px(col + 1, row - 1)) + | |
| 53 | 6628064 | (1 * get_px(col - 1, row + 1)) + (2 * get_px(col, row + 1)) + (1 * get_px(col + 1, row + 1)); | |
| 54 | |||
| 55 | 6628064 | float magnitude = std::sqrt((gx * gx) + (gy * gy)); | |
| 56 | 6628064 | output[(static_cast<std::size_t>(row) * width) + col] = static_cast<uint8_t>(std::min(255.0F, magnitude)); | |
| 57 | } | ||
| 58 | } | ||
| 59 | 56 | }; | |
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 16 times.
|
56 | for (int i = 0; i < num_threads; ++i) { |
| 62 | 40 | int start_y = i * rows_per_thread; | |
| 63 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 16 times.
|
40 | int end_y = (i == num_threads - 1) ? height : start_y + rows_per_thread; |
| 64 | |||
| 65 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | threads.emplace_back(worker, start_y, end_y); |
| 66 | } | ||
| 67 | |||
| 68 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 16 times.
|
56 | for (auto &t : threads) { |
| 69 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | if (t.joinable()) { |
| 70 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | t.join(); |
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | 16 | return true; | |
| 75 | 16 | } | |
| 76 | |||
| 77 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | bool BelovESobelSTL::PostProcessingImpl() { |
| 78 |
3/6✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 16 times.
|
16 | return !std::get<0>(GetOutput()).empty() && (std::get<1>(GetOutput()) > 0) && (std::get<2>(GetOutput()) > 0); |
| 79 | } | ||
| 80 | |||
| 81 | } // namespace belov_e_sobel | ||
| 82 |