GCC Code Coverage Report


Directory: ./
File: tasks/morozov_n_sobels_filter/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 32 32 100.0%
Functions: 7 7 100.0%
Branches: 13 20 65.0%

Line Branch Exec Source
1 #include "morozov_n_sobels_filter/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <array>
5 #include <cmath>
6 #include <cstddef>
7 #include <cstdint>
8
9 #include "morozov_n_sobels_filter/common/include/common.hpp"
10
11 namespace morozov_n_sobels_filter {
12
13
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 MorozovNSobelsFilterSEQ::MorozovNSobelsFilterSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16
17 40 result_image_.height = in.height;
18 40 result_image_.width = in.width;
19
1/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
40 result_image_.pixels.resize(result_image_.height * result_image_.width, 0);
20 40 }
21
22 40 bool MorozovNSobelsFilterSEQ::ValidationImpl() {
23 const Image &input = GetInput();
24
3/6
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
40 return (input.height == result_image_.height) && (input.width == result_image_.width) &&
25 40 (input.pixels.size() == result_image_.pixels.size());
26 }
27
28 40 bool MorozovNSobelsFilterSEQ::PreProcessingImpl() {
29 40 return true;
30 }
31
32 40 bool MorozovNSobelsFilterSEQ::RunImpl() {
33 const Image &input = GetInput();
34 40 Filter(input);
35 GetOutput() = result_image_;
36 40 return true;
37 }
38
39 40 bool MorozovNSobelsFilterSEQ::PostProcessingImpl() {
40 40 return true;
41 }
42
43 40 void MorozovNSobelsFilterSEQ::Filter(const Image &img) {
44
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 40 times.
224 for (size_t id_y = 1; id_y < img.height - 1; id_y++) {
45
2/2
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 184 times.
1248 for (size_t id_x = 1; id_x < img.width - 1; id_x++) {
46 1064 size_t pixel_id = (id_y * img.width) + id_x;
47 1064 result_image_.pixels[pixel_id] = CalculateNewPixelColor(img, id_x, id_y);
48 }
49 }
50 40 }
51
52 1064 uint8_t MorozovNSobelsFilterSEQ::CalculateNewPixelColor(const Image &img, size_t x, size_t y) {
53 constexpr int kRadX = 1;
54 constexpr int kRadY = 1;
55 1064 constexpr size_t kZero = 0;
56
57 int grad_x = 0;
58 int grad_y = 0;
59
60
2/2
✓ Branch 0 taken 3192 times.
✓ Branch 1 taken 1064 times.
4256 for (int row_offset = -kRadY; row_offset <= kRadY; row_offset++) {
61
2/2
✓ Branch 0 taken 9576 times.
✓ Branch 1 taken 3192 times.
12768 for (int col_offset = -kRadX; col_offset <= kRadX; col_offset++) {
62 9576 size_t id_x = std::clamp(x + col_offset, kZero, img.width - 1);
63 9576 size_t id_y = std::clamp(y + row_offset, kZero, img.height - 1);
64 9576 size_t pixel_id = (id_y * img.width) + id_x;
65
66 9576 grad_x += img.pixels[pixel_id] * kKernelX.at(row_offset + kRadY).at(col_offset + kRadX);
67 9576 grad_y += img.pixels[pixel_id] * kKernelY.at(row_offset + kRadY).at(col_offset + kRadX);
68 }
69 }
70
71 1064 int gradient = static_cast<int>(std::sqrt((grad_x * grad_x) + (grad_y * grad_y)));
72 gradient = std::clamp(gradient, 0, 255);
73
74 1064 return static_cast<uint8_t>(gradient);
75 }
76 } // namespace morozov_n_sobels_filter
77