| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "pylaeva_s_inc_contrast_img_by_lsh/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> // для std::round | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "pylaeva_s_inc_contrast_img_by_lsh/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace pylaeva_s_inc_contrast_img_by_lsh { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | PylaevaSIncContrastImgByLshOMP::PylaevaSIncContrastImgByLshOMP(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | GetInput() = in; |
| 16 | GetOutput() = {}; | ||
| 17 | 72 | } | |
| 18 | |||
| 19 | 72 | bool PylaevaSIncContrastImgByLshOMP::ValidationImpl() { | |
| 20 | 72 | return !(GetInput().empty()); | |
| 21 | } | ||
| 22 | |||
| 23 | 72 | bool PylaevaSIncContrastImgByLshOMP::PreProcessingImpl() { | |
| 24 | 72 | GetOutput().resize(GetInput().size()); | |
| 25 | 72 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 44 times.
|
72 | bool PylaevaSIncContrastImgByLshOMP::RunImpl() { |
| 29 | const auto &input = GetInput(); | ||
| 30 | auto &output = GetOutput(); | ||
| 31 | |||
| 32 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 44 times.
|
72 | uint8_t min_pixel = input[0]; |
| 33 | uint8_t max_pixel = input[0]; | ||
| 34 | |||
| 35 | const size_t input_size = input.size(); | ||
| 36 | |||
| 37 | 72 | #pragma omp parallel for default(none) shared(input, input_size) reduction(min : min_pixel) reduction(max : max_pixel) | |
| 38 | for (size_t i = 0; i < input_size; ++i) { | ||
| 39 | min_pixel = std::min(min_pixel, input[i]); | ||
| 40 | max_pixel = std::max(max_pixel, input[i]); | ||
| 41 | } | ||
| 42 | |||
| 43 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 44 times.
|
72 | if (min_pixel == max_pixel) { |
| 44 | 28 | output = input; | |
| 45 | 28 | return true; | |
| 46 | } | ||
| 47 | |||
| 48 | 44 | float scale = 255.0F / static_cast<float>(max_pixel - min_pixel); | |
| 49 | |||
| 50 | 44 | #pragma omp parallel for default(none) shared(input, output, min_pixel, input_size, scale) | |
| 51 | for (size_t i = 0; i < input.size(); ++i) { | ||
| 52 | output[i] = static_cast<uint8_t>(std::round(static_cast<float>(input[i] - min_pixel) * scale)); | ||
| 53 | } | ||
| 54 | |||
| 55 | 44 | return true; | |
| 56 | } | ||
| 57 | |||
| 58 | 72 | bool PylaevaSIncContrastImgByLshOMP::PostProcessingImpl() { | |
| 59 | 72 | return true; | |
| 60 | } | ||
| 61 | |||
| 62 | } // namespace pylaeva_s_inc_contrast_img_by_lsh | ||
| 63 |