GCC Code Coverage Report


Directory: ./
File: tasks/nikolaev_d_block_linear_image_filtering/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 18 22 81.8%
Functions: 5 6 83.3%
Branches: 1 2 50.0%

Line Branch Exec Source
1 #include "nikolaev_d_block_linear_image_filtering/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 "nikolaev_d_block_linear_image_filtering/common/include/common.hpp"
12
13 namespace nikolaev_d_block_linear_image_filtering {
14
15
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 NikolaevDBlockLinearImageFilteringOMP::NikolaevDBlockLinearImageFilteringOMP(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17 GetInput() = in;
18 20 GetOutput() = std::vector<uint8_t>();
19 20 }
20
21 20 bool NikolaevDBlockLinearImageFilteringOMP::ValidationImpl() {
22 20 const auto img_width = get<0>(GetInput());
23 20 const auto img_height = get<1>(GetInput());
24 const auto &pixel_data = get<2>(GetInput());
25
26 20 return static_cast<std::size_t>(img_width) * static_cast<std::size_t>(img_height) * 3 == pixel_data.size();
27 }
28
29 20 bool NikolaevDBlockLinearImageFilteringOMP::PreProcessingImpl() {
30 20 return true;
31 }
32
33 std::uint8_t NikolaevDBlockLinearImageFilteringOMP::GetPixel(const std::vector<uint8_t> &data, int w, int h, int nx,
34 int ny, int ch) {
35 int ix = std::clamp(nx, 0, w - 1);
36 int iy = std::clamp(ny, 0, h - 1);
37 return data[((iy * w + ix) * 3) + ch];
38 }
39
40 20 bool NikolaevDBlockLinearImageFilteringOMP::RunImpl() {
41 20 const int width = std::get<0>(GetInput());
42 20 const int height = std::get<1>(GetInput());
43 const auto &src = std::get<2>(GetInput());
44
45 auto &dst = GetOutput();
46 20 dst.assign(src.size(), 0);
47
48 20 const std::array<std::array<int, 3>, 3> kernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}};
49 const int sum = 16;
50
51 20 #pragma omp parallel for collapse(2) schedule(static) default(none) shared(width, height, src, dst, kernel, sum)
52 for (int ny = 0; ny < height; ++ny) {
53 for (int nx = 0; nx < width; ++nx) {
54 for (int ch = 0; ch < 3; ++ch) {
55 int acc = 0;
56 for (int ky = -1; ky <= 1; ++ky) {
57 for (int kx = -1; kx <= 1; ++kx) {
58 acc += GetPixel(src, width, height, nx + kx, ny + ky, ch) * kernel.at(ky + 1).at(kx + 1);
59 }
60 }
61
62 int res = (acc + 8) / sum;
63 dst[((ny * width + nx) * 3) + ch] = static_cast<uint8_t>(std::clamp(res, 0, 255));
64 }
65 }
66 }
67 20 return true;
68 }
69
70 20 bool NikolaevDBlockLinearImageFilteringOMP::PostProcessingImpl() {
71 20 return true;
72 }
73
74 } // namespace nikolaev_d_block_linear_image_filtering
75