GCC Code Coverage Report


Directory: ./
File: tasks/vdovin_a_gauss_block/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 39 40 97.5%
Functions: 7 7 100.0%
Branches: 23 30 76.7%

Line Branch Exec Source
1 #include "vdovin_a_gauss_block/tbb/include/ops_tbb.hpp"
2
3 #include <algorithm>
4 #include <array>
5 #include <cstdint>
6 #include <vector>
7
8 #include "oneapi/tbb/blocked_range2d.h"
9 #include "oneapi/tbb/parallel_for.h"
10 #include "vdovin_a_gauss_block/common/include/common.hpp"
11
12 namespace vdovin_a_gauss_block {
13
14 namespace {
15 constexpr int kChannels = 3;
16 constexpr int kKernelSize = 3;
17 constexpr int kKernelSum = 16;
18 constexpr std::array<std::array<int, kKernelSize>, kKernelSize> kKernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}};
19 } // namespace
20
21 40 VdovinAGaussBlockTBB::VdovinAGaussBlockTBB(const InType &in) {
22 SetTypeOfTask(GetStaticTypeOfTask());
23 40 GetInput() = in;
24 GetOutput() = 0;
25 40 }
26
27 40 bool VdovinAGaussBlockTBB::ValidationImpl() {
28 40 return GetInput() >= 3;
29 }
30
31 40 bool VdovinAGaussBlockTBB::PreProcessingImpl() {
32 40 width_ = GetInput();
33 40 height_ = GetInput();
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (width_ < 3 || height_ < 3) {
35 input_image_.clear();
36 output_image_.clear();
37 return false;
38 }
39 40 int total = width_ * height_ * kChannels;
40 40 input_image_.assign(total, 100);
41 40 output_image_.assign(total, 0);
42 40 return true;
43 }
44
45 52796 void VdovinAGaussBlockTBB::ApplyGaussianToPixel(int py, int px) {
46
2/2
✓ Branch 0 taken 158388 times.
✓ Branch 1 taken 52796 times.
211184 for (int ch = 0; ch < kChannels; ch++) {
47 int sum = 0;
48
2/2
✓ Branch 0 taken 475164 times.
✓ Branch 1 taken 158388 times.
633552 for (int ky = -1; ky <= 1; ky++) {
49
2/2
✓ Branch 0 taken 1425492 times.
✓ Branch 1 taken 475164 times.
1900656 for (int kx = -1; kx <= 1; kx++) {
50 1425492 int ny = std::clamp(py + ky, 0, height_ - 1);
51 1425492 int nx = std::clamp(px + kx, 0, width_ - 1);
52 1425492 sum += input_image_[(((ny * width_) + nx) * kChannels) + ch] * kKernel.at(ky + 1).at(kx + 1);
53 }
54 }
55
1/2
✓ Branch 0 taken 158388 times.
✗ Branch 1 not taken.
316776 output_image_[(((py * width_) + px) * kChannels) + ch] = static_cast<uint8_t>(std::clamp(sum / kKernelSum, 0, 255));
56 }
57 52796 }
58
59
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 bool VdovinAGaussBlockTBB::RunImpl() {
60
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 if (input_image_.empty() || output_image_.empty()) {
61 return false;
62 }
63
64
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 int block_height = std::max(1, height_ / 4);
65
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
40 int block_width = std::max(1, width_ / 4);
66
67 80 tbb::parallel_for(tbb::blocked_range2d<int>(0, height_, block_height, 0, width_, block_width),
68 1060 [this](const tbb::blocked_range2d<int> &range) {
69
2/2
✓ Branch 0 taken 4028 times.
✓ Branch 1 taken 1020 times.
5048 for (int py = range.rows().begin(); py < range.rows().end(); py++) {
70
2/2
✓ Branch 0 taken 52796 times.
✓ Branch 1 taken 4028 times.
56824 for (int px = range.cols().begin(); px < range.cols().end(); px++) {
71 52796 ApplyGaussianToPixel(py, px);
72 }
73 }
74 1020 });
75
76 40 return true;
77 }
78
79
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 bool VdovinAGaussBlockTBB::PostProcessingImpl() {
80
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (output_image_.empty()) {
81 return false;
82 }
83 auto total = static_cast<int64_t>(output_image_.size());
84 if (total == 0) {
85 return false;
86 }
87 int64_t sum = 0;
88
2/2
✓ Branch 0 taken 158388 times.
✓ Branch 1 taken 40 times.
158428 for (int64_t idx = 0; idx < total; idx++) {
89 158388 sum += output_image_[idx];
90 }
91 40 GetOutput() = static_cast<int>(sum / total);
92 40 return true;
93 }
94
95 } // namespace vdovin_a_gauss_block
96