GCC Code Coverage Report


Directory: ./
File: tasks/pylaeva_s_inc_contrast_img_by_lsh/stl/src/ops_stl.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 59 59 100.0%
Functions: 9 9 100.0%
Branches: 34 52 65.4%

Line Branch Exec Source
1 #include "pylaeva_s_inc_contrast_img_by_lsh/stl/include/ops_stl.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <thread>
6 #include <vector>
7
8 #include "pylaeva_s_inc_contrast_img_by_lsh/common/include/common.hpp"
9
10 namespace pylaeva_s_inc_contrast_img_by_lsh {
11
12
1/2
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
140 PylaevaSIncContrastImgByLshSTL::PylaevaSIncContrastImgByLshSTL(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
140 GetInput() = in;
15
1/2
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
140 GetOutput() = OutType(GetInput().size());
16 140 }
17
18 140 bool PylaevaSIncContrastImgByLshSTL::ValidationImpl() {
19 140 return !(GetInput().empty());
20 }
21
22 140 bool PylaevaSIncContrastImgByLshSTL::PreProcessingImpl() {
23 140 return true;
24 }
25
26 140 bool PylaevaSIncContrastImgByLshSTL::RunImpl() {
27 const InType &input = GetInput();
28
29 140 size_ = static_cast<int>(input.size());
30
31 140 thread_count_ = static_cast<int>(std::thread::hardware_concurrency());
32 140 chunk_size_ = static_cast<int>(input.size()) / thread_count_;
33
34 140 std::vector<unsigned char> loc_mins(thread_count_, 255);
35
1/4
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
140 std::vector<unsigned char> loc_maxs(thread_count_, 0);
36
37
1/2
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
140 FindLocalMinMax(loc_mins, loc_maxs);
38
39
1/2
✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
140 const int min = *std::ranges::min_element(loc_mins);
40 140 const int max = *std::ranges::max_element(loc_maxs);
41
42
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 88 times.
140 if (max == min) {
43
1/2
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
52 GetOutput() = GetInput();
44 return true;
45 }
46
47
1/2
✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
88 ApplyLinearStretching(min, max);
48
49 return true;
50 }
51
52 140 bool PylaevaSIncContrastImgByLshSTL::PostProcessingImpl() {
53 140 return true;
54 }
55
56
1/2
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
140 void PylaevaSIncContrastImgByLshSTL::FindLocalMinMax(std::vector<unsigned char> &loc_mins,
57 std::vector<unsigned char> &loc_maxs) {
58 const InType &input = GetInput();
59
60 140 std::vector<std::thread> thread_pool;
61
1/2
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
140 thread_pool.reserve(thread_count_);
62
63 560 auto reduction = [&](const int idx, const int start, const int end) {
64 560 unsigned char loc_min = loc_mins[idx];
65 560 unsigned char loc_max = loc_maxs[idx];
66
67
2/2
✓ Branch 0 taken 704 times.
✓ Branch 1 taken 560 times.
1264 for (int i = start; i < end; i++) {
68 704 loc_min = (input[i] < loc_min) ? input[i] : loc_min;
69 704 loc_max = (input[i] > loc_max) ? input[i] : loc_max;
70 }
71
72 560 loc_mins[idx] = loc_min;
73 560 loc_maxs[idx] = loc_max;
74 700 };
75
76
2/2
✓ Branch 0 taken 560 times.
✓ Branch 1 taken 140 times.
700 for (int i = 0; i < thread_count_; i++) {
77 560 const int start = chunk_size_ * i;
78
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 420 times.
560 const int end = (i == (thread_count_ - 1)) ? size_ : start + chunk_size_;
79
1/2
✓ Branch 1 taken 560 times.
✗ Branch 2 not taken.
560 thread_pool.emplace_back(reduction, i, start, end);
80 }
81
2/2
✓ Branch 0 taken 560 times.
✓ Branch 1 taken 140 times.
700 for (auto &thread : thread_pool) {
82
1/2
✓ Branch 1 taken 560 times.
✗ Branch 2 not taken.
560 thread.join();
83 }
84 140 }
85
86
1/2
✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
88 void PylaevaSIncContrastImgByLshSTL::ApplyLinearStretching(int min, int max) {
87 const InType &input = GetInput();
88 OutType &output = GetOutput();
89
90 88 const double scale = 255.0 / static_cast<double>(max - min);
91 88 const double offset = static_cast<double>(-min) * scale;
92
93 352 auto process = [&](const int start, const int end) {
94
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 352 times.
864 for (int i = start; i < end; i++) {
95 // Предварительно вычисленное выражение: input[i] * scale + offset
96 512 double new_value = (static_cast<double>(input[i]) * scale) + offset;
97 // Округление к ближайшему целому
98 512 int rounded_value = static_cast<int>(std::lround(new_value));
99
100 rounded_value = std::clamp(rounded_value, 0, 255);
101
102 512 output[i] = static_cast<unsigned char>(rounded_value);
103 }
104 440 };
105
106 88 std::vector<std::thread> thread_pool;
107
1/2
✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
88 thread_pool.reserve(thread_count_);
108
109
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 88 times.
440 for (int i = 0; i < thread_count_; i++) {
110 352 const int start = chunk_size_ * i;
111
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 264 times.
352 const int end = (i == (thread_count_ - 1)) ? size_ : start + chunk_size_;
112
1/2
✓ Branch 1 taken 352 times.
✗ Branch 2 not taken.
352 thread_pool.emplace_back(process, start, end);
113 }
114
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 88 times.
440 for (auto &thread : thread_pool) {
115
1/2
✓ Branch 1 taken 352 times.
✗ Branch 2 not taken.
352 thread.join();
116 }
117 88 }
118
119 } // namespace pylaeva_s_inc_contrast_img_by_lsh
120