| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gutyansky_a_img_contrast_incr/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <limits> | ||
| 7 | #include <thread> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "gutyansky_a_img_contrast_incr/common/include/common.hpp" | ||
| 12 | #include "util/include/util.hpp" | ||
| 13 | |||
| 14 | namespace gutyansky_a_img_contrast_incr { | ||
| 15 | |||
| 16 | namespace { | ||
| 17 | void WaitAll(std::vector<std::thread> &threads) { | ||
| 18 |
6/6✓ Branch 0 taken 120 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 200 times.
✓ Branch 5 taken 80 times.
|
560 | for (auto &thread : threads) { |
| 19 |
3/6✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 200 times.
✗ Branch 8 not taken.
|
400 | thread.join(); |
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | 80 | std::pair<uint8_t, uint8_t> ComputeBounds(const std::vector<uint8_t> &input) { | |
| 24 | 80 | const size_t sz = input.size(); | |
| 25 | 80 | const auto num_threads = static_cast<size_t>(ppc::util::GetNumThreads()); | |
| 26 | 80 | const size_t chunk_sz = (sz + num_threads - 1) / num_threads; | |
| 27 | |||
| 28 | 80 | std::vector<std::thread> threads; | |
| 29 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | threads.reserve(num_threads); |
| 30 | |||
| 31 | std::vector<std::pair<uint8_t, uint8_t>> local_res( | ||
| 32 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | num_threads, std::make_pair(static_cast<uint8_t>(255), static_cast<uint8_t>(0))); |
| 33 | |||
| 34 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 80 times.
|
280 | for (uint32_t tid = 0; tid < num_threads; tid++) { |
| 35 | 200 | size_t from = tid * chunk_sz; | |
| 36 |
1/2✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
|
200 | size_t to = std::min(sz, from + chunk_sz); |
| 37 | |||
| 38 |
1/4✓ Branch 1 taken 200 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
200 | threads.emplace_back([&local_res, &input, from, to, tid]() { |
| 39 | 200 | uint8_t local_min = 255; | |
| 40 | 200 | uint8_t local_max = 0; | |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 296 times.
✓ Branch 1 taken 200 times.
|
496 | for (size_t i = from; i < to; ++i) { |
| 43 |
4/4✓ Branch 0 taken 144 times.
✓ Branch 1 taken 152 times.
✓ Branch 2 taken 198 times.
✓ Branch 3 taken 98 times.
|
440 | local_min = std::min(local_min, input[i]); |
| 44 | 296 | local_max = std::max(local_max, input[i]); | |
| 45 | } | ||
| 46 | |||
| 47 | 200 | local_res[tid] = std::make_pair(local_min, local_max); | |
| 48 | 200 | }); | |
| 49 | } | ||
| 50 | |||
| 51 | WaitAll(threads); | ||
| 52 | |||
| 53 | 80 | uint8_t lower_bound = 255; | |
| 54 | 80 | uint8_t upper_bound = 0; | |
| 55 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 80 times.
|
280 | for (const auto &result : local_res) { |
| 56 | 200 | lower_bound = std::min(lower_bound, result.first); | |
| 57 | 200 | upper_bound = std::max(upper_bound, result.second); | |
| 58 | } | ||
| 59 | |||
| 60 | 80 | return std::make_pair(lower_bound, upper_bound); | |
| 61 | 80 | } | |
| 62 | |||
| 63 | 32 | void CopyMultiThread(const std::vector<uint8_t> &input, std::vector<uint8_t> &output) { | |
| 64 | 32 | const size_t sz = input.size(); | |
| 65 | 32 | const auto num_threads = static_cast<size_t>(ppc::util::GetNumThreads()); | |
| 66 | 32 | const size_t chunk_sz = (sz + num_threads - 1) / num_threads; | |
| 67 | |||
| 68 | 32 | std::vector<std::thread> threads; | |
| 69 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | threads.reserve(num_threads); |
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 32 times.
|
112 | for (uint32_t tid = 0; tid < num_threads; tid++) { |
| 72 | 80 | size_t from = tid * chunk_sz; | |
| 73 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | size_t to = std::min(from + chunk_sz, sz); |
| 74 | |||
| 75 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | threads.emplace_back([&output, &input, from, to]() { |
| 76 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 80 times.
|
144 | for (size_t idx = from; idx < to; ++idx) { |
| 77 | 64 | output[idx] = input[idx]; | |
| 78 | } | ||
| 79 | }); | ||
| 80 | } | ||
| 81 | |||
| 82 | WaitAll(threads); | ||
| 83 | 32 | } | |
| 84 | |||
| 85 | 48 | void TransformMultiThread(const std::vector<uint8_t> &input, std::vector<uint8_t> &output, uint8_t lower_bound, | |
| 86 | uint8_t delta) { | ||
| 87 | 48 | const size_t sz = input.size(); | |
| 88 | 48 | const auto num_threads = static_cast<size_t>(ppc::util::GetNumThreads()); | |
| 89 | 48 | const size_t chunk_sz = (sz + num_threads - 1) / num_threads; | |
| 90 | |||
| 91 | 48 | std::vector<std::thread> threads; | |
| 92 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | threads.reserve(num_threads); |
| 93 | |||
| 94 | constexpr uint16_t kMaxUint8 = std::numeric_limits<uint8_t>::max(); | ||
| 95 | |||
| 96 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 48 times.
|
168 | for (unsigned int tid = 0; tid < num_threads; tid++) { |
| 97 | 120 | size_t from = tid * chunk_sz; | |
| 98 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | size_t to = std::min(from + chunk_sz, sz); |
| 99 | |||
| 100 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | threads.emplace_back([&output, &input, from, to, lower_bound, delta]() { |
| 101 |
2/2✓ Branch 0 taken 232 times.
✓ Branch 1 taken 120 times.
|
352 | for (size_t idx = from; idx < to; ++idx) { |
| 102 | 232 | uint16_t old_value = input[idx]; | |
| 103 | 232 | uint16_t new_value = (kMaxUint8 * (old_value - lower_bound)) / delta; | |
| 104 | 232 | output[idx] = static_cast<uint8_t>(new_value); | |
| 105 | } | ||
| 106 | }); | ||
| 107 | } | ||
| 108 | |||
| 109 | WaitAll(threads); | ||
| 110 | 48 | } | |
| 111 | |||
| 112 | } // namespace | ||
| 113 | |||
| 114 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | GutyanskyAImgContrastIncrSTL::GutyanskyAImgContrastIncrSTL(const InType &in) { |
| 115 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 116 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | GetInput() = in; |
| 117 | GetOutput() = {}; | ||
| 118 | 80 | } | |
| 119 | |||
| 120 | 80 | bool GutyanskyAImgContrastIncrSTL::ValidationImpl() { | |
| 121 | 80 | return !GetInput().empty(); | |
| 122 | } | ||
| 123 | |||
| 124 | 80 | bool GutyanskyAImgContrastIncrSTL::PreProcessingImpl() { | |
| 125 | 80 | GetOutput().resize(GetInput().size()); | |
| 126 | 80 | return true; | |
| 127 | } | ||
| 128 | |||
| 129 | 80 | bool GutyanskyAImgContrastIncrSTL::RunImpl() { | |
| 130 | const auto &input = GetInput(); | ||
| 131 | auto &output = GetOutput(); | ||
| 132 | |||
| 133 | 80 | const auto bounds = ComputeBounds(input); | |
| 134 | 80 | const uint8_t delta = bounds.second - bounds.first; | |
| 135 | |||
| 136 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 48 times.
|
80 | if (delta == 0) { |
| 137 | 32 | CopyMultiThread(input, output); | |
| 138 | } else { | ||
| 139 | 48 | TransformMultiThread(input, output, bounds.first, delta); | |
| 140 | } | ||
| 141 | |||
| 142 | 80 | return true; | |
| 143 | } | ||
| 144 | |||
| 145 | 80 | bool GutyanskyAImgContrastIncrSTL::PostProcessingImpl() { | |
| 146 | 80 | return true; | |
| 147 | } | ||
| 148 | |||
| 149 | } // namespace gutyansky_a_img_contrast_incr | ||
| 150 |