GCC Code Coverage Report


Directory: ./
File: tasks/krykov_e_sobel_op/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 6 6 100.0%
Branches: 14 18 77.8%

Line Branch Exec Source
1 #include "krykov_e_sobel_op/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/tbb.h>
4
5 #include <array>
6 #include <cmath>
7 #include <cstddef>
8 #include <vector>
9
10 #include "krykov_e_sobel_op/common/include/common.hpp"
11
12 namespace krykov_e_sobel_op {
13
14
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 KrykovESobelOpTBB::KrykovESobelOpTBB(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17 GetOutput().clear();
18 12 }
19
20 12 bool KrykovESobelOpTBB::ValidationImpl() {
21 const auto &img = GetInput();
22
3/6
✓ 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.
12 return img.width > 2 && img.height > 2 && static_cast<int>(img.data.size()) == img.width * img.height;
23 }
24
25 12 bool KrykovESobelOpTBB::PreProcessingImpl() {
26 const auto &img = GetInput();
27
28 12 width_ = img.width;
29 12 height_ = img.height;
30
31 12 grayscale_.resize(static_cast<size_t>(width_) * static_cast<size_t>(height_));
32 // RGB → grayscale
33
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 12 times.
204 for (int i = 0; i < width_ * height_; ++i) {
34 192 const Pixel &p = img.data[i];
35 192 grayscale_[i] = static_cast<int>((0.299 * p.r) + (0.587 * p.g) + (0.114 * p.b));
36 }
37 12 GetOutput().assign(static_cast<size_t>(width_) * static_cast<size_t>(height_), 0);
38 12 return true;
39 }
40
41 12 bool KrykovESobelOpTBB::RunImpl() {
42 12 const std::array<std::array<int, 3>, 3> gx_kernel = {{{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}}};
43 12 const std::array<std::array<int, 3>, 3> gy_kernel = {{{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}}};
44
45 auto &output = GetOutput();
46 12 const auto &gray = grayscale_;
47 12 const int h = height_;
48 12 const int w = width_;
49
50 36 tbb::parallel_for(tbb::blocked_range<int>(1, h - 1), [&](const tbb::blocked_range<int> &range) {
51
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
48 for (int row = range.begin(); row != range.end(); ++row) {
52
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int col = 1; col < w - 1; ++col) {
53 int gx = 0;
54 int gy = 0;
55
56
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 48 times.
192 for (int ky = -1; ky <= 1; ++ky) {
57
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 144 times.
576 for (int kx = -1; kx <= 1; ++kx) {
58 432 int pixel = gray[((row + ky) * w) + (col + kx)];
59 432 gx += pixel * gx_kernel.at(ky + 1).at(kx + 1);
60 432 gy += pixel * gy_kernel.at(ky + 1).at(kx + 1);
61 }
62 }
63
64 48 int magnitude = static_cast<int>(std::sqrt(static_cast<double>((gx * gx) + (gy * gy))));
65 48 output[(row * w) + col] = magnitude;
66 }
67 }
68 24 });
69
70 12 return true;
71 }
72
73 12 bool KrykovESobelOpTBB::PostProcessingImpl() {
74 12 return true;
75 }
76
77 } // namespace krykov_e_sobel_op
78