GCC Code Coverage Report


Directory: ./
File: tasks/zaharov_g_linear_contrast_stretch/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 8 8 100.0%
Branches: 12 14 85.7%

Line Branch Exec Source
1 #include "zaharov_g_linear_contrast_stretch/tbb/include/ops_tbb.hpp"
2
3 #include <algorithm>
4 #include <cstddef>
5 #include <cstdint>
6 #include <limits>
7
8 #include "oneapi/tbb/blocked_range.h"
9 #include "oneapi/tbb/parallel_for.h"
10 #include "oneapi/tbb/parallel_reduce.h"
11 #include "zaharov_g_linear_contrast_stretch/common/include/common.hpp"
12
13 namespace zaharov_g_linear_contrast_stretch {
14
15 namespace {
16
17 struct MinMax {
18 int min;
19 int max;
20 };
21
22 MinMax MergeMinMax(const MinMax &left, const MinMax &right) {
23 return MinMax{.min = std::min(left.min, right.min), .max = std::max(left.max, right.max)};
24 }
25
26 16 MinMax FindMinMax(const InType &input) {
27 const auto range = oneapi::tbb::blocked_range<std::size_t>(0, input.size());
28 16 const auto identity = MinMax{.min = std::numeric_limits<uint8_t>::max(), .max = std::numeric_limits<uint8_t>::min()};
29
30 const auto find_local_minmax = [&input](const oneapi::tbb::blocked_range<std::size_t> &range, MinMax current) {
31
4/4
✓ Branch 0 taken 378 times.
✓ Branch 1 taken 194 times.
✓ Branch 2 taken 4698 times.
✓ Branch 3 taken 1951 times.
7221 for (std::size_t i = range.begin(); i != range.end(); ++i) {
32 5076 const int value = static_cast<int>(input[i]);
33 current.min = std::min(current.min, value);
34 current.max = std::max(current.max, value);
35 }
36 return current;
37 16 };
38
39 const auto merge_minmax = [](const MinMax &left, const MinMax &right) { return MergeMinMax(left, right); };
40
41 16 return oneapi::tbb::parallel_reduce(range, identity, find_local_minmax, merge_minmax);
42 }
43
44 16 void StretchImage(const InType &input, OutType &output, const MinMax &minmax) {
45
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
16 if (minmax.max > minmax.min) {
46 12 const int denom = minmax.max - minmax.min;
47 oneapi::tbb::parallel_for(
48 12 oneapi::tbb::blocked_range<std::size_t>(0, input.size()),
49 12 [&input, &output, min_el = minmax.min, denom](const oneapi::tbb::blocked_range<std::size_t> &range) {
50
4/4
✓ Branch 0 taken 329 times.
✓ Branch 1 taken 151 times.
✓ Branch 2 taken 4707 times.
✓ Branch 3 taken 1996 times.
7183 for (std::size_t i = range.begin(); i != range.end(); ++i) {
51 5036 const int value = (static_cast<int>(input[i]) - min_el) * std::numeric_limits<uint8_t>::max() / denom;
52 5036 output[i] = static_cast<uint8_t>(std::clamp(value, 0, 255));
53 }
54 });
55 } else {
56 4 oneapi::tbb::parallel_for(oneapi::tbb::blocked_range<std::size_t>(0, input.size()),
57 44 [&input, &output](const oneapi::tbb::blocked_range<std::size_t> &range) {
58 40 std::copy(input.begin() + static_cast<std::ptrdiff_t>(range.begin()),
59 40 input.begin() + static_cast<std::ptrdiff_t>(range.end()),
60 40 output.begin() + static_cast<std::ptrdiff_t>(range.begin()));
61 40 });
62 }
63 16 }
64
65 } // namespace
66
67
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 ZaharovGLinContrStrTBB::ZaharovGLinContrStrTBB(const InType &in) {
68 SetTypeOfTask(GetStaticTypeOfTask());
69
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 GetInput() = in;
70 16 }
71
72 16 bool ZaharovGLinContrStrTBB::ValidationImpl() {
73 16 return !GetInput().empty();
74 }
75
76 16 bool ZaharovGLinContrStrTBB::PreProcessingImpl() {
77 16 GetOutput().resize(GetInput().size());
78 16 return true;
79 }
80
81 16 bool ZaharovGLinContrStrTBB::RunImpl() {
82 const InType &input = GetInput();
83 OutType &output = GetOutput();
84
85 16 const MinMax minmax = FindMinMax(input);
86 16 StretchImage(input, output, minmax);
87
88 16 return true;
89 }
90
91 16 bool ZaharovGLinContrStrTBB::PostProcessingImpl() {
92 16 return !GetOutput().empty();
93 }
94
95 } // namespace zaharov_g_linear_contrast_stretch
96