GCC Code Coverage Report


Directory: ./
File: tasks/belov_e_sobel/omp/src/ops_omp.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 5 5 100.0%
Branches: 9 18 50.0%

Line Branch Exec Source
1 #include "belov_e_sobel/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <algorithm>
6 #include <cmath>
7 #include <cstddef>
8 #include <cstdint>
9 #include <vector>
10
11 #include "belov_e_sobel/common/include/common.hpp"
12
13 namespace belov_e_sobel {
14
15
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 BelovESobelOMP::BelovESobelOMP(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17 GetInput() = in;
18 GetOutput() = in;
19 8 }
20
21
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 bool BelovESobelOMP::ValidationImpl() {
22
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 return !std::get<0>(GetInput()).empty() && (std::get<1>(GetInput()) > 0) && (std::get<2>(GetInput()) > 0);
23 }
24
25 8 bool BelovESobelOMP::PreProcessingImpl() {
26 8 return true;
27 }
28
29 8 bool BelovESobelOMP::RunImpl() {
30 const std::vector<uint8_t> &input = std::get<0>(GetInput());
31 std::vector<uint8_t> &output = std::get<0>(GetOutput());
32 8 int width = std::get<1>(GetInput());
33 8 int height = std::get<2>(GetInput());
34
35 8 #pragma omp parallel for default(none) shared(input, output, width, height) schedule(static)
36 for (int row = 0; row < height; ++row) {
37 for (int col = 0; col < width; ++col) {
38 int x_minus = std::clamp(col - 1, 0, width - 1);
39 int x_plus = std::clamp(col + 1, 0, width - 1);
40 int y_minus = std::clamp(row - 1, 0, height - 1);
41 int y_plus = std::clamp(row + 1, 0, height - 1);
42
43 float gx = (-1.0F * static_cast<float>(input[(static_cast<std::size_t>(y_minus) * width) + x_minus])) +
44 (1.0F * static_cast<float>(input[(static_cast<std::size_t>(y_minus) * width) + x_plus])) +
45 (-2.0F * static_cast<float>(input[(static_cast<std::size_t>(row) * width) + x_minus])) +
46 (2.0F * static_cast<float>(input[(static_cast<std::size_t>(row) * width) + x_plus])) +
47 (-1.0F * static_cast<float>(input[(static_cast<std::size_t>(y_plus) * width) + x_minus])) +
48 (1.0F * static_cast<float>(input[(static_cast<std::size_t>(y_plus) * width) + x_plus]));
49
50 float gy = (-1.0F * static_cast<float>(input[(static_cast<std::size_t>(y_minus) * width) + x_minus])) -
51 (2.0F * static_cast<float>(input[(static_cast<std::size_t>(y_minus) * width) + col])) -
52 (1.0F * static_cast<float>(input[(static_cast<std::size_t>(y_minus) * width) + x_plus])) +
53 (1.0F * static_cast<float>(input[(static_cast<std::size_t>(y_plus) * width) + x_minus])) +
54 (2.0F * static_cast<float>(input[(static_cast<std::size_t>(y_plus) * width) + col])) +
55 (1.0F * static_cast<float>(input[(static_cast<std::size_t>(y_plus) * width) + x_plus]));
56
57 float magnitude = std::sqrt((gx * gx) + (gy * gy));
58 output[(static_cast<std::size_t>(row) * width) + col] = static_cast<uint8_t>(std::min(255.0F, magnitude));
59 }
60 }
61
62 8 return true;
63 }
64
65
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 bool BelovESobelOMP::PostProcessingImpl() {
66
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 return !std::get<0>(GetOutput()).empty() && (std::get<1>(GetOutput()) > 0) && (std::get<2>(GetOutput()) > 0);
67 }
68
69 } // namespace belov_e_sobel
70