GCC Code Coverage Report


Directory: ./
File: tasks/romanova_v_linear_histogram_stretch/stl/src/ops_stl.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 55 59 93.2%
Functions: 7 9 77.8%
Branches: 33 54 61.1%

Line Branch Exec Source
1 #include "romanova_v_linear_histogram_stretch/stl/include/ops_stl.hpp"
2
3 #include <algorithm>
4 #include <cstddef>
5 #include <cstdint>
6 #include <thread>
7 #include <vector>
8
9 #include "romanova_v_linear_histogram_stretch/common/include/common.hpp"
10 #include "util/include/util.hpp"
11
12 namespace romanova_v_linear_histogram_stretch_threads {
13
14 void RomanovaVLinHistogramStretchSTL::GetThreadRange(size_t thid, size_t total, size_t num_th, size_t &beg,
15 size_t &en) {
16 200 size_t chunk = total / num_th;
17 200 beg = thid * chunk;
18
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
120 en = (thid == num_th - 1) ? total : (beg + chunk);
19 }
20
21 void RomanovaVLinHistogramStretchSTL::FindMinMax(size_t begin, size_t end, uint8_t &curr_min, uint8_t &curr_max,
22 const InType &in) {
23
2/4
✓ Branch 0 taken 8360760 times.
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8360880 for (size_t i = begin; i < end; ++i) {
24
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
8360760 uint8_t val = in[i];
25
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
8360760 curr_min = std::min(curr_min, val);
26 8360760 curr_max = std::max(curr_max, val);
27 }
28 }
29
30
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 RomanovaVLinHistogramStretchSTL::RomanovaVLinHistogramStretchSTL(const InType &in) {
31 SetTypeOfTask(GetStaticTypeOfTask());
32
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 GetInput() = in;
33 GetOutput().clear();
34 48 }
35
36 48 bool RomanovaVLinHistogramStretchSTL::ValidationImpl() {
37 48 return !GetInput().empty();
38 }
39
40 48 bool RomanovaVLinHistogramStretchSTL::PreProcessingImpl() {
41 48 GetOutput().resize(GetInput().size());
42 48 return !GetOutput().empty();
43 }
44
45 48 bool RomanovaVLinHistogramStretchSTL::RunImpl() {
46 const InType &in = GetInput();
47 OutType &out = GetOutput();
48 48 size_t size = in.size();
49
50 48 const int num_th = ppc::util::GetNumThreads();
51 48 std::vector<std::thread> threads;
52
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 threads.reserve(num_th);
53
54
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 std::vector<uint8_t> local_min(num_th, 255);
55
1/4
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
48 std::vector<uint8_t> local_max(num_th, 0);
56
57
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 48 times.
168 for (int thid = 0; thid < num_th; thid++) {
58
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 threads.emplace_back([&, thid]() {
59 size_t begin = 0;
60 size_t end = 0;
61
62
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 48 times.
120 GetThreadRange(thid, size, num_th, begin, end);
63
64 120 uint8_t current_min = 255;
65 120 uint8_t current_max = 0;
66
67 120 FindMinMax(begin, end, current_min, current_max, in);
68
69 120 local_min[thid] = current_min;
70 120 local_max[thid] = current_max;
71 120 });
72 }
73
74
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 48 times.
168 for (auto &th : threads) {
75
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 th.join();
76 }
77 48 threads.clear();
78
79 48 uint8_t min_v = local_min[0];
80 48 uint8_t max_v = local_max[0];
81
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 48 times.
120 for (int thid = 1; thid < num_th; thid++) {
82
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 54 times.
78 min_v = std::min(min_v, local_min[thid]);
83 72 max_v = std::max(max_v, local_max[thid]);
84 }
85
86
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 32 times.
48 if (min_v == max_v) {
87 std::ranges::copy(in, out.begin());
88 return true;
89 }
90
91 32 const uint8_t diff = max_v - min_v;
92 32 const double ratio = 255.0 / diff;
93
94
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 32 times.
112 for (int thid = 0; thid < num_th; thid++) {
95
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 threads.emplace_back([&, thid]() {
96 size_t begin = 0;
97 size_t end = 0;
98
99
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 32 times.
80 GetThreadRange(thid, size, num_th, begin, end);
100
101
2/2
✓ Branch 0 taken 360752 times.
✓ Branch 1 taken 80 times.
360832 for (size_t i = begin; i < end; i++) {
102 360752 out[i] = (std::clamp(static_cast<int>((in[i] - min_v) * ratio), 0, 255));
103 }
104 80 });
105 }
106
107
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 32 times.
112 for (auto &th : threads) {
108
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 th.join();
109 }
110 32 threads.clear();
111
112 32 return true;
113 48 }
114
115 48 bool RomanovaVLinHistogramStretchSTL::PostProcessingImpl() {
116 48 return true;
117 }
118
119 } // namespace romanova_v_linear_histogram_stretch_threads
120