GCC Code Coverage Report


Directory: ./
File: tasks/fedoseev_linear_image_filtering_vertical/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 22 23 95.7%
Functions: 5 5 100.0%
Branches: 6 14 42.9%

Line Branch Exec Source
1 #include "fedoseev_linear_image_filtering_vertical/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <algorithm>
6 #include <array>
7 #include <cstddef>
8 #include <vector>
9
10 #include "fedoseev_linear_image_filtering_vertical/common/include/common.hpp"
11
12 namespace fedoseev_linear_image_filtering_vertical {
13
14 namespace {
15 int GetPixel(const std::vector<int> &src, int w, int h, int col, int row) {
16 col = std::clamp(col, 0, w - 1);
17 row = std::clamp(row, 0, h - 1);
18 return src[(static_cast<size_t>(row) * static_cast<size_t>(w)) + static_cast<size_t>(col)];
19 }
20 } // namespace
21
22
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 LinearImageFilteringVerticalOMP::LinearImageFilteringVerticalOMP(const InType &in) {
23 SetTypeOfTask(GetStaticTypeOfTask());
24 GetInput() = in;
25 80 GetOutput() = InType{};
26 80 }
27
28 80 bool LinearImageFilteringVerticalOMP::ValidationImpl() {
29 const InType &input = GetInput();
30
2/4
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
80 if (input.width < 3 || input.height < 3) {
31 return false;
32 }
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80 times.
80 if (input.data.size() != static_cast<size_t>(input.width) * static_cast<size_t>(input.height)) {
34 return false;
35 }
36 return true;
37 }
38
39 80 bool LinearImageFilteringVerticalOMP::PreProcessingImpl() {
40 const InType &input = GetInput();
41 80 OutType output;
42 80 output.width = input.width;
43 80 output.height = input.height;
44
2/6
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
80 output.data.resize(static_cast<size_t>(input.width) * static_cast<size_t>(input.height), 0);
45 GetOutput() = output;
46 80 return true;
47 }
48
49 80 bool LinearImageFilteringVerticalOMP::RunImpl() {
50 const InType &input = GetInput();
51 OutType &output = GetOutput();
52
53 80 int w = input.width;
54 80 int h = input.height;
55 80 const std::vector<int> &src = input.data;
56 80 std::vector<int> &dst = output.data;
57
58 80 const std::array<std::array<int, 3>, 3> kernel = {{{{1, 2, 1}}, {{2, 4, 2}}, {{1, 2, 1}}}};
59 const int kernel_sum = 16;
60 const int block_width = 64;
61
62 80 #pragma omp parallel for schedule(static) default(none) shared(w, h, src, dst, kernel, kernel_sum, block_width)
63 for (int col_start = 0; col_start < w; col_start += block_width) {
64 int col_end = std::min(col_start + block_width, w);
65 for (int row = 0; row < h; ++row) {
66 for (int col = col_start; col < col_end; ++col) {
67 int sum = 0;
68 for (int ky = 0; ky < 3; ++ky) {
69 for (int kx = 0; kx < 3; ++kx) {
70 int px = col + kx - 1;
71 int py = row + ky - 1;
72 int pixel = GetPixel(src, w, h, px, py);
73 sum += pixel * kernel.at(ky).at(kx);
74 }
75 }
76 dst[(static_cast<size_t>(row) * static_cast<size_t>(w)) + static_cast<size_t>(col)] = sum / kernel_sum;
77 }
78 }
79 }
80
81 80 return true;
82 }
83
84 80 bool LinearImageFilteringVerticalOMP::PostProcessingImpl() {
85 80 return true;
86 }
87
88 } // namespace fedoseev_linear_image_filtering_vertical
89