GCC Code Coverage Report


Directory: ./
File: tasks/balchunayte_z_sobel/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 45 45 100.0%
Functions: 6 6 100.0%
Branches: 10 18 55.6%

Line Branch Exec Source
1 #include "balchunayte_z_sobel/tbb/include/ops_tbb.hpp"
2
3 #include <cstddef>
4 #include <cstdlib>
5 #include <vector>
6
7 #include "balchunayte_z_sobel/common/include/common.hpp"
8 #include "oneapi/tbb/parallel_for.h"
9
10 namespace balchunayte_z_sobel {
11
12 namespace {
13
14 int ConvertPixelToGray(const Pixel &pixel_value) {
15 48 return (77 * static_cast<int>(pixel_value.r) + 150 * static_cast<int>(pixel_value.g) +
16 48 29 * static_cast<int>(pixel_value.b)) >>
17 48 8;
18 }
19
20 } // namespace
21
22
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 BalchunayteZSobelOpTBB::BalchunayteZSobelOpTBB(const InType &input_image) {
23 SetTypeOfTask(GetStaticTypeOfTask());
24 GetInput() = input_image;
25 GetOutput().clear();
26 12 }
27
28 12 bool BalchunayteZSobelOpTBB::ValidationImpl() {
29 const auto &input_image = GetInput();
30
31
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 if (input_image.width <= 0 || input_image.height <= 0) {
32 return false;
33 }
34
35
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 const auto expected_size = static_cast<size_t>(input_image.width) * static_cast<size_t>(input_image.height);
36
37
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (input_image.data.size() != expected_size) {
38 return false;
39 }
40
41 12 return GetOutput().empty();
42 }
43
44 12 bool BalchunayteZSobelOpTBB::PreProcessingImpl() {
45 const auto &input_image = GetInput();
46 12 GetOutput().assign(static_cast<size_t>(input_image.width) * static_cast<size_t>(input_image.height), 0);
47 12 return true;
48 }
49
50
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 bool BalchunayteZSobelOpTBB::RunImpl() {
51 const auto &input_image = GetInput();
52 auto &output_data = GetOutput();
53
54 12 const int image_width = input_image.width;
55 12 const int image_height = input_image.height;
56 12 const auto image_width_size = static_cast<size_t>(image_width);
57
58
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 if (image_width < 3 || image_height < 3) {
59 return true;
60 }
61
62 12 oneapi::tbb::parallel_for(1, image_height - 1, [&](int row_index) {
63
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int col_index = 1; col_index < image_width - 1; ++col_index) {
64 48 const size_t index_top_left =
65 48 (static_cast<size_t>(row_index - 1) * image_width_size) + static_cast<size_t>(col_index - 1);
66 48 const size_t index_top_middle =
67 48 (static_cast<size_t>(row_index - 1) * image_width_size) + static_cast<size_t>(col_index);
68 48 const size_t index_top_right =
69 48 (static_cast<size_t>(row_index - 1) * image_width_size) + static_cast<size_t>(col_index + 1);
70
71 48 const size_t index_middle_left =
72 48 (static_cast<size_t>(row_index) * image_width_size) + static_cast<size_t>(col_index - 1);
73 48 const size_t index_middle_right =
74 (static_cast<size_t>(row_index) * image_width_size) + static_cast<size_t>(col_index + 1);
75
76 48 const size_t index_bottom_left =
77 48 (static_cast<size_t>(row_index + 1) * image_width_size) + static_cast<size_t>(col_index - 1);
78 48 const size_t index_bottom_middle =
79 (static_cast<size_t>(row_index + 1) * image_width_size) + static_cast<size_t>(col_index);
80 48 const size_t index_bottom_right =
81 (static_cast<size_t>(row_index + 1) * image_width_size) + static_cast<size_t>(col_index + 1);
82
83 48 const int gray_top_left = ConvertPixelToGray(input_image.data[index_top_left]);
84 const int gray_top_middle = ConvertPixelToGray(input_image.data[index_top_middle]);
85 const int gray_top_right = ConvertPixelToGray(input_image.data[index_top_right]);
86
87 const int gray_middle_left = ConvertPixelToGray(input_image.data[index_middle_left]);
88 const int gray_middle_right = ConvertPixelToGray(input_image.data[index_middle_right]);
89
90 const int gray_bottom_left = ConvertPixelToGray(input_image.data[index_bottom_left]);
91 const int gray_bottom_middle = ConvertPixelToGray(input_image.data[index_bottom_middle]);
92 const int gray_bottom_right = ConvertPixelToGray(input_image.data[index_bottom_right]);
93
94 48 const int gradient_x = (-gray_top_left + gray_top_right) + (-2 * gray_middle_left + 2 * gray_middle_right) +
95 48 (-gray_bottom_left + gray_bottom_right);
96
97 48 const int gradient_y = (gray_top_left + (2 * gray_top_middle) + gray_top_right) +
98 48 (-gray_bottom_left - (2 * gray_bottom_middle) - gray_bottom_right);
99
100 48 const int magnitude = std::abs(gradient_x) + std::abs(gradient_y);
101
102 48 const size_t output_index = (static_cast<size_t>(row_index) * image_width_size) + static_cast<size_t>(col_index);
103 48 output_data[output_index] = magnitude;
104 }
105 24 });
106
107 12 return true;
108 }
109
110 12 bool BalchunayteZSobelOpTBB::PostProcessingImpl() {
111 12 return true;
112 }
113
114 } // namespace balchunayte_z_sobel
115