GCC Code Coverage Report


Directory: ./
File: tasks/kolotukhin_a_gaussian_blur/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 32 32 100.0%
Functions: 7 7 100.0%
Branches: 17 18 94.4%

Line Branch Exec Source
1 #include "kolotukhin_a_gaussian_blur/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/blocked_range2d.h>
4 #include <tbb/parallel_for.h>
5
6 #include <algorithm>
7 #include <array>
8 #include <cstddef>
9 #include <cstdint>
10 #include <vector>
11
12 #include "kolotukhin_a_gaussian_blur/common/include/common.hpp"
13
14 namespace kolotukhin_a_gaussian_blur {
15
16
1/2
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
16 KolotukhinAGaussinBlureTBB::KolotukhinAGaussinBlureTBB(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 GetInput() = in;
19 GetOutput().clear();
20 16 }
21
22 16 bool KolotukhinAGaussinBlureTBB::ValidationImpl() {
23 const auto &pixel_data = get<0>(GetInput());
24 16 const auto img_width = get<1>(GetInput());
25 16 const auto img_height = get<2>(GetInput());
26
27 16 return static_cast<std::size_t>(img_height) * static_cast<std::size_t>(img_width) == pixel_data.size();
28 }
29
30 16 bool KolotukhinAGaussinBlureTBB::PreProcessingImpl() {
31 16 const auto img_width = get<1>(GetInput());
32 16 const auto img_height = get<2>(GetInput());
33
34 16 GetOutput().assign(static_cast<std::size_t>(img_height) * static_cast<std::size_t>(img_width), 0);
35 16 return true;
36 }
37
38 16 bool KolotukhinAGaussinBlureTBB::RunImpl() {
39 const auto &pixel_data = get<0>(GetInput());
40 16 const auto img_width = get<1>(GetInput());
41 16 const auto img_height = get<2>(GetInput());
42
43 const static std::array<std::array<int, 3>, 3> kKernel = {{{{1, 2, 1}}, {{2, 4, 2}}, {{1, 2, 1}}}};
44 const static int kSum = 16;
45
46 auto &output = GetOutput();
47
48 16 tbb::parallel_for(tbb::blocked_range2d<int>(0, img_height, 0, img_width),
49 172 [&](const tbb::blocked_range2d<int> &range) {
50
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 156 times.
312 for (int row = range.rows().begin(); row < range.rows().end(); row++) {
51
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 156 times.
312 for (int col = range.cols().begin(); col < range.cols().end(); col++) {
52 int acc = 0;
53
2/2
✓ Branch 0 taken 468 times.
✓ Branch 1 taken 156 times.
624 for (int dy = -1; dy <= 1; dy++) {
54
2/2
✓ Branch 0 taken 1404 times.
✓ Branch 1 taken 468 times.
1872 for (int dx = -1; dx <= 1; dx++) {
55 1404 std::uint8_t pixel = GetPixel(pixel_data, img_width, img_height, col + dx, row + dy);
56 1404 acc += kKernel.at(1 + dy).at(1 + dx) * static_cast<int>(pixel);
57 }
58 }
59 156 output[(static_cast<std::size_t>(row) * static_cast<std::size_t>(img_width)) + static_cast<std::size_t>(col)] =
60 156 static_cast<std::uint8_t>(acc / kSum);
61 }
62 }
63 156 });
64
65 16 return true;
66 }
67
68 1404 std::uint8_t KolotukhinAGaussinBlureTBB::GetPixel(const std::vector<std::uint8_t> &pixel_data, int img_width,
69 int img_height, int pos_x, int pos_y) {
70
4/4
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 1260 times.
✓ Branch 2 taken 972 times.
✓ Branch 3 taken 432 times.
1548 std::size_t x = static_cast<std::size_t>(std::max(0, std::min(pos_x, img_width - 1)));
71
4/4
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 1248 times.
✓ Branch 2 taken 936 times.
✓ Branch 3 taken 468 times.
1560 std::size_t y = static_cast<std::size_t>(std::max(0, std::min(pos_y, img_height - 1)));
72 1404 return pixel_data[(y * static_cast<std::size_t>(img_width)) + x];
73 }
74
75 16 bool KolotukhinAGaussinBlureTBB::PostProcessingImpl() {
76 16 return true;
77 }
78
79 } // namespace kolotukhin_a_gaussian_blur
80