| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "shakirova_e_sobel_edge_detection/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <thread> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "shakirova_e_sobel_edge_detection/common/include/common.hpp" | ||
| 10 | #include "util/include/util.hpp" | ||
| 11 | |||
| 12 | namespace shakirova_e_sobel_edge_detection { | ||
| 13 | |||
| 14 | namespace { | ||
| 15 | |||
| 16 | 120 | void ProcessRows(const int *inp, int *out, int w, int row_begin, int row_end) { | |
| 17 |
2/2✓ Branch 0 taken 12488 times.
✓ Branch 1 taken 120 times.
|
12608 | for (int row = row_begin; row < row_end; ++row) { |
| 18 | 12488 | const int *prev = inp + static_cast<ptrdiff_t>((row - 1) * w); | |
| 19 | 12488 | const int *curr = inp + static_cast<ptrdiff_t>((row)*w); | |
| 20 | 12488 | const int *next = inp + static_cast<ptrdiff_t>((row + 1) * w); | |
| 21 | int *out_row = out + static_cast<ptrdiff_t>((row)*w); | ||
| 22 | |||
| 23 |
2/2✓ Branch 0 taken 6516712 times.
✓ Branch 1 taken 12488 times.
|
6529200 | for (int col = 1; col < w - 1; ++col) { |
| 24 | 6516712 | const int gx = | |
| 25 | 6516712 | -prev[col - 1] + prev[col + 1] - (2 * curr[col - 1]) + (2 * curr[col + 1]) - next[col - 1] + next[col + 1]; | |
| 26 | 6516712 | const int gy = -prev[col - 1] - (2 * prev[col]) - prev[col + 1] + next[col - 1] + (2 * next[col]) + next[col + 1]; | |
| 27 | |||
| 28 | 6516712 | const int agx = std::abs(gx); | |
| 29 | 6516712 | const int agy = std::abs(gy); | |
| 30 | 6516712 | const int magnitude = (((std::max(agx, agy) * 123) + (std::min(agx, agy) * 51)) >> 7); | |
| 31 | 6516712 | out_row[col] = magnitude > 255 ? 255 : magnitude; | |
| 32 | } | ||
| 33 | } | ||
| 34 | 120 | } | |
| 35 | |||
| 36 | } // namespace | ||
| 37 | |||
| 38 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | ShakirovaESobelEdgeDetectionSTL::ShakirovaESobelEdgeDetectionSTL(const InType &in) { |
| 39 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 40 | GetInput() = in; | ||
| 41 | GetOutput().clear(); | ||
| 42 | 48 | } | |
| 43 | |||
| 44 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | bool ShakirovaESobelEdgeDetectionSTL::ValidationImpl() { |
| 45 | 48 | return GetInput().IsValid(); | |
| 46 | } | ||
| 47 | |||
| 48 | 48 | bool ShakirovaESobelEdgeDetectionSTL::PreProcessingImpl() { | |
| 49 | const auto &img = GetInput(); | ||
| 50 | 48 | GetOutput().assign(static_cast<size_t>(img.width) * static_cast<size_t>(img.height), 0); | |
| 51 | 48 | return true; | |
| 52 | } | ||
| 53 | |||
| 54 | 48 | bool ShakirovaESobelEdgeDetectionSTL::RunImpl() { | |
| 55 | const auto &img = GetInput(); | ||
| 56 | 48 | const int h = img.height; | |
| 57 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | const int w = img.width; |
| 58 | const int *inp = img.pixels.data(); | ||
| 59 | int *out = GetOutput().data(); | ||
| 60 | |||
| 61 | 48 | const int inner_rows = h - 2; | |
| 62 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (inner_rows <= 0) { |
| 63 | return true; | ||
| 64 | } | ||
| 65 | |||
| 66 | 48 | const int num_t = ppc::util::GetNumThreads(); | |
| 67 | 48 | std::vector<std::thread> threads; | |
| 68 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | threads.reserve(static_cast<size_t>(num_t)); |
| 69 | |||
| 70 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 48 times.
|
168 | for (int tid = 0; tid < num_t; ++tid) { |
| 71 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | threads.emplace_back([inp, out, w, inner_rows, num_t, tid]() { |
| 72 | 120 | const int chunk = inner_rows / num_t; | |
| 73 | 120 | const int row_begin = (tid * chunk) + 1; | |
| 74 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 72 times.
|
120 | const int row_end = (tid == num_t - 1) ? (inner_rows + 1) : (row_begin + chunk); |
| 75 | 120 | ProcessRows(inp, out, w, row_begin, row_end); | |
| 76 | 120 | }); | |
| 77 | } | ||
| 78 | |||
| 79 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 48 times.
|
168 | for (auto &th : threads) { |
| 80 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | th.join(); |
| 81 | } | ||
| 82 | |||
| 83 | return true; | ||
| 84 | 48 | } | |
| 85 | |||
| 86 | 48 | bool ShakirovaESobelEdgeDetectionSTL::PostProcessingImpl() { | |
| 87 | 48 | return true; | |
| 88 | } | ||
| 89 | |||
| 90 | } // namespace shakirova_e_sobel_edge_detection | ||
| 91 |