| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gutyansky_a_img_contrast_incr/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <limits> | ||
| 8 | #include <utility> | ||
| 9 | |||
| 10 | #include "gutyansky_a_img_contrast_incr/common/include/common.hpp" | ||
| 11 | #include "oneapi/tbb/blocked_range.h" | ||
| 12 | #include "oneapi/tbb/parallel_for.h" | ||
| 13 | |||
| 14 | namespace gutyansky_a_img_contrast_incr { | ||
| 15 | |||
| 16 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GutyanskyAImgContrastIncrTBB::GutyanskyAImgContrastIncrTBB(const InType &in) { |
| 17 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 18 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetInput() = in; |
| 19 | GetOutput() = {}; | ||
| 20 | 40 | } | |
| 21 | |||
| 22 | 40 | bool GutyanskyAImgContrastIncrTBB::ValidationImpl() { | |
| 23 | 40 | return !GetInput().empty(); | |
| 24 | } | ||
| 25 | |||
| 26 | 40 | bool GutyanskyAImgContrastIncrTBB::PreProcessingImpl() { | |
| 27 | 40 | GetOutput().resize(GetInput().size()); | |
| 28 | 40 | return true; | |
| 29 | } | ||
| 30 | |||
| 31 | 40 | bool GutyanskyAImgContrastIncrTBB::RunImpl() { | |
| 32 | const auto &input = GetInput(); | ||
| 33 | auto &output = GetOutput(); | ||
| 34 | |||
| 35 | const size_t sz = input.size(); | ||
| 36 | 40 | auto [lower_bound, upper_bound] = tbb::parallel_reduce( | |
| 37 | 80 | tbb::blocked_range<size_t>(0, sz), std::make_pair(static_cast<uint8_t>(255), static_cast<uint8_t>(0)), | |
| 38 | 188 | [&input](const auto &range, auto init) { | |
| 39 | auto [local_min, local_max] = init; | ||
| 40 |
2/2✓ Branch 0 taken 148 times.
✓ Branch 1 taken 148 times.
|
296 | for (size_t i = range.begin(); i != range.end(); ++i) { |
| 41 |
4/4✓ Branch 0 taken 40 times.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 68 times.
|
188 | local_min = std::min(local_min, input[i]); |
| 42 | 148 | local_max = std::max(local_max, input[i]); | |
| 43 | } | ||
| 44 | 148 | return std::make_pair(local_min, local_max); | |
| 45 | 40 | }, [](auto a, auto b) { return std::make_pair(std::min(a.first, b.first), std::max(a.second, b.second)); }); | |
| 46 | |||
| 47 | 40 | uint8_t delta = upper_bound - lower_bound; | |
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 24 times.
|
40 | if (delta == 0) { |
| 50 | 16 | tbb::parallel_for(tbb::blocked_range<size_t>(0, sz), [&](const auto &range) { | |
| 51 |
2/4✓ Branch 0 taken 32 times.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
64 | for (auto idx = range.begin(); idx != range.end(); ++idx) { |
| 52 | 32 | output[idx] = input[idx]; | |
| 53 | } | ||
| 54 | }); | ||
| 55 | } else { | ||
| 56 | 24 | constexpr uint16_t kMaxUint8 = std::numeric_limits<uint8_t>::max(); | |
| 57 | 24 | tbb::parallel_for(tbb::blocked_range<size_t>(0, sz), [&](const auto &range) { | |
| 58 |
2/4✓ Branch 0 taken 116 times.
✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
232 | for (auto idx = range.begin(); idx != range.end(); ++idx) { |
| 59 | 116 | uint16_t old_value = input[idx]; | |
| 60 | 116 | uint16_t new_value = (kMaxUint8 * (old_value - lower_bound)) / delta; | |
| 61 | 116 | output[idx] = static_cast<uint8_t>(new_value); | |
| 62 | } | ||
| 63 | }); | ||
| 64 | } | ||
| 65 | |||
| 66 | 40 | return true; | |
| 67 | } | ||
| 68 | |||
| 69 | 40 | bool GutyanskyAImgContrastIncrTBB::PostProcessingImpl() { | |
| 70 | 40 | return true; | |
| 71 | } | ||
| 72 | |||
| 73 | } // namespace gutyansky_a_img_contrast_incr | ||
| 74 |