| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "otcheskov_s_contrast_lin_stretch/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <cstdint> | ||
| 8 | #include <util/include/util.hpp> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "otcheskov_s_contrast_lin_stretch/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace otcheskov_s_contrast_lin_stretch { | ||
| 14 | |||
| 15 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | OtcheskovSContrastLinStretchTBB::OtcheskovSContrastLinStretchTBB(const InType &in) { |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 |
1/2✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
|
36 | GetInput() = in; |
| 18 | GetOutput().clear(); | ||
| 19 | 36 | } | |
| 20 | |||
| 21 | 36 | bool OtcheskovSContrastLinStretchTBB::ValidationImpl() { | |
| 22 | 36 | return !GetInput().empty(); | |
| 23 | } | ||
| 24 | |||
| 25 | 36 | bool OtcheskovSContrastLinStretchTBB::PreProcessingImpl() { | |
| 26 | 36 | GetOutput().resize(GetInput().size()); | |
| 27 | 36 | return GetOutput().size() == GetInput().size(); | |
| 28 | } | ||
| 29 | |||
| 30 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 4 times.
|
36 | bool OtcheskovSContrastLinStretchTBB::RunImpl() { |
| 31 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 4 times.
|
36 | if (GetInput().empty()) { |
| 32 | return false; | ||
| 33 | } | ||
| 34 | |||
| 35 | const InType &input = GetInput(); | ||
| 36 | OutType &output = GetOutput(); | ||
| 37 | const size_t size = input.size(); | ||
| 38 | |||
| 39 | 32 | tbb::task_arena arena(ppc::util::GetNumThreads()); | |
| 40 | |||
| 41 | MinMax result = ComputeMinMax(input, arena); | ||
| 42 | 32 | if (result.min == result.max) { | |
| 43 | const size_t threshold_size = 1000000; | ||
| 44 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
|
12 | if (size > threshold_size) { |
| 45 | CopyInput(input, output, arena); | ||
| 46 | } else { | ||
| 47 |
2/2✓ Branch 0 taken 404 times.
✓ Branch 1 taken 8 times.
|
412 | for (size_t i = 0; i < size; ++i) { |
| 48 | 404 | output[i] = input[i]; | |
| 49 | } | ||
| 50 | } | ||
| 51 | 12 | return true; | |
| 52 | } | ||
| 53 | 20 | const int min_i = static_cast<int>(result.min); | |
| 54 | 20 | const int range = static_cast<int>(result.max - min_i); | |
| 55 | 20 | LinearStretch(input, output, min_i, range, arena); | |
| 56 | 20 | return true; | |
| 57 | } | ||
| 58 | |||
| 59 | 36 | bool OtcheskovSContrastLinStretchTBB::PostProcessingImpl() { | |
| 60 | 36 | return true; | |
| 61 | } | ||
| 62 | |||
| 63 | ✗ | OtcheskovSContrastLinStretchTBB::MinMax OtcheskovSContrastLinStretchTBB::ComputeMinMax(const InType &input, | |
| 64 | tbb::task_arena &arena) { | ||
| 65 | 32 | MinMax result{}; | |
| 66 |
1/2✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
32 | arena.execute([&] { |
| 67 | 64 | result = tbb::parallel_reduce(tbb::blocked_range<size_t>(0, input.size()), MinMax{}, | |
| 68 | 32 | [&](const tbb::blocked_range<size_t> &r, MinMax local) { | |
| 69 |
2/2✓ Branch 0 taken 9309420 times.
✓ Branch 1 taken 74 times.
|
9309494 | for (size_t i = r.begin(); i != r.end(); ++i) { |
| 70 |
4/4✓ Branch 0 taken 195 times.
✓ Branch 1 taken 9309225 times.
✓ Branch 2 taken 857 times.
✓ Branch 3 taken 9308563 times.
|
9309615 | local.min = std::min(local.min, input[i]); |
| 71 | 9309420 | local.max = std::max(local.max, input[i]); | |
| 72 | } | ||
| 73 | 74 | return local; | |
| 74 | 32 | }, [](const MinMax &a, const MinMax &b) -> MinMax { | |
| 75 | return MinMax{.min = std::min(a.min, b.min), .max = std::max(a.max, b.max)}; | ||
| 76 | 32 | }, tbb::static_partitioner{}); | |
| 77 | 32 | }); | |
| 78 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 20 times.
|
32 | return result; |
| 79 | } | ||
| 80 | |||
| 81 | ✗ | void OtcheskovSContrastLinStretchTBB::CopyInput(const InType &input, OutType &output, tbb::task_arena &arena) { | |
| 82 |
1/2✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | arena.execute([&] { |
| 83 | 4 | tbb::parallel_for(tbb::blocked_range<size_t>(0, input.size()), [&](const tbb::blocked_range<size_t> &r) { | |
| 84 |
2/2✓ Branch 0 taken 4008004 times.
✓ Branch 1 taken 10 times.
|
4008014 | for (size_t i = r.begin(); i != r.end(); ++i) { |
| 85 | 4008004 | output[i] = input[i]; | |
| 86 | } | ||
| 87 | 4 | }, tbb::static_partitioner{}); | |
| 88 | 4 | }); | |
| 89 | 4 | } | |
| 90 | |||
| 91 | ✗ | void OtcheskovSContrastLinStretchTBB::LinearStretch(const InType &input, OutType &output, int min_i, int range, | |
| 92 | tbb::task_arena &arena) { | ||
| 93 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | arena.execute([&] { |
| 94 | 70 | tbb::parallel_for(tbb::blocked_range<size_t>(0, input.size()), [&](const tbb::blocked_range<size_t> &r) { | |
| 95 |
2/2✓ Branch 0 taken 5301012 times.
✓ Branch 1 taken 50 times.
|
5301062 | for (size_t i = r.begin(); i != r.end(); ++i) { |
| 96 | 5301012 | int value = (static_cast<int>(input[i]) - min_i) * 255 / range; | |
| 97 | 5301012 | output[i] = static_cast<uint8_t>(std::clamp(value, 0, 255)); | |
| 98 | } | ||
| 99 | 70 | }, tbb::static_partitioner{}); | |
| 100 | 20 | }); | |
| 101 | ✗ | } | |
| 102 | |||
| 103 | } // namespace otcheskov_s_contrast_lin_stretch | ||
| 104 |