| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "batkov_f_contrast_enh_lin_hist_stretch/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <limits> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "batkov_f_contrast_enh_lin_hist_stretch/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace batkov_f_contrast_enh_lin_hist_stretch { | ||
| 13 | |||
| 14 | namespace { | ||
| 15 | |||
| 16 | 12 | std::pair<uint8_t, uint8_t> FindMinMaxParallel(const std::vector<uint8_t> &input) { | |
| 17 | uint8_t min_el = std::numeric_limits<uint8_t>::max(); | ||
| 18 | uint8_t max_el = std::numeric_limits<uint8_t>::min(); | ||
| 19 | auto input_size = static_cast<int64_t>(input.size()); | ||
| 20 | |||
| 21 | 12 | #pragma omp parallel for default(none) shared(input, input_size) reduction(min : min_el) reduction(max : max_el) | |
| 22 | for (int64_t i = 0; i < input_size; ++i) { | ||
| 23 | min_el = std::min(input[i], min_el); | ||
| 24 | max_el = std::max(input[i], max_el); | ||
| 25 | } | ||
| 26 | |||
| 27 | 12 | return {min_el, max_el}; | |
| 28 | } | ||
| 29 | |||
| 30 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
|
24 | std::pair<uint8_t, uint8_t> FindMinMax(const std::vector<uint8_t> &input, size_t parallel_threshold) { |
| 31 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
|
24 | if (input.size() < parallel_threshold) { |
| 32 | auto [it_min, it_max] = std::ranges::minmax_element(input); | ||
| 33 | 12 | return {*it_min, *it_max}; | |
| 34 | } | ||
| 35 | |||
| 36 | 12 | return FindMinMaxParallel(input); | |
| 37 | } | ||
| 38 | |||
| 39 | } // namespace | ||
| 40 | |||
| 41 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | BatkovFContrastEnhLinHistStretchOMP::BatkovFContrastEnhLinHistStretchOMP(const InType &in) { |
| 42 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 43 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | GetInput() = in; |
| 44 | 24 | } | |
| 45 | |||
| 46 | 24 | bool BatkovFContrastEnhLinHistStretchOMP::ValidationImpl() { | |
| 47 | 24 | return !GetInput().empty(); | |
| 48 | } | ||
| 49 | |||
| 50 | 24 | bool BatkovFContrastEnhLinHistStretchOMP::PreProcessingImpl() { | |
| 51 | 24 | GetOutput().resize(GetInput().size()); | |
| 52 | 24 | return true; | |
| 53 | } | ||
| 54 | |||
| 55 | 24 | bool BatkovFContrastEnhLinHistStretchOMP::RunImpl() { | |
| 56 | const auto &input = GetInput(); | ||
| 57 | auto &output = GetOutput(); | ||
| 58 | auto input_size = static_cast<int64_t>(input.size()); | ||
| 59 | |||
| 60 | 24 | auto [min_el, max_el] = FindMinMax(input, 100000); | |
| 61 | |||
| 62 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (max_el > min_el) { |
| 63 | 24 | double a = 255.0 / (max_el - min_el); | |
| 64 | 24 | double b = -a * min_el; | |
| 65 | |||
| 66 | 24 | #pragma omp parallel for default(none) shared(input, input_size, output, a, b) | |
| 67 | for (int64_t i = 0; i < input_size; ++i) { | ||
| 68 | double new_pixel = (a * static_cast<double>(input[i])) + b; | ||
| 69 | output[i] = static_cast<uint8_t>(std::clamp(new_pixel, 0.0, 255.0)); | ||
| 70 | } | ||
| 71 | } else { | ||
| 72 | std::ranges::copy(input.begin(), input.end(), output.begin()); | ||
| 73 | } | ||
| 74 | |||
| 75 | 24 | return true; | |
| 76 | } | ||
| 77 | |||
| 78 | 24 | bool BatkovFContrastEnhLinHistStretchOMP::PostProcessingImpl() { | |
| 79 | 24 | return !GetOutput().empty(); | |
| 80 | } | ||
| 81 | |||
| 82 | } // namespace batkov_f_contrast_enh_lin_hist_stretch | ||
| 83 |