GCC Code Coverage Report


Directory: ./
File: tasks/chaschin_v_sobel_operator/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 52 52 100.0%
Functions: 6 6 100.0%
Branches: 39 74 52.7%

Line Branch Exec Source
1 #include "chaschin_v_sobel_operator/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cassert>
5 #include <cmath>
6 #include <cstddef>
7 #include <utility>
8 #include <vector>
9
10 #include "chaschin_v_sobel_operator/common/include/common.hpp"
11
12 namespace chaschin_v_sobel_operator {
13
14
1/2
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
152 ChaschinVSobelOperatorSEQ::ChaschinVSobelOperatorSEQ(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 auto in_copy = in;
17 GetInput() = std::move(in_copy);
18 this->GetOutput().clear();
19 152 }
20
21 152 bool ChaschinVSobelOperatorSEQ::ValidationImpl() {
22 const auto &in = GetInput();
23
24 const auto &image = std::get<0>(in);
25
26 152 return !image.empty();
27 }
28
29 152 bool ChaschinVSobelOperatorSEQ::PreProcessingImpl() {
30 152 return true;
31 }
32
33 152 bool ChaschinVSobelOperatorSEQ::RunImpl() {
34 const auto &in = GetInput();
35
36 const auto &mat = std::get<0>(in);
37 auto &out = GetOutput();
38
39 152 int n = std::get<1>(in);
40 152 int m = std::get<2>(in);
41
1/2
✓ Branch 2 taken 152 times.
✗ Branch 3 not taken.
152 std::vector<std::vector<float>> gray(n, std::vector<float>(m, 0.0F));
42
43
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 152 times.
3064 for (int i = 0; i < n; ++i) {
44
2/2
✓ Branch 0 taken 72672 times.
✓ Branch 1 taken 2912 times.
75584 for (int j = 0; j < m; ++j) {
45 72672 Pixel p = mat[i][j];
46 72672 gray[i][j] =
47 72672 (0.299F * static_cast<float>(p.r)) + (0.587F * static_cast<float>(p.g)) + (0.114F * static_cast<float>(p.b));
48 }
49 }
50
51
1/2
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
152 std::vector<float> post_process_gray = SobelSeq(gray);
52
53
1/2
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
152 out.resize(n);
54
55
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 152 times.
3064 for (int i = 0; i < n; ++i) {
56
1/2
✓ Branch 1 taken 2912 times.
✗ Branch 2 not taken.
2912 out[i].resize(m);
57
2/2
✓ Branch 0 taken 72672 times.
✓ Branch 1 taken 2912 times.
75584 for (int j = 0; j < m; ++j) {
58 72672 float v = post_process_gray[(i * m) + j];
59 72672 unsigned char c = static_cast<unsigned char>(std::clamp(v, 0.0F, 255.0F));
60 72672 out[i][j] = Pixel{.r = c, .g = c, .b = c};
61 }
62 }
63
64 152 return true;
65 152 }
66
67 152 bool ChaschinVSobelOperatorSEQ::PostProcessingImpl() {
68 152 return true;
69 }
70
71
1/2
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
152 std::vector<float> SobelSeq(const std::vector<std::vector<float>> &image) {
72 152 const int n = static_cast<int>(image.size());
73 assert(n > 0);
74 152 const int m = static_cast<int>(image[0].size());
75 assert(m > 0);
76
77
4/10
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
✓ Branch 3 taken 456 times.
✓ Branch 4 taken 152 times.
✓ Branch 5 taken 456 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
608 std::vector<std::vector<int>> k_kx = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};
78
79
4/10
✗ Branch 1 not taken.
✓ Branch 2 taken 152 times.
✓ Branch 3 taken 456 times.
✓ Branch 4 taken 152 times.
✓ Branch 5 taken 456 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
608 std::vector<std::vector<int>> k_ky = {{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}};
80
81 304 std::vector<float> out(static_cast<size_t>(n) * static_cast<size_t>(m), 0.0F);
82
83
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 152 times.
3064 for (int i = 0; i < n; ++i) {
84
2/2
✓ Branch 0 taken 72672 times.
✓ Branch 1 taken 2912 times.
75584 for (int j = 0; j < m; ++j) {
85 float gx = 0.0F;
86 float gy = 0.0F;
87
88 72672 const int i0 = std::max(0, i - 1);
89 72672 const int i1 = std::min(n - 1, i + 1);
90 72672 const int j0 = std::max(0, j - 1);
91 72672 const int j1 = std::min(m - 1, j + 1);
92
93
2/2
✓ Branch 0 taken 212192 times.
✓ Branch 1 taken 72672 times.
284864 for (int ni = i0; ni <= i1; ++ni) {
94
2/2
✓ Branch 0 taken 619712 times.
✓ Branch 1 taken 212192 times.
831904 for (int nj = j0; nj <= j1; ++nj) {
95 619712 const int di = ni - i;
96 619712 const int dj = nj - j;
97
98
1/2
✓ Branch 0 taken 619712 times.
✗ Branch 1 not taken.
619712 float v = image[ni][nj];
99
100 619712 volatile int vi = i;
101 619712 volatile int vj = j;
102
1/2
✓ Branch 0 taken 619712 times.
✗ Branch 1 not taken.
619712 if ((vi + vj) > -1) {
103 619712 gx += v * static_cast<float>(k_kx[di + 1][dj + 1]);
104 619712 gy += v * static_cast<float>(k_ky[di + 1][dj + 1]);
105 }
106 }
107 }
108 72672 out[(i * m) + j] = std::sqrt((gx * gx) + (gy * gy));
109 }
110 }
111
112 152 return out;
113
7/22
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 152 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 152 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 152 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 152 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 152 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 152 times.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
608 }
114
115 } // namespace chaschin_v_sobel_operator
116