GCC Code Coverage Report


Directory: ./
File: tasks/shakirova_e_sobel_edge_detection/omp/src/ops_omp.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 5 5 100.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 #include "shakirova_e_sobel_edge_detection/omp/include/ops_omp.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <vector>
7
8 #include "shakirova_e_sobel_edge_detection/common/include/common.hpp"
9
10 namespace shakirova_e_sobel_edge_detection {
11
12
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 ShakirovaESobelEdgeDetectionOMP::ShakirovaESobelEdgeDetectionOMP(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 GetOutput().clear();
16 24 }
17
18
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 bool ShakirovaESobelEdgeDetectionOMP::ValidationImpl() {
19 24 return GetInput().IsValid();
20 }
21
22 24 bool ShakirovaESobelEdgeDetectionOMP::PreProcessingImpl() {
23 const auto &img = GetInput();
24 24 width_ = img.width;
25 24 height_ = img.height;
26 24 input_ = img.pixels;
27
28 24 GetOutput().assign(static_cast<size_t>(width_) * static_cast<size_t>(height_), 0);
29 24 return true;
30 }
31
32 24 bool ShakirovaESobelEdgeDetectionOMP::RunImpl() {
33 auto &out = GetOutput();
34 24 const int h = height_;
35 24 const int w = width_;
36 const int *inp = input_.data();
37
38 24 #pragma omp parallel for default(none) shared(out, inp) firstprivate(h, w) schedule(static)
39 for (int row = 1; row < h - 1; ++row) {
40 const int *prev = inp + (static_cast<ptrdiff_t>(row - 1) * w);
41 const int *curr = inp + (static_cast<ptrdiff_t>(row) * w);
42 const int *next = inp + (static_cast<ptrdiff_t>(row + 1) * w);
43
44 for (int col = 1; col < w - 1; ++col) {
45 const int gx =
46 -prev[col - 1] + prev[col + 1] - (2 * curr[col - 1]) + (2 * curr[col + 1]) - next[col - 1] + next[col + 1];
47
48 const int gy = -prev[col - 1] - (2 * prev[col]) - prev[col + 1] + next[col - 1] + (2 * next[col]) + next[col + 1];
49
50 const int abs_gx = std::abs(gx);
51 const int abs_gy = std::abs(gy);
52 const int magnitude = (std::max(abs_gx, abs_gy) * 123 + std::min(abs_gx, abs_gy) * 51) >> 7;
53 out[(row * w) + col] = std::min(magnitude, 255);
54 }
55 }
56
57 24 return true;
58 }
59
60 24 bool ShakirovaESobelEdgeDetectionOMP::PostProcessingImpl() {
61 24 return true;
62 }
63
64 } // namespace shakirova_e_sobel_edge_detection
65