GCC Code Coverage Report


Directory: ./
File: tasks/fatehov_k_gaussian/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 53 53 100.0%
Functions: 8 8 100.0%
Branches: 22 28 78.6%

Line Branch Exec Source
1 #include "fatehov_k_gaussian/tbb/include/ops_tbb.hpp"
2
3 #include <oneapi/tbb/blocked_range.h>
4 #include <oneapi/tbb/parallel_for.h>
5
6 #include <algorithm>
7 #include <cmath>
8 #include <cstddef>
9 #include <cstdint>
10 #include <vector>
11
12 #include "fatehov_k_gaussian/common/include/common.hpp"
13
14 namespace fatehov_k_gaussian {
15
16 namespace {
17
18 8700 float ConvolvePixel(const Image &image, const std::vector<float> &kernel, int kernel_size, int half, int y_coord,
19 int x_coord, int c_coord) {
20 8700 const int w = static_cast<int>(image.width);
21 8700 const int h = static_cast<int>(image.height);
22 8700 const int ch = static_cast<int>(image.channels);
23 float res = 0.0F;
24
25
2/2
✓ Branch 0 taken 60900 times.
✓ Branch 1 taken 8700 times.
69600 for (int ky = -half; ky <= half; ++ky) {
26
2/2
✓ Branch 0 taken 426300 times.
✓ Branch 1 taken 60900 times.
487200 for (int kx = -half; kx <= half; ++kx) {
27 426300 const int ny = std::clamp(y_coord + ky, 0, h - 1);
28 426300 const int nx = std::clamp(x_coord + kx, 0, w - 1);
29 426300 const float weight = kernel[((ky + half) * kernel_size) + (kx + half)];
30 426300 res += static_cast<float>(image.data[((ny * w + nx) * ch) + c_coord]) * weight;
31 }
32 }
33
34 8700 return res;
35 }
36
37 2900 void ProcessPixel(const Image &src, Image &dst, const std::vector<float> &kernel, int kernel_size, int half,
38 int y_coord, int x_coord) {
39 2900 const int ch = static_cast<int>(src.channels);
40 2900 const int w = static_cast<int>(src.width);
41
42
2/2
✓ Branch 0 taken 8700 times.
✓ Branch 1 taken 2900 times.
11600 for (int c_coord = 0; c_coord < ch; ++c_coord) {
43 8700 const float res = ConvolvePixel(src, kernel, kernel_size, half, y_coord, x_coord, c_coord);
44 8700 dst.data[((y_coord * w + x_coord) * ch) + c_coord] = static_cast<uint8_t>(std::clamp(res, 0.0F, 255.0F));
45 }
46 2900 }
47
48 void ProcessRow(const Image &src, Image &dst, const std::vector<float> &kernel, int kernel_size, int half,
49 int y_coord) {
50 180 const int w = static_cast<int>(src.width);
51
52
2/2
✓ Branch 0 taken 2900 times.
✓ Branch 1 taken 180 times.
3080 for (int x_coord = 0; x_coord < w; ++x_coord) {
53 2900 ProcessPixel(src, dst, kernel, kernel_size, half, y_coord, x_coord);
54 }
55 }
56
57 } // namespace
58
59
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 FatehovKGaussianTBB::FatehovKGaussianTBB(const InType &in) {
60 SetTypeOfTask(GetStaticTypeOfTask());
61 GetInput() = in;
62 12 }
63
64 12 bool FatehovKGaussianTBB::ValidationImpl() {
65 const auto &input = GetInput();
66
4/8
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 12 times.
12 return input.image.width > 0 && input.image.height > 0 && input.image.channels > 0 && !input.image.data.empty() &&
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 input.sigma > 0.0F;
68 }
69
70 12 bool FatehovKGaussianTBB::PreProcessingImpl() {
71 const auto &input = GetInput();
72 12 const float sigma = input.sigma;
73
74 12 kernel_size_ = (2 * static_cast<int>(std::ceil(3.0F * sigma))) + 1;
75 12 kernel_.resize(static_cast<std::size_t>(kernel_size_) * kernel_size_);
76
77 12 const int half = kernel_size_ / 2;
78 12 const float two_sigma_sq = 2.0F * sigma * sigma;
79 float sum = 0.0F;
80
81
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 12 times.
96 for (int i = -half; i <= half; ++i) {
82
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 84 times.
672 for (int j = -half; j <= half; ++j) {
83 588 const float val = std::exp(-(static_cast<float>((i * i) + (j * j))) / two_sigma_sq);
84 588 kernel_[((i + half) * kernel_size_) + (j + half)] = val;
85 588 sum += val;
86 }
87 }
88
89
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 12 times.
600 for (float &val : kernel_) {
90 588 val /= sum;
91 }
92
93 12 GetOutput() = Image(input.image.width, input.image.height, input.image.channels);
94
95 12 return true;
96 }
97
98 12 bool FatehovKGaussianTBB::RunImpl() {
99 const auto &input = GetInput();
100 auto &output = GetOutput();
101 12 const int h = static_cast<int>(input.image.height);
102 12 const int half = kernel_size_ / 2;
103 12 const int kernel_size = kernel_size_;
104 12 const auto &kernel = kernel_;
105
106 192 oneapi::tbb::parallel_for(oneapi::tbb::blocked_range<int>(0, h), [&](const oneapi::tbb::blocked_range<int> &range) {
107
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 180 times.
360 for (int y_coord = range.begin(); y_coord < range.end(); ++y_coord) {
108 180 ProcessRow(input.image, output, kernel, kernel_size, half, y_coord);
109 }
110 180 });
111
112 12 return true;
113 }
114
115 12 bool FatehovKGaussianTBB::PostProcessingImpl() {
116 12 return true;
117 }
118
119 } // namespace fatehov_k_gaussian
120