GCC Code Coverage Report


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

Line Branch Exec Source
1 #include "iskhakov_d_vertical_gauss_filter/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <array>
6 #include <cstddef>
7 #include <cstdint>
8 #include <utility>
9 #include <vector>
10
11 #include "iskhakov_d_vertical_gauss_filter/common/include/common.hpp"
12 #include "util/include/util.hpp"
13
14 namespace iskhakov_d_vertical_gauss_filter {
15
16 namespace {
17 const int kDivConst = 16;
18 const std::array<std::array<int, 3>, 3> kGaussKernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}};
19
20 uint8_t IskhakovDGetPixelMirrorOmp(const std::vector<uint8_t> &res, int col, int row, int width, int height) {
21 if (col < 0) {
22 col = -col - 1;
23 } else if (col >= width) {
24 col = (2 * width) - col - 1;
25 }
26 if (row < 0) {
27 row = -row - 1;
28 } else if (row >= height) {
29 row = (2 * height) - row - 1;
30 }
31 return res[(row * width) + col];
32 }
33 } // namespace
34
35 IskhakovDVerticalGaussFilterOMP::IskhakovDVerticalGaussFilterOMP(const InType &in) {
36 SetTypeOfTask(GetStaticTypeOfTask());
37 GetInput() = in;
38 GetOutput() = OutType{};
39 }
40
41 bool IskhakovDVerticalGaussFilterOMP::ValidationImpl() {
42 const auto &in = GetInput();
43
44 if (in.width <= 0 || in.height <= 0) {
45 return false;
46 }
47 if (in.data.size() != static_cast<size_t>(in.width) * static_cast<size_t>(in.height)) {
48 return false;
49 }
50 return true;
51 }
52
53 bool IskhakovDVerticalGaussFilterOMP::PreProcessingImpl() {
54 return true;
55 }
56
57 bool IskhakovDVerticalGaussFilterOMP::RunImpl() {
58 const auto &in = GetInput();
59
60 int width = in.width;
61 int height = in.height;
62 const std::vector<uint8_t> &matrix = in.data;
63 std::vector<uint8_t> result(static_cast<size_t>(width) * static_cast<size_t>(height));
64
65 int num_threads = ppc::util::GetNumThreads();
66 omp_set_num_threads(num_threads);
67
68 #pragma omp parallel for default(none) shared(matrix, result, width, height, kGaussKernel, kDivConst)
69 for (int horizontal_band = 0; horizontal_band < width; ++horizontal_band) {
70 for (int vertical_band = 0; vertical_band < height; ++vertical_band) {
71 int sum = 0;
72
73 sum += kGaussKernel[0][0] *
74 IskhakovDGetPixelMirrorOmp(matrix, horizontal_band - 1, vertical_band - 1, width, height);
75 sum += kGaussKernel[0][1] * IskhakovDGetPixelMirrorOmp(matrix, horizontal_band, vertical_band - 1, width, height);
76 sum += kGaussKernel[0][2] *
77 IskhakovDGetPixelMirrorOmp(matrix, horizontal_band + 1, vertical_band - 1, width, height);
78
79 sum += kGaussKernel[1][0] * IskhakovDGetPixelMirrorOmp(matrix, horizontal_band - 1, vertical_band, width, height);
80 sum += kGaussKernel[1][1] * IskhakovDGetPixelMirrorOmp(matrix, horizontal_band, vertical_band, width, height);
81 sum += kGaussKernel[1][2] * IskhakovDGetPixelMirrorOmp(matrix, horizontal_band + 1, vertical_band, width, height);
82
83 sum += kGaussKernel[2][0] *
84 IskhakovDGetPixelMirrorOmp(matrix, horizontal_band - 1, vertical_band + 1, width, height);
85 sum += kGaussKernel[2][1] * IskhakovDGetPixelMirrorOmp(matrix, horizontal_band, vertical_band + 1, width, height);
86 sum += kGaussKernel[2][2] *
87 IskhakovDGetPixelMirrorOmp(matrix, horizontal_band + 1, vertical_band + 1, width, height);
88
89 result[(vertical_band * width) + horizontal_band] = static_cast<uint8_t>(sum / kDivConst);
90 }
91 }
92
93 GetOutput().width = width;
94 GetOutput().height = height;
95 GetOutput().data = std::move(result);
96 return true;
97 }
98
99 bool IskhakovDVerticalGaussFilterOMP::PostProcessingImpl() {
100 return true;
101 }
102
103 } // namespace iskhakov_d_vertical_gauss_filter
104