GCC Code Coverage Report


Directory: ./
File: tasks/shilin_n_gauss_filter_vertical_split/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 40 41 97.6%
Functions: 6 7 85.7%
Branches: 18 26 69.2%

Line Branch Exec Source
1 #include "shilin_n_gauss_filter_vertical_split/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <array>
5 #include <cstddef>
6 #include <cstdint>
7 #include <vector>
8
9 #include "shilin_n_gauss_filter_vertical_split/common/include/common.hpp"
10
11 namespace shilin_n_gauss_filter_vertical_split {
12
13
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 ShilinNGaussFilterVerticalSplitSEQ::ShilinNGaussFilterVerticalSplitSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16 56 GetOutput() = std::vector<uint8_t>();
17 56 }
18
19 56 bool ShilinNGaussFilterVerticalSplitSEQ::ValidationImpl() {
20 const InType &input = GetInput();
21
3/6
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
56 if (input.width <= 0 || input.height <= 0 || input.channels <= 0) {
22 return false;
23 }
24
25 56 size_t expected_size =
26 56 static_cast<size_t>(input.width) * static_cast<size_t>(input.height) * static_cast<size_t>(input.channels);
27 56 return input.pixels.size() == expected_size;
28 }
29
30 56 bool ShilinNGaussFilterVerticalSplitSEQ::PreProcessingImpl() {
31 const InType &input = GetInput();
32 56 size_t output_size =
33 56 static_cast<size_t>(input.width) * static_cast<size_t>(input.height) * static_cast<size_t>(input.channels);
34 56 GetOutput() = std::vector<uint8_t>(output_size, 0);
35 56 return true;
36 }
37
38 56 bool ShilinNGaussFilterVerticalSplitSEQ::RunImpl() {
39 const InType &input = GetInput();
40 std::vector<uint8_t> &output = GetOutput();
41
42 56 ApplyGaussianKernel(input.pixels, output, input.width, input.height, input.channels);
43
44 56 return true;
45 }
46
47 56 bool ShilinNGaussFilterVerticalSplitSEQ::PostProcessingImpl() {
48 56 return !GetOutput().empty();
49 }
50
51 double ShilinNGaussFilterVerticalSplitSEQ::GetPixelValue(const std::vector<uint8_t> &pixels, int x, int y, int width,
52 int height, int channels, int channel) {
53
2/6
✓ Branch 0 taken 2946840 times.
✓ Branch 1 taken 30576 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2977416 if (x < 0 || x >= width || y < 0 || y >= height) {
54 return 0.0;
55 }
56
57 2946840 size_t index = ((static_cast<size_t>(y) * static_cast<size_t>(width)) * static_cast<size_t>(channels)) +
58 2946840 ((static_cast<size_t>(x) * static_cast<size_t>(channels)) + static_cast<size_t>(channel));
59 2946840 return static_cast<double>(pixels[index]);
60 }
61
62 56 void ShilinNGaussFilterVerticalSplitSEQ::ApplyGaussianKernel(const std::vector<uint8_t> &input,
63 std::vector<uint8_t> &output, int width, int height,
64 int channels) {
65 // ядро гаусса 3x3
66 56 constexpr std::array<std::array<double, 3>, 3> kKernel = {{{{1.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0}},
67 {{2.0 / 16.0, 4.0 / 16.0, 2.0 / 16.0}},
68 {{1.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0}}}};
69
70
2/2
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 56 times.
1792 for (int row = 0; row < height; ++row) {
71
2/2
✓ Branch 0 taken 111432 times.
✓ Branch 1 taken 1736 times.
113168 for (int col = 0; col < width; ++col) {
72
2/2
✓ Branch 0 taken 334296 times.
✓ Branch 1 taken 111432 times.
445728 for (int ch = 0; ch < channels; ++ch) {
73 334296 double sum = 0.0;
74
75
2/2
✓ Branch 0 taken 1002888 times.
✓ Branch 1 taken 334296 times.
1337184 for (int ky = -1; ky <= 1; ++ky) {
76
2/2
✓ Branch 0 taken 3008664 times.
✓ Branch 1 taken 1002888 times.
4011552 for (int kx = -1; kx <= 1; ++kx) {
77
2/2
✓ Branch 0 taken 2977416 times.
✓ Branch 1 taken 31248 times.
3008664 double pixel_val = GetPixelValue(input, col + kx, row + ky, width, height, channels, ch);
78 3008664 const int kernel_y_idx = ky + 1;
79 3008664 const int kernel_x_idx = kx + 1;
80 3008664 const auto kernel_y = static_cast<size_t>(kernel_y_idx);
81 3008664 const auto kernel_x = static_cast<size_t>(kernel_x_idx);
82 3008664 sum += pixel_val * kKernel.at(kernel_y).at(kernel_x);
83 }
84 }
85
86 334296 size_t index = ((static_cast<size_t>(row) * static_cast<size_t>(width)) * static_cast<size_t>(channels)) +
87 334296 ((static_cast<size_t>(col) * static_cast<size_t>(channels)) + static_cast<size_t>(ch));
88 334296 output[index] = static_cast<uint8_t>(std::clamp(sum, 0.0, 255.0));
89 }
90 }
91 }
92 56 }
93
94 } // namespace shilin_n_gauss_filter_vertical_split
95