GCC Code Coverage Report


Directory: ./
File: tasks/rysev_m_linear_filter_gauss_kernel/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 57 57 100.0%
Functions: 7 7 100.0%
Branches: 27 36 75.0%

Line Branch Exec Source
1 #include "rysev_m_linear_filter_gauss_kernel/seq/include/ops_seq.hpp"
2
3 #include <stb/stb_image.h>
4
5 #include <algorithm>
6 #include <array>
7 #include <cstddef>
8 #include <cstdint>
9 #include <random>
10 #include <string>
11 #include <vector>
12
13 #include "rysev_m_linear_filter_gauss_kernel/common/include/common.hpp"
14 #include "util/include/util.hpp"
15
16 namespace rysev_m_linear_filter_gauss_kernel {
17
18 namespace {
19 struct KernelElement {
20 int dr;
21 int dc;
22 float weight;
23 };
24
25 const std::array<KernelElement, 9> kKernelElements = {
26 {KernelElement{.dr = -1, .dc = -1, .weight = 1.0F / 16}, KernelElement{.dr = -1, .dc = 0, .weight = 2.0F / 16},
27 KernelElement{.dr = -1, .dc = 1, .weight = 1.0F / 16}, KernelElement{.dr = 0, .dc = -1, .weight = 2.0F / 16},
28 KernelElement{.dr = 0, .dc = 0, .weight = 4.0F / 16}, KernelElement{.dr = 0, .dc = 1, .weight = 2.0F / 16},
29 KernelElement{.dr = 1, .dc = -1, .weight = 1.0F / 16}, KernelElement{.dr = 1, .dc = 0, .weight = 2.0F / 16},
30 KernelElement{.dr = 1, .dc = 1, .weight = 1.0F / 16}}};
31
32 1567008 float ComputePixelValue(int row, int col, int channel, int rows, int cols, int channels,
33 const std::vector<uint8_t> &input) {
34 float sum = 0.0F;
35
2/2
✓ Branch 0 taken 14103072 times.
✓ Branch 1 taken 1567008 times.
15670080 for (const auto &ke : kKernelElements) {
36 14103072 int nr = row + ke.dr;
37 14103072 int nc = col + ke.dc;
38
4/4
✓ Branch 0 taken 13998528 times.
✓ Branch 1 taken 104544 times.
✓ Branch 2 taken 13895424 times.
✓ Branch 3 taken 103104 times.
14103072 if (nr >= 0 && nr < rows && nc >= 0 && nc < cols) {
39 13895424 std::size_t idx = (static_cast<std::size_t>(nr) * cols) + nc;
40 13895424 idx = (idx * channels) + channel;
41 13895424 sum += static_cast<float>(input[idx]) * ke.weight;
42 }
43 }
44 1567008 return sum;
45 }
46
47 } // namespace
48
49 120 RysevMGaussFilterSEQ::RysevMGaussFilterSEQ(const InType &in) {
50 SetTypeOfTask(GetStaticTypeOfTask());
51 120 GetInput() = in;
52 GetOutput() = 0;
53 120 }
54
55 120 bool RysevMGaussFilterSEQ::ValidationImpl() {
56
2/4
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
120 return GetInput() >= 0 && GetOutput() == 0;
57 }
58
59 120 bool RysevMGaussFilterSEQ::PreProcessingImpl() {
60
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 96 times.
120 if (GetInput() == 0) {
61 std::string abs_path =
62
2/4
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
48 ppc::util::GetAbsoluteTaskPath(std::string(PPC_ID_rysev_m_linear_filter_gauss_kernel), "pic.ppm");
63 24 int w = 0;
64 24 int h = 0;
65
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 int ch = 0;
66
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 unsigned char *data = stbi_load(abs_path.c_str(), &w, &h, &ch, STBI_rgb);
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (data == nullptr) {
68 return false;
69 }
70 24 width_ = w;
71 24 height_ = h;
72 24 channels_ = STBI_rgb;
73 24 std::ptrdiff_t total_pixels = static_cast<std::ptrdiff_t>(width_) * height_ * channels_;
74
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 input_image_.assign(data, data + total_pixels);
75
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 stbi_image_free(data);
76 } else {
77 int size = GetInput();
78 96 width_ = height_ = size;
79 96 channels_ = 3;
80 96 std::size_t total_pixels = static_cast<std::size_t>(width_) * height_ * channels_;
81 96 input_image_.resize(total_pixels);
82
83 96 std::mt19937 gen(static_cast<unsigned int>(GetInput()));
84 std::uniform_int_distribution<int> dist(0, 255);
85
2/2
✓ Branch 0 taken 1566720 times.
✓ Branch 1 taken 96 times.
1566816 for (auto &pixel : input_image_) {
86 1566720 pixel = static_cast<uint8_t>(dist(gen));
87 }
88 }
89
90 120 output_image_.resize(input_image_.size(), 0);
91 120 return true;
92 }
93
94 360 void RysevMGaussFilterSEQ::ApplyKernelToChannel(int channel, int rows, int cols) {
95
2/2
✓ Branch 0 taken 17424 times.
✓ Branch 1 taken 360 times.
17784 for (int row = 0; row < rows; ++row) {
96
2/2
✓ Branch 0 taken 1567008 times.
✓ Branch 1 taken 17424 times.
1584432 for (int col = 0; col < cols; ++col) {
97 1567008 float sum = ComputePixelValue(row, col, channel, rows, cols, channels_, input_image_);
98 1567008 std::size_t out_idx = (static_cast<std::size_t>(row) * cols) + col;
99 1567008 out_idx = (out_idx * channels_) + channel;
100 1567008 output_image_[out_idx] = static_cast<uint8_t>(std::clamp(sum, 0.0F, 255.0F));
101 }
102 }
103 360 }
104
105 120 bool RysevMGaussFilterSEQ::RunImpl() {
106 120 int rows = height_;
107 120 int cols = width_;
108 120 int ch = channels_;
109
110
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 120 times.
480 for (int channel = 0; channel < ch; ++channel) {
111 360 ApplyKernelToChannel(channel, rows, cols);
112 }
113
114 120 return true;
115 }
116
117 120 bool RysevMGaussFilterSEQ::PostProcessingImpl() {
118 int64_t total = 0;
119
2/2
✓ Branch 0 taken 1567008 times.
✓ Branch 1 taken 120 times.
1567128 for (uint8_t pixel : output_image_) {
120 1567008 total += pixel;
121 }
122 120 GetOutput() = static_cast<int>(total);
123 120 return true;
124 }
125
126 } // namespace rysev_m_linear_filter_gauss_kernel
127