GCC Code Coverage Report


Directory: ./
File: tasks/belov_e_sobel/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 26 26 100.0%
Functions: 6 6 100.0%
Branches: 13 22 59.1%

Line Branch Exec Source
1 #include "belov_e_sobel/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/blocked_range2d.h>
4 #include <tbb/parallel_for.h>
5
6 #include <algorithm>
7 #include <cmath>
8 #include <cstddef>
9 #include <cstdint>
10 #include <vector>
11
12 #include "belov_e_sobel/common/include/common.hpp"
13
14 namespace belov_e_sobel {
15
16
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 BelovESobelTBB::BelovESobelTBB(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 GetInput() = in;
19 GetOutput() = in;
20 8 }
21
22
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 bool BelovESobelTBB::ValidationImpl() {
23
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 return !std::get<0>(GetInput()).empty() && (std::get<1>(GetInput()) > 0) && (std::get<2>(GetInput()) > 0);
24 }
25
26 8 bool BelovESobelTBB::PreProcessingImpl() {
27 8 return true;
28 }
29
30 8 bool BelovESobelTBB::RunImpl() {
31 const std::vector<uint8_t> &input = std::get<0>(GetInput());
32 std::vector<uint8_t> &output = std::get<0>(GetOutput());
33 8 int width = std::get<1>(GetInput());
34 8 int height = std::get<2>(GetInput());
35
36 auto get_px = [&](int col, int row) -> float {
37 3314032 int clamped_x = std::clamp(col, 0, width - 1);
38 3314032 int clamped_y = std::clamp(row, 0, height - 1);
39 3314032 return static_cast<float>(input[(static_cast<std::size_t>(clamped_y) * width) + clamped_x]);
40 8 };
41
42 2964 tbb::parallel_for(tbb::blocked_range2d<int>(0, height, 0, width), [&](const tbb::blocked_range2d<int> &r) {
43
2/2
✓ Branch 0 taken 87989 times.
✓ Branch 1 taken 2956 times.
90945 for (int row = r.rows().begin(); row < r.rows().end(); ++row) {
44
2/2
✓ Branch 0 taken 3314032 times.
✓ Branch 1 taken 87989 times.
3402021 for (int col = r.cols().begin(); col < r.cols().end(); ++col) {
45 3314032 float gx = (-1 * get_px(col - 1, row - 1)) + (1 * get_px(col + 1, row - 1)) + (-2 * get_px(col - 1, row)) +
46 3314032 (2 * get_px(col + 1, row)) + (-1 * get_px(col - 1, row + 1)) + (1 * get_px(col + 1, row + 1));
47
48 3314032 float gy = (-1 * get_px(col - 1, row - 1)) - (2 * get_px(col, row - 1)) - (1 * get_px(col + 1, row - 1)) +
49 3314032 (1 * get_px(col - 1, row + 1)) + (2 * get_px(col, row + 1)) + (1 * get_px(col + 1, row + 1));
50
51 3314032 float magnitude = std::sqrt((gx * gx) + (gy * gy));
52 3314032 output[(static_cast<std::size_t>(row) * width) + col] = static_cast<uint8_t>(std::min(255.0F, magnitude));
53 }
54 }
55 2956 });
56
57 8 return true;
58 }
59
60
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 bool BelovESobelTBB::PostProcessingImpl() {
61
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 return !std::get<0>(GetOutput()).empty() && (std::get<1>(GetOutput()) > 0) && (std::get<2>(GetOutput()) > 0);
62 }
63
64 } // namespace belov_e_sobel
65