| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "zaharov_g_linear_contrast_stretch/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <omp.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <cstdint> | ||
| 8 | #include <limits> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "util/include/util.hpp" | ||
| 12 | #include "zaharov_g_linear_contrast_stretch/common/include/common.hpp" | ||
| 13 | |||
| 14 | namespace zaharov_g_linear_contrast_stretch { | ||
| 15 | |||
| 16 | namespace { | ||
| 17 | |||
| 18 | struct MinMax { | ||
| 19 | int min; | ||
| 20 | int max; | ||
| 21 | }; | ||
| 22 | |||
| 23 | 16 | MinMax FindMinMax(const InType &input) { | |
| 24 | const auto size = static_cast<std::int64_t>(input.size()); | ||
| 25 | 16 | const int thread_count = std::max(1, ppc::util::GetNumThreads()); | |
| 26 | std::vector<MinMax> local_minmax( | ||
| 27 | static_cast<std::size_t>(thread_count), | ||
| 28 | 16 | MinMax{.min = std::numeric_limits<uint8_t>::max(), .max = std::numeric_limits<uint8_t>::min()}); | |
| 29 | |||
| 30 | 16 | #pragma omp parallel default(none) shared(input, local_minmax, size) num_threads(thread_count) | |
| 31 | { | ||
| 32 | MinMax current{.min = std::numeric_limits<uint8_t>::max(), .max = std::numeric_limits<uint8_t>::min()}; | ||
| 33 | #pragma omp for nowait | ||
| 34 | for (std::int64_t i = 0; i < size; ++i) { | ||
| 35 | const int value = static_cast<int>(input[static_cast<std::size_t>(i)]); | ||
| 36 | current.min = std::min(current.min, value); | ||
| 37 | current.max = std::max(current.max, value); | ||
| 38 | } | ||
| 39 | local_minmax[static_cast<std::size_t>(omp_get_thread_num())] = current; | ||
| 40 | } | ||
| 41 | |||
| 42 | 16 | MinMax result{.min = std::numeric_limits<uint8_t>::max(), .max = std::numeric_limits<uint8_t>::min()}; | |
| 43 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 16 times.
|
56 | for (const auto ¤t : local_minmax) { |
| 44 | 40 | result.min = std::min(result.min, current.min); | |
| 45 | 40 | result.max = std::max(result.max, current.max); | |
| 46 | } | ||
| 47 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | return result; |
| 48 | } | ||
| 49 | |||
| 50 | } // namespace | ||
| 51 | |||
| 52 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | ZaharovGLinContrStrOMP::ZaharovGLinContrStrOMP(const InType &in) { |
| 53 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 54 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | GetInput() = in; |
| 55 | 16 | } | |
| 56 | |||
| 57 | 16 | bool ZaharovGLinContrStrOMP::ValidationImpl() { | |
| 58 | 16 | return !GetInput().empty(); | |
| 59 | } | ||
| 60 | |||
| 61 | 16 | bool ZaharovGLinContrStrOMP::PreProcessingImpl() { | |
| 62 | 16 | GetOutput().resize(GetInput().size()); | |
| 63 | 16 | return true; | |
| 64 | } | ||
| 65 | |||
| 66 | 16 | bool ZaharovGLinContrStrOMP::RunImpl() { | |
| 67 | const InType &input = GetInput(); | ||
| 68 | OutType &output = GetOutput(); | ||
| 69 | |||
| 70 | const auto size = static_cast<std::int64_t>(input.size()); | ||
| 71 | 16 | const MinMax minmax = FindMinMax(input); | |
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
|
16 | if (minmax.max > minmax.min) { |
| 74 | 12 | const int denom = minmax.max - minmax.min; | |
| 75 | |||
| 76 | 12 | #pragma omp parallel for default(none) shared(input, output, size, minmax, denom) \ | |
| 77 | 12 | num_threads(ppc::util::GetNumThreads()) | |
| 78 | for (std::int64_t i = 0; i < size; ++i) { | ||
| 79 | const int value = (static_cast<int>(input[static_cast<std::size_t>(i)]) - minmax.min) * | ||
| 80 | std::numeric_limits<uint8_t>::max() / denom; | ||
| 81 | output[static_cast<std::size_t>(i)] = static_cast<uint8_t>(std::clamp(value, 0, 255)); | ||
| 82 | } | ||
| 83 | } else { | ||
| 84 | 4 | #pragma omp parallel for default(none) shared(input, output, size) num_threads(ppc::util::GetNumThreads()) | |
| 85 | for (std::int64_t i = 0; i < size; ++i) { | ||
| 86 | output[static_cast<std::size_t>(i)] = input[static_cast<std::size_t>(i)]; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | 16 | return true; | |
| 91 | } | ||
| 92 | |||
| 93 | 16 | bool ZaharovGLinContrStrOMP::PostProcessingImpl() { | |
| 94 | 16 | return !GetOutput().empty(); | |
| 95 | } | ||
| 96 | |||
| 97 | } // namespace zaharov_g_linear_contrast_stretch | ||
| 98 |