GCC Code Coverage Report


Directory: ./
File: tasks/buzulukski_d_gaus_gorizontal/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 0 37 0.0%
Functions: 0 7 0.0%
Branches: 0 20 0.0%

Line Branch Exec Source
1 #include "buzulukski_d_gaus_gorizontal/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <algorithm>
6 #include <array>
7 #include <cstddef>
8 #include <cstdint>
9 #include <vector>
10
11 #include "buzulukski_d_gaus_gorizontal/common/include/common.hpp"
12
13 namespace buzulukski_d_gaus_gorizontal {
14
15 namespace {
16 constexpr int kChannels = 3;
17 constexpr int kKernelSize = 3;
18 constexpr int kKernelSum = 16;
19
20 using KernelRow = std::array<int, kKernelSize>;
21 constexpr std::array<KernelRow, kKernelSize> kKernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}};
22
23 uint8_t CalculatePixel(const uint8_t *in, int py, int px, int w, int h, int ch) {
24 int sum = 0;
25 for (int ky = -1; ky <= 1; ++ky) {
26 for (int kx = -1; kx <= 1; ++kx) {
27 int ny = std::max(0, std::min(h - 1, py + ky));
28 int nx = std::max(0, std::min(w - 1, px + kx));
29
30 size_t idx = (((static_cast<size_t>(ny) * static_cast<size_t>(w)) + static_cast<size_t>(nx)) * 3) +
31 static_cast<size_t>(ch);
32
33 size_t row_idx = static_cast<size_t>(ky) + 1;
34 size_t col_idx = static_cast<size_t>(kx) + 1;
35 sum += static_cast<int>(in[idx]) * kKernel.at(row_idx).at(col_idx);
36 }
37 }
38 return static_cast<uint8_t>(sum / kKernelSum);
39 }
40 } // namespace
41
42 BuzulukskiDGausGorizontalOMP::BuzulukskiDGausGorizontalOMP(const InType &in) : BaseTask() {
43 SetTypeOfTask(GetStaticTypeOfTask());
44 GetInput() = in;
45 GetOutput() = 0;
46 }
47
48 bool BuzulukskiDGausGorizontalOMP::ValidationImpl() {
49 return GetInput() >= kKernelSize;
50 }
51
52 bool BuzulukskiDGausGorizontalOMP::PreProcessingImpl() {
53 width_ = GetInput();
54 height_ = GetInput();
55
56 if (width_ < kKernelSize) {
57 return false;
58 }
59
60 const auto total_size = (static_cast<std::size_t>(width_) * static_cast<std::size_t>(height_) * kChannels);
61 input_image_.assign(total_size, static_cast<uint8_t>(100));
62 output_image_.assign(total_size, 0);
63 return true;
64 }
65
66 void BuzulukskiDGausGorizontalOMP::ApplyGaussianToPixel(int py, int px) {
67 (void)py;
68 (void)px;
69 }
70
71 bool BuzulukskiDGausGorizontalOMP::RunImpl() {
72 const int h = height_;
73 const int w = width_;
74 const uint8_t *in_ptr = input_image_.data();
75 uint8_t *out_ptr = output_image_.data();
76
77 #pragma omp parallel for default(none) shared(h, w, in_ptr, out_ptr, kKernel)
78 for (int py = 0; py < h; ++py) {
79 for (int px = 0; px < w; ++px) {
80 for (int ch = 0; ch < 3; ++ch) {
81 size_t out_idx = ((((static_cast<size_t>(py) * static_cast<size_t>(w)) + static_cast<size_t>(px)) * 3) +
82 static_cast<size_t>(ch));
83 out_ptr[out_idx] = CalculatePixel(in_ptr, py, px, w, h, ch);
84 }
85 }
86 }
87 return true;
88 }
89
90 bool BuzulukskiDGausGorizontalOMP::PostProcessingImpl() {
91 if (output_image_.empty()) {
92 return false;
93 }
94
95 int64_t total_sum = 0;
96 for (const auto &val : output_image_) {
97 total_sum += static_cast<int64_t>(val);
98 }
99 GetOutput() = static_cast<int>(total_sum / static_cast<int64_t>(output_image_.size()));
100 return true;
101 }
102
103 } // namespace buzulukski_d_gaus_gorizontal
104