GCC Code Coverage Report


Directory: ./
File: tasks/gutyansky_a_img_contrast_incr/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 6 6 100.0%
Branches: 14 20 70.0%

Line Branch Exec Source
1 #include "gutyansky_a_img_contrast_incr/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/tbb.h>
4
5 #include <cstddef>
6 #include <cstdint>
7 #include <limits>
8 #include <utility>
9
10 #include "gutyansky_a_img_contrast_incr/common/include/common.hpp"
11 #include "oneapi/tbb/blocked_range.h"
12 #include "oneapi/tbb/parallel_for.h"
13 #include "util/include/util.hpp"
14
15 namespace gutyansky_a_img_contrast_incr {
16
17
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GutyanskyAImgContrastIncrTBB::GutyanskyAImgContrastIncrTBB(const InType &in) {
18 SetTypeOfTask(GetStaticTypeOfTask());
19
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GetInput() = in;
20 GetOutput() = {};
21 40 }
22
23 40 bool GutyanskyAImgContrastIncrTBB::ValidationImpl() {
24 40 return !GetInput().empty();
25 }
26
27 40 bool GutyanskyAImgContrastIncrTBB::PreProcessingImpl() {
28 40 GetOutput().resize(GetInput().size());
29 40 return true;
30 }
31
32 40 bool GutyanskyAImgContrastIncrTBB::RunImpl() {
33 const auto &input = GetInput();
34 auto &output = GetOutput();
35
36 const size_t sz = input.size();
37 40 const auto num_threads = static_cast<size_t>(ppc::util::GetNumThreads());
38 40 const size_t chunk_sz = (sz + num_threads - 1) / num_threads;
39
40 40 auto [lower_bound, upper_bound] = tbb::parallel_reduce(
41 80 tbb::blocked_range<size_t>(0, sz, chunk_sz), std::make_pair(static_cast<uint8_t>(255), static_cast<uint8_t>(0)),
42 117 [&input](const auto &range, auto init) {
43 auto [local_min, local_max] = init;
44
2/2
✓ Branch 0 taken 148 times.
✓ Branch 1 taken 77 times.
225 for (size_t i = range.begin(); i != range.end(); ++i) {
45
4/4
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 68 times.
188 local_min = std::min(local_min, input[i]);
46 148 local_max = std::max(local_max, input[i]);
47 }
48 77 return std::make_pair(local_min, local_max);
49 40 }, [](auto a, auto b) { return std::make_pair(std::min(a.first, b.first), std::max(a.second, b.second)); });
50
51 40 uint8_t delta = upper_bound - lower_bound;
52
53
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 24 times.
40 if (delta == 0) {
54 16 tbb::parallel_for(tbb::blocked_range<size_t>(0, sz, chunk_sz), [&](const auto &range) {
55
2/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
53 for (auto idx = range.begin(); idx != range.end(); ++idx) {
56 32 output[idx] = input[idx];
57 }
58 });
59 } else {
60 24 constexpr uint16_t kMaxUint8 = std::numeric_limits<uint8_t>::max();
61 24 tbb::parallel_for(tbb::blocked_range<size_t>(0, sz, chunk_sz), [&](const auto &range) {
62
2/4
✓ Branch 0 taken 116 times.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
172 for (auto idx = range.begin(); idx != range.end(); ++idx) {
63 116 uint16_t old_value = input[idx];
64 116 uint16_t new_value = (kMaxUint8 * (old_value - lower_bound)) / delta;
65 116 output[idx] = static_cast<uint8_t>(new_value);
66 }
67 });
68 }
69
70 40 return true;
71 }
72
73 40 bool GutyanskyAImgContrastIncrTBB::PostProcessingImpl() {
74 40 return true;
75 }
76
77 } // namespace gutyansky_a_img_contrast_incr
78