GCC Code Coverage Report


Directory: ./
File: tasks/lukin_i_ench_contr_lin_hist/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 7 7 100.0%
Branches: 9 12 75.0%

Line Branch Exec Source
1 #include "lukin_i_ench_contr_lin_hist/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/tbb.h>
4
5 #include <algorithm>
6 #include <utility>
7 #include <vector>
8
9 #include "lukin_i_ench_contr_lin_hist/common/include/common.hpp"
10 #include "oneapi/tbb/parallel_for.h"
11
12 namespace lukin_i_ench_contr_lin_hist {
13
14 using MinMax = std::pair<unsigned char, unsigned char>;
15
16
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 LukinITestTaskTBB::LukinITestTaskTBB(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 GetInput() = in;
19
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 GetOutput() = OutType(GetInput().size());
20 16 }
21
22 16 bool LukinITestTaskTBB::ValidationImpl() {
23 16 return !(GetInput().empty());
24 }
25
26 16 bool LukinITestTaskTBB::PreProcessingImpl() {
27 16 return true;
28 }
29
30 16 bool LukinITestTaskTBB::RunImpl() {
31 const auto &input = GetInput();
32 auto &output = GetOutput();
33
34 16 unsigned char min = 255;
35 unsigned char max = 0;
36
37 16 const int size = static_cast<int>(input.size());
38
39 16 auto result = tbb::parallel_reduce(tbb::blocked_range<int>(0, size), MinMax(min, max),
40 16 [&](const tbb::blocked_range<int> &r, MinMax local) {
41 5245 unsigned char local_min = local.first;
42 5245 unsigned char local_max = local.second;
43
44
2/2
✓ Branch 0 taken 1380352 times.
✓ Branch 1 taken 5245 times.
1385597 for (int i = r.begin(); i < r.end(); i++) {
45 1380352 unsigned char curr = input[i];
46 1380352 local_max = std::max(local_max, curr);
47 1380352 local_min = std::min(local_min, curr);
48 }
49
50 5245 return MinMax(local_min, local_max);
51 16 }, [](MinMax left, MinMax right) {
52 return MinMax(std::min(left.first, right.first), std::max(left.second, right.second));
53 });
54
55 16 min = result.first;
56 max = result.second;
57
58
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
16 if (max == min) {
59 4 output = input;
60 4 return true;
61 }
62
63 12 float scale = 255.0F / static_cast<float>(max - min);
64
65 3934 tbb::parallel_for(tbb::blocked_range<int>(0, size), [&](const tbb::blocked_range<int> &r) {
66
2/2
✓ Branch 0 taken 1376256 times.
✓ Branch 1 taken 3922 times.
1380178 for (int i = r.begin(); i < r.end(); i++) {
67 1376256 output[i] = static_cast<unsigned char>(static_cast<float>(input[i] - min) * scale);
68 }
69 3922 });
70
71 12 return true;
72 }
73
74 16 bool LukinITestTaskTBB::PostProcessingImpl() {
75 16 return true;
76 }
77
78 } // namespace lukin_i_ench_contr_lin_hist
79