| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "kiselev_i_linear_histogram_stretch/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <limits> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "kiselev_i_linear_histogram_stretch/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace kiselev_i_linear_histogram_stretch { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
|
104 | KiselevITestTaskSEQ::KiselevITestTaskSEQ(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 | GetInput() = in; | ||
| 17 | |||
| 18 |
1/2✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
|
104 | if (!in.pixels.empty()) { |
| 19 |
1/2✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
|
104 | GetOutput().resize(in.pixels.size()); |
| 20 | } | ||
| 21 | 104 | } | |
| 22 | |||
| 23 | 104 | bool KiselevITestTaskSEQ::ValidationImpl() { | |
| 24 | const auto &img = GetInput(); | ||
| 25 |
3/6✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 104 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 104 times.
|
104 | return img.width > 0 && img.height > 0 && img.pixels.size() == img.width * img.height; |
| 26 | } | ||
| 27 | |||
| 28 | 104 | bool KiselevITestTaskSEQ::PreProcessingImpl() { | |
| 29 | 104 | return true; | |
| 30 | } | ||
| 31 | |||
| 32 | 104 | bool KiselevITestTaskSEQ::RunImpl() { | |
| 33 | 104 | const auto &input = GetInput().pixels; | |
| 34 | auto &output = GetOutput(); | ||
| 35 | |||
| 36 | 104 | std::uint8_t min_val = std::numeric_limits<std::uint8_t>::max(); | |
| 37 | 104 | std::uint8_t max_val = std::numeric_limits<std::uint8_t>::min(); | |
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 104 times.
|
488 | for (std::uint8_t value : input) { |
| 40 | 384 | min_val = std::min(min_val, value); | |
| 41 | 384 | max_val = std::max(max_val, value); | |
| 42 | } | ||
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 96 times.
|
104 | if (min_val == max_val) { |
| 45 | 8 | output = input; | |
| 46 | 8 | return true; | |
| 47 | } | ||
| 48 | |||
| 49 | 96 | const double scale = 255.0 / static_cast<double>(max_val - min_val); | |
| 50 | |||
| 51 |
2/2✓ Branch 0 taken 336 times.
✓ Branch 1 taken 96 times.
|
432 | for (std::size_t i = 0; i < input.size(); ++i) { |
| 52 | 336 | const double stretched = static_cast<double>(input[i] - min_val) * scale; | |
| 53 | 336 | output[i] = static_cast<std::uint8_t>(std::lround(stretched)); | |
| 54 | } | ||
| 55 | |||
| 56 | return true; | ||
| 57 | } | ||
| 58 | |||
| 59 | 104 | bool KiselevITestTaskSEQ::PostProcessingImpl() { | |
| 60 | 104 | return true; | |
| 61 | } | ||
| 62 | |||
| 63 | } // namespace kiselev_i_linear_histogram_stretch | ||
| 64 |