GCC Code Coverage Report


Directory: ./
File: tasks/kopilov_d_vertical_gauss_filter/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 39 40 97.5%
Functions: 6 6 100.0%
Branches: 21 28 75.0%

Line Branch Exec Source
1 #include "kopilov_d_vertical_gauss_filter/tbb/include/ops_tbb.hpp"
2
3 #include <oneapi/tbb/blocked_range2d.h>
4 #include <oneapi/tbb/parallel_for.h>
5
6 #include <array>
7 #include <cstddef>
8 #include <cstdint>
9 #include <utility>
10 #include <vector>
11
12 #include "kopilov_d_vertical_gauss_filter/common/include/common.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 GetPixelMirroredTBB(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 1404 if (new_x < 0) {
25 new_x = -new_x - 1;
26
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 1092 times.
1248 } else if (new_x >= width) {
27 156 new_x = (2 * width) - new_x - 1;
28 }
29
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 1248 times.
1404 if (new_y < 0) {
30 new_y = -new_y - 1;
31
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 1092 times.
1248 } else if (new_y >= height) {
32 156 new_y = (2 * height) - new_y - 1;
33 }
34 1404 auto idx = (static_cast<size_t>(new_y) * static_cast<size_t>(width)) + static_cast<size_t>(new_x);
35 1404 return image[idx];
36 }
37 } // namespace
38
39
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 KopilovDVerticalGaussFilterTBB::KopilovDVerticalGaussFilterTBB(const InType &in) {
40 SetTypeOfTask(GetStaticTypeOfTask());
41 GetInput() = in;
42 20 GetOutput() = OutType{};
43 20 }
44
45 20 bool KopilovDVerticalGaussFilterTBB::ValidationImpl() {
46 const auto &in = GetInput();
47
48
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 if (in.width <= 0 || in.height <= 0) {
49 return false;
50 }
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (in.data.size() != static_cast<size_t>(in.width) * static_cast<size_t>(in.height)) {
52 return false;
53 }
54 return true;
55 }
56
57 20 bool KopilovDVerticalGaussFilterTBB::PreProcessingImpl() {
58 20 return true;
59 }
60
61 20 bool KopilovDVerticalGaussFilterTBB::RunImpl() {
62 const auto &in = GetInput();
63 20 int width = in.width;
64 20 int height = in.height;
65 20 const std::vector<uint8_t> &source_image = in.data;
66 20 std::vector<uint8_t> destination_image(static_cast<size_t>(width) * static_cast<size_t>(height));
67
68
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
176 tbb::parallel_for(tbb::blocked_range2d<int>(0, height, 0, width), [&](const tbb::blocked_range2d<int> &range) {
69
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 156 times.
312 for (int j = range.rows().begin(); j != range.rows().end(); ++j) {
70
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 156 times.
312 for (int i = range.cols().begin(); i != range.cols().end(); ++i) {
71 int pixel_sum = 0;
72
73
2/2
✓ Branch 0 taken 468 times.
✓ Branch 1 taken 156 times.
624 for (size_t ky = 0; ky < 3; ++ky) {
74
2/2
✓ Branch 0 taken 1404 times.
✓ Branch 1 taken 468 times.
1872 for (size_t kx = 0; kx < 3; ++kx) {
75 1404 int current_x = i + static_cast<int>(kx) - 1;
76 1404 int current_y = j + static_cast<int>(ky) - 1;
77 1404 pixel_sum +=
78
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 1248 times.
2808 kGaussKernel.at(ky).at(kx) * GetPixelMirroredTBB(source_image, current_x, current_y, width, height);
79 }
80 }
81
82 156 auto out_idx = (static_cast<size_t>(j) * static_cast<size_t>(width)) + static_cast<size_t>(i);
83 156 destination_image[out_idx] = static_cast<uint8_t>(pixel_sum / kDivisor);
84 }
85 }
86 156 });
87
88 20 GetOutput().width = width;
89 20 GetOutput().height = height;
90 20 GetOutput().data = std::move(destination_image);
91 20 return true;
92 }
93
94 20 bool KopilovDVerticalGaussFilterTBB::PostProcessingImpl() {
95 20 return true;
96 }
97
98 } // namespace kopilov_d_vertical_gauss_filter
99