GCC Code Coverage Report


Directory: ./
File: tasks/mityaeva_d_contrast_enhancement_histogram_stretching/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 45 45 100.0%
Functions: 5 5 100.0%
Branches: 24 40 60.0%

Line Branch Exec Source
1 #include "mityaeva_d_contrast_enhancement_histogram_stretching/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <cstdint>
7 #include <utility>
8 #include <vector>
9
10 #include "mityaeva_d_contrast_enhancement_histogram_stretching/common/include/common.hpp"
11
12 namespace mityaeva_d_contrast_enhancement_histogram_stretching {
13
14
1/2
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
66 ContrastEnhancementSEQ::ContrastEnhancementSEQ(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16
1/2
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
66 GetInput() = in;
17 66 GetOutput() = std::vector<uint8_t>{};
18 66 }
19
20
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 bool ContrastEnhancementSEQ::ValidationImpl() {
21 const auto &input = GetInput();
22
23
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (input.size() < 3) {
24 return false;
25 }
26
27 66 const auto w_u8 = static_cast<std::uint8_t>(input[0]);
28 66 const auto h_u8 = static_cast<std::uint8_t>(input[1]);
29
30 66 width_ = static_cast<int>(w_u8);
31 66 height_ = static_cast<int>(h_u8);
32
33
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 66 times.
66 if (width_ <= 0 || height_ <= 0) {
34 return false;
35 }
36
37 66 total_pixels_ = width_ * height_;
38 if (total_pixels_ <= 0) {
39 return false;
40 }
41
42 66 return input.size() == static_cast<std::size_t>(total_pixels_) + 2U;
43 }
44
45 66 bool ContrastEnhancementSEQ::PreProcessingImpl() {
46 const auto &input = GetInput();
47
48 66 min_pixel_ = 255;
49 66 max_pixel_ = 0;
50
51
2/2
✓ Branch 0 taken 330 times.
✓ Branch 1 taken 66 times.
396 for (std::size_t i = 2; i < input.size(); ++i) {
52 330 const auto pixel = static_cast<std::uint8_t>(input[i]);
53 330 min_pixel_ = std::min(min_pixel_, pixel);
54 330 max_pixel_ = std::max(max_pixel_, pixel);
55 }
56
57 66 return true;
58 }
59
60 66 bool ContrastEnhancementSEQ::RunImpl() {
61 const auto &input = GetInput();
62
63
3/6
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 66 times.
✗ Branch 5 not taken.
66 if (width_ <= 0 || height_ <= 0 || total_pixels_ <= 0) {
64 return false;
65 }
66
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 const std::size_t expected_size = static_cast<std::size_t>(total_pixels_) + 2U;
67
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if (input.size() != expected_size) {
68 return false;
69 }
70
71 66 OutType result;
72
1/2
✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
66 result.resize(expected_size);
73
74
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 48 times.
66 result[0] = static_cast<std::uint8_t>(width_);
75 66 result[1] = static_cast<std::uint8_t>(height_);
76
77
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 48 times.
66 if (min_pixel_ == max_pixel_) {
78 18 std::copy(input.begin() + 2, input.end(), result.begin() + 2);
79 GetOutput() = std::move(result);
80 18 return true;
81 }
82
83 48 const double scale = 255.0 / static_cast<double>(max_pixel_ - min_pixel_);
84
85
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 48 times.
280 for (std::size_t i = 2; i < expected_size; ++i) {
86 232 const auto pixel = static_cast<std::uint8_t>(input[i]);
87 232 const double stretched = static_cast<double>(pixel - min_pixel_) * scale;
88
89 232 int rounded_value = static_cast<int>(std::lround(stretched));
90 rounded_value = std::clamp(rounded_value, 0, 255);
91
92 232 result[i] = static_cast<std::uint8_t>(rounded_value);
93 }
94
95 GetOutput() = std::move(result);
96 48 return true;
97 }
98
99
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 bool ContrastEnhancementSEQ::PostProcessingImpl() {
100 const auto &output = GetOutput();
101
102
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if (output.size() < 2) {
103 return false;
104 }
105
106 66 const int out_width = static_cast<int>(static_cast<std::uint8_t>(output[0]));
107 66 const int out_height = static_cast<int>(static_cast<std::uint8_t>(output[1]));
108
109
2/4
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
66 if (out_width != width_ || out_height != height_) {
110 return false;
111 }
112
113 66 return output.size() == static_cast<std::size_t>(total_pixels_) + 2U;
114 }
115
116 } // namespace mityaeva_d_contrast_enhancement_histogram_stretching
117