GCC Code Coverage Report


Directory: ./
File: tasks/buzulukski_d_gaus_gorizontal/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 0 44 0.0%
Functions: 0 7 0.0%
Branches: 0 16 0.0%

Line Branch Exec Source
1 #include "buzulukski_d_gaus_gorizontal/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/blocked_range.h>
4 #include <tbb/parallel_for.h>
5
6 #include <algorithm>
7 #include <array>
8 #include <cstddef>
9 #include <cstdint>
10
11 #include "buzulukski_d_gaus_gorizontal/common/include/common.hpp"
12
13 namespace buzulukski_d_gaus_gorizontal {
14
15 namespace {
16 constexpr int kChannels = 3;
17 constexpr int kKernelSize = 3;
18 constexpr int kKernelSum = 16;
19
20 using KernelRow = std::array<int, kKernelSize>;
21 constexpr std::array<KernelRow, kKernelSize> kKernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}};
22
23 uint8_t CalculatePixelTBB(const uint8_t *in, int py, int px, int w, int h, int ch) {
24 int sum = 0;
25 for (int ky = -1; ky <= 1; ++ky) {
26 for (int kx = -1; kx <= 1; ++kx) {
27 int ny = std::clamp(py + ky, 0, h - 1);
28 int nx = std::clamp(px + kx, 0, w - 1);
29
30 size_t idx = (((static_cast<size_t>(ny) * static_cast<size_t>(w)) + static_cast<size_t>(nx)) * kChannels) +
31 static_cast<size_t>(ch);
32
33 size_t row_idx = static_cast<size_t>(ky) + 1;
34 size_t col_idx = static_cast<size_t>(kx) + 1;
35 sum += static_cast<int>(in[idx]) * kKernel.at(row_idx).at(col_idx);
36 }
37 }
38 return static_cast<uint8_t>(sum / kKernelSum);
39 }
40 } // namespace
41
42 BuzulukskiDGausGorizontalTBB::BuzulukskiDGausGorizontalTBB(const InType &in) : BaseTask() {
43 SetTypeOfTask(GetStaticTypeOfTask());
44 GetInput() = in;
45 GetOutput() = 0;
46 }
47
48 bool BuzulukskiDGausGorizontalTBB::ValidationImpl() {
49 return GetInput() >= kKernelSize;
50 }
51
52 bool BuzulukskiDGausGorizontalTBB::PreProcessingImpl() {
53 width_ = GetInput();
54 height_ = GetInput();
55 const auto total_size = static_cast<std::size_t>(width_) * static_cast<std::size_t>(height_) * kChannels;
56 input_image_.assign(total_size, 100);
57 output_image_.assign(total_size, 0);
58 return true;
59 }
60
61 bool BuzulukskiDGausGorizontalTBB::RunImpl() {
62 const int h = height_;
63 const int w = width_;
64 const uint8_t *in_ptr = input_image_.data();
65 uint8_t *out_ptr = output_image_.data();
66
67 tbb::parallel_for(tbb::blocked_range<int>(0, h), [&](const tbb::blocked_range<int> &r) {
68 for (int py = r.begin(); py < r.end(); ++py) {
69 for (int px = 0; px < w; ++px) {
70 for (int ch = 0; ch < kChannels; ++ch) {
71 size_t out_idx =
72 (((static_cast<size_t>(py) * static_cast<size_t>(w)) + static_cast<size_t>(px)) * kChannels) +
73 static_cast<size_t>(ch);
74 out_ptr[out_idx] = CalculatePixelTBB(in_ptr, py, px, w, h, ch);
75 }
76 }
77 }
78 });
79 return true;
80 }
81
82 bool BuzulukskiDGausGorizontalTBB::PostProcessingImpl() {
83 if (output_image_.empty()) {
84 return false;
85 }
86 int64_t total_sum = 0;
87 for (const auto &val : output_image_) {
88 total_sum += static_cast<int64_t>(val);
89 }
90 GetOutput() = static_cast<int>(total_sum / static_cast<int64_t>(output_image_.size()));
91 return true;
92 }
93
94 } // namespace buzulukski_d_gaus_gorizontal
95