GCC Code Coverage Report


Directory: ./
File: tasks/kopilov_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 "kopilov_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 "kopilov_d_vertical_gauss_filter/common/include/common.hpp"
12 #include "util/include/util.hpp"
13
14 namespace kopilov_d_vertical_gauss_filter {
15
16 namespace {
17 const int kDivisor = 16;
18 const std::array<std::array<int, 3>, 3> kGaussKernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}};
19
20 uint8_t GetPixelMirroredOmp(const std::vector<uint8_t> &image, int x, int y, int width, int height) {
21 int new_x = x;
22 int new_y = y;
23
24 if (new_x < 0) {
25 new_x = -new_x - 1;
26 } else if (new_x >= width) {
27 new_x = (2 * width) - new_x - 1;
28 }
29 if (new_y < 0) {
30 new_y = -new_y - 1;
31 } else if (new_y >= height) {
32 new_y = (2 * height) - new_y - 1;
33 }
34 return image[(new_y * width) + new_x];
35 }
36 } // namespace
37
38 KopilovDVerticalGaussFilterOMP::KopilovDVerticalGaussFilterOMP(const InType &in) {
39 SetTypeOfTask(GetStaticTypeOfTask());
40 GetInput() = in;
41 GetOutput() = OutType{};
42 }
43
44 bool KopilovDVerticalGaussFilterOMP::ValidationImpl() {
45 const auto &in = GetInput();
46
47 if (in.width <= 0 || in.height <= 0) {
48 return false;
49 }
50 if (in.data.size() != static_cast<size_t>(in.width) * static_cast<size_t>(in.height)) {
51 return false;
52 }
53 return true;
54 }
55
56 bool KopilovDVerticalGaussFilterOMP::PreProcessingImpl() {
57 return true;
58 }
59
60 bool KopilovDVerticalGaussFilterOMP::RunImpl() {
61 const auto &in = GetInput();
62 int width = in.width;
63 int height = in.height;
64 const std::vector<uint8_t> &source_image = in.data;
65 std::vector<uint8_t> destination_image(static_cast<size_t>(width) * static_cast<size_t>(height));
66
67 int num_threads = ppc::util::GetNumThreads();
68 omp_set_num_threads(num_threads);
69
70 #pragma omp parallel for default(none) shared(source_image, destination_image, width, height, kGaussKernel, kDivisor)
71 for (int j = 0; j < height; ++j) {
72 for (int i = 0; i < width; ++i) {
73 int pixel_sum = 0;
74 for (int kernel_y = -1; kernel_y <= 1; ++kernel_y) {
75 for (int kernel_x = -1; kernel_x <= 1; ++kernel_x) {
76 pixel_sum += kGaussKernel.at(kernel_y + 1).at(kernel_x + 1) *
77 GetPixelMirroredOmp(source_image, i + kernel_x, j + kernel_y, width, height);
78 }
79 }
80 destination_image[(j * width) + i] = static_cast<uint8_t>(pixel_sum / kDivisor);
81 }
82 }
83
84 GetOutput().width = width;
85 GetOutput().height = height;
86 GetOutput().data = std::move(destination_image);
87 return true;
88 }
89
90 bool KopilovDVerticalGaussFilterOMP::PostProcessingImpl() {
91 return true;
92 }
93
94 } // namespace kopilov_d_vertical_gauss_filter
95