GCC Code Coverage Report


Directory: ./
File: tasks/balchunayte_z_sobel/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 19 19 100.0%
Functions: 5 5 100.0%
Branches: 7 14 50.0%

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