GCC Code Coverage Report


Directory: ./
File: tasks/morozov_n_sobels_filter/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 36 36 100.0%
Functions: 8 8 100.0%
Branches: 15 24 62.5%

Line Branch Exec Source
1 #include "morozov_n_sobels_filter/tbb/include/ops_tbb.hpp"
2
3 #include <oneapi/tbb/blocked_range2d.h>
4 #include <oneapi/tbb/global_control.h>
5 #include <oneapi/tbb/parallel_for.h>
6
7 #include <algorithm>
8 #include <array>
9 #include <cmath>
10 #include <cstddef>
11 #include <cstdint>
12
13 #include "morozov_n_sobels_filter/common/include/common.hpp"
14 #include "util/include/util.hpp"
15
16 namespace morozov_n_sobels_filter {
17
18
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 MorozovNSobelsFilterTBB::MorozovNSobelsFilterTBB(const InType &in) {
19 SetTypeOfTask(GetStaticTypeOfTask());
20 GetInput() = in;
21
22 20 result_image_.height = in.height;
23 20 result_image_.width = in.width;
24
1/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
20 result_image_.pixels.resize(result_image_.height * result_image_.width, 0);
25 20 }
26
27 20 bool MorozovNSobelsFilterTBB::ValidationImpl() {
28 const Image &input = GetInput();
29
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
20 return (input.height == result_image_.height) && (input.width == result_image_.width) &&
30
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
40 (input.pixels.size() == result_image_.pixels.size()) && (ppc::util::GetNumThreads() >= 1);
31 }
32
33 20 bool MorozovNSobelsFilterTBB::PreProcessingImpl() {
34 20 return true;
35 }
36
37 20 bool MorozovNSobelsFilterTBB::RunImpl() {
38 const Image &input = GetInput();
39 20 Filter(input);
40 GetOutput() = result_image_;
41 20 return true;
42 }
43
44 20 bool MorozovNSobelsFilterTBB::PostProcessingImpl() {
45 20 return true;
46 }
47
48 20 void MorozovNSobelsFilterTBB::Filter(const Image &img) {
49 20 oneapi::tbb::global_control control(oneapi::tbb::global_control::max_allowed_parallelism, ppc::util::GetNumThreads());
50
51 40 oneapi::tbb::parallel_for(oneapi::tbb::blocked_range2d<size_t>(1, img.height - 1, 1, img.width - 1),
52
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
552 [&](const oneapi::tbb::blocked_range2d<size_t> &range) {
53
2/2
✓ Branch 0 taken 532 times.
✓ Branch 1 taken 532 times.
1064 for (size_t id_y = range.rows().begin(); id_y != range.rows().end(); ++id_y) {
54
2/2
✓ Branch 0 taken 532 times.
✓ Branch 1 taken 532 times.
1064 for (size_t id_x = range.cols().begin(); id_x != range.cols().end(); ++id_x) {
55 532 const size_t pixel_id = (id_y * img.width) + id_x;
56 532 result_image_.pixels[pixel_id] = CalculateNewPixelColor(img, id_x, id_y);
57 }
58 }
59 532 });
60 20 }
61
62 532 uint8_t MorozovNSobelsFilterTBB::CalculateNewPixelColor(const Image &img, size_t x, size_t y) {
63 constexpr int kRadX = 1;
64 constexpr int kRadY = 1;
65 532 constexpr size_t kZero = 0;
66
67 int grad_x = 0;
68 int grad_y = 0;
69
70
2/2
✓ Branch 0 taken 1596 times.
✓ Branch 1 taken 532 times.
2128 for (int row_offset = -kRadY; row_offset <= kRadY; row_offset++) {
71
2/2
✓ Branch 0 taken 4788 times.
✓ Branch 1 taken 1596 times.
6384 for (int col_offset = -kRadX; col_offset <= kRadX; col_offset++) {
72 4788 size_t id_x = std::clamp(x + col_offset, kZero, img.width - 1);
73 4788 size_t id_y = std::clamp(y + row_offset, kZero, img.height - 1);
74 4788 size_t pixel_id = (id_y * img.width) + id_x;
75
76 4788 grad_x += img.pixels[pixel_id] * kKernelX.at(row_offset + kRadY).at(col_offset + kRadX);
77
78 4788 grad_y += img.pixels[pixel_id] * kKernelY.at(row_offset + kRadY).at(col_offset + kRadX);
79 }
80 }
81
82 532 int gradient = static_cast<int>(std::sqrt((grad_x * grad_x) + (grad_y * grad_y)));
83
84 gradient = std::clamp(gradient, 0, 255);
85
86 532 return static_cast<uint8_t>(gradient);
87 }
88
89 } // namespace morozov_n_sobels_filter
90