GCC Code Coverage Report


Directory: ./
File: tasks/krykov_e_sobel_op/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 23 23 100.0%
Functions: 5 5 100.0%
Branches: 6 10 60.0%

Line Branch Exec Source
1 #include "krykov_e_sobel_op/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <array>
6 #include <cmath>
7 #include <cstddef>
8 #include <vector>
9
10 #include "krykov_e_sobel_op/common/include/common.hpp"
11
12 namespace krykov_e_sobel_op {
13
14
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 KrykovESobelOpOMP::KrykovESobelOpOMP(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 GetOutput().clear();
18 12 }
19
20 12 bool KrykovESobelOpOMP::ValidationImpl() {
21 const auto &img = GetInput();
22
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
12 return img.width > 2 && img.height > 2 && static_cast<int>(img.data.size()) == img.width * img.height;
23 }
24
25 12 bool KrykovESobelOpOMP::PreProcessingImpl() {
26 const auto &img = GetInput();
27
28 12 width_ = img.width;
29 12 height_ = img.height;
30
31 12 grayscale_.resize(static_cast<size_t>(width_) * static_cast<size_t>(height_));
32 // RGB → grayscale
33
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 12 times.
204 for (int i = 0; i < width_ * height_; ++i) {
34 192 const Pixel &p = img.data[i];
35 192 grayscale_[i] = static_cast<int>((0.299 * p.r) + (0.587 * p.g) + (0.114 * p.b));
36 }
37 12 GetOutput().assign(static_cast<size_t>(width_) * static_cast<size_t>(height_), 0);
38 12 return true;
39 }
40
41 12 bool KrykovESobelOpOMP::RunImpl() {
42 12 const std::array<std::array<int, 3>, 3> gx_kernel = {{{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}}};
43
44 12 const std::array<std::array<int, 3>, 3> gy_kernel = {{{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}}};
45
46 auto &output = GetOutput();
47
48 12 const auto &gray = grayscale_;
49 12 const int h = height_;
50 12 const int w = width_;
51
52 12 #pragma omp parallel for default(none) shared(output, gray, gx_kernel, gy_kernel) firstprivate(h, w) schedule(static)
53
54 for (int row = 1; row < h - 1; ++row) {
55 for (int col = 1; col < w - 1; ++col) {
56 int gx = 0;
57 int gy = 0;
58
59 for (int ky = -1; ky <= 1; ++ky) {
60 for (int kx = -1; kx <= 1; ++kx) {
61 int pixel = gray[((row + ky) * w) + (col + kx)];
62 gx += pixel * gx_kernel.at(ky + 1).at(kx + 1);
63 gy += pixel * gy_kernel.at(ky + 1).at(kx + 1);
64 }
65 }
66
67 int magnitude = static_cast<int>(std::sqrt(static_cast<double>((gx * gx) + (gy * gy))));
68
69 output[(row * w) + col] = magnitude;
70 }
71 }
72
73 12 return true;
74 }
75
76 12 bool KrykovESobelOpOMP::PostProcessingImpl() {
77 12 return true;
78 }
79
80 } // namespace krykov_e_sobel_op
81