GCC Code Coverage Report


Directory: ./
File: tasks/shakirova_e_sobel_edge_detection/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: 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 <array>
5 #include <cmath>
6 #include <cstddef>
7 #include <vector>
8
9 #include "shakirova_e_sobel_edge_detection/common/include/common.hpp"
10
11 namespace shakirova_e_sobel_edge_detection {
12
13
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 ShakirovaESobelEdgeDetectionOMP::ShakirovaESobelEdgeDetectionOMP(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16 GetOutput().clear();
17 24 }
18
19
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 bool ShakirovaESobelEdgeDetectionOMP::ValidationImpl() {
20 24 return GetInput().IsValid();
21 }
22
23 24 bool ShakirovaESobelEdgeDetectionOMP::PreProcessingImpl() {
24 const auto &img = GetInput();
25 24 width_ = img.width;
26 24 height_ = img.height;
27 24 input_ = img.pixels;
28
29 24 GetOutput().assign(static_cast<size_t>(width_) * static_cast<size_t>(height_), 0);
30 24 return true;
31 }
32
33 24 bool ShakirovaESobelEdgeDetectionOMP::RunImpl() {
34 24 const std::array<std::array<int, 3>, 3> k_gx = {{{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}}};
35 24 const std::array<std::array<int, 3>, 3> k_gy = {{{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}}};
36
37 auto &out = GetOutput();
38 24 const int h = height_;
39 24 const int w = width_;
40
41 24 #pragma omp parallel for default(none) shared(out, k_gx, k_gy) firstprivate(h, w) schedule(static)
42 for (int row = 1; row < h - 1; ++row) {
43 for (int col = 1; col < w - 1; ++col) {
44 int gx = 0;
45 int gy = 0;
46
47 for (int ky = -1; ky <= 1; ++ky) {
48 for (int kx = -1; kx <= 1; ++kx) {
49 const int pixel = input_[((row + ky) * w) + (col + kx)];
50 const auto ky_idx = static_cast<size_t>(ky) + 1;
51 const auto kx_idx = static_cast<size_t>(kx) + 1;
52 gx += pixel * k_gx.at(ky_idx).at(kx_idx);
53 gy += pixel * k_gy.at(ky_idx).at(kx_idx);
54 }
55 }
56
57 const int magnitude = static_cast<int>(std::sqrt(static_cast<double>((gx * gx) + (gy * gy))));
58 out[(row * w) + col] = std::clamp(magnitude, 0, 255);
59 }
60 }
61
62 24 return true;
63 }
64
65 24 bool ShakirovaESobelEdgeDetectionOMP::PostProcessingImpl() {
66 24 return true;
67 }
68
69 } // namespace shakirova_e_sobel_edge_detection
70