GCC Code Coverage Report


Directory: ./
File: tasks/romanova_v_linear_histogram_stretch/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 6 6 100.0%
Branches: 16 18 88.9%

Line Branch Exec Source
1 #include "romanova_v_linear_histogram_stretch/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/blocked_range.h>
4 #include <tbb/parallel_for.h>
5 #include <tbb/parallel_reduce.h>
6 #include <tbb/tbb.h>
7
8 #include <algorithm>
9 #include <cstddef>
10 #include <cstdint>
11 #include <vector>
12
13 #include "romanova_v_linear_histogram_stretch/common/include/common.hpp"
14
15 namespace romanova_v_linear_histogram_stretch_threads {
16
17
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 RomanovaVLinHistogramStretchTBB::RomanovaVLinHistogramStretchTBB(const InType &in) {
18 SetTypeOfTask(GetStaticTypeOfTask());
19
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetInput() = in;
20 GetOutput().clear();
21 24 }
22
23 24 bool RomanovaVLinHistogramStretchTBB::ValidationImpl() {
24 24 return !GetInput().empty();
25 }
26
27 24 bool RomanovaVLinHistogramStretchTBB::PreProcessingImpl() {
28 24 GetOutput().resize(GetInput().size());
29 24 return !GetOutput().empty();
30 }
31
32 24 bool RomanovaVLinHistogramStretchTBB::RunImpl() {
33 const InType &in = GetInput();
34 OutType &out = GetOutput();
35
36 struct MM {
37 uint8_t min;
38 uint8_t max;
39 };
40
41 48 MM minmax = tbb::parallel_reduce(tbb::blocked_range<size_t>(0, in.size()), MM{.min = 255, .max = 0},
42 24 [&](const tbb::blocked_range<size_t> &range, MM init) {
43
2/2
✓ Branch 0 taken 4180380 times.
✓ Branch 1 taken 4880 times.
4185260 for (size_t i = range.begin(); i != range.end(); i++) {
44
4/4
✓ Branch 0 taken 247 times.
✓ Branch 1 taken 4180133 times.
✓ Branch 2 taken 535 times.
✓ Branch 3 taken 4179845 times.
4181162 init = MM{.min = std::min(init.min, in[i]), .max = std::max(init.max, in[i])};
45 }
46 4880 return init;
47 24 }, [](MM first, MM second) {
48 return MM{.min = std::min(first.min, second.min), .max = std::max(first.max, second.max)};
49 });
50
51
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 16 times.
24 if (minmax.min == minmax.max) {
52 8 tbb::parallel_for(tbb::blocked_range<size_t>(0, in.size()), [&](const tbb::blocked_range<size_t> &range) {
53
4/4
✓ Branch 0 taken 238862 times.
✓ Branch 1 taken 158 times.
✓ Branch 2 taken 3761142 times.
✓ Branch 3 taken 1640 times.
4001802 for (size_t i = range.begin(); i != range.end(); i++) {
54 4000004 out[i] = in[i];
55 }
56 });
57 8 return true;
58 }
59
60 16 const uint8_t diff = minmax.max - minmax.min;
61 16 const double ratio = 255.0 / diff;
62
63 3084 tbb::parallel_for(tbb::blocked_range<size_t>(0, in.size()), [&](const tbb::blocked_range<size_t> &range) {
64
2/2
✓ Branch 0 taken 180376 times.
✓ Branch 1 taken 3068 times.
183444 for (size_t i = range.begin(); i != range.end(); i++) {
65 180376 out[i] = (std::clamp(static_cast<int>((in[i] - minmax.min) * ratio), 0, 255));
66 }
67 3068 });
68
69 16 return true;
70 }
71
72 24 bool RomanovaVLinHistogramStretchTBB::PostProcessingImpl() {
73 24 return true;
74 }
75
76 } // namespace romanova_v_linear_histogram_stretch_threads
77