GCC Code Coverage Report


Directory: ./
File: tasks/sabirov_s_linear_filtering_block_partitioning/common/include/common.hpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 2 2 100.0%
Branches: 14 25 56.0%

Line Branch Exec Source
1 #pragma once
2
3 #include <algorithm>
4 #include <array>
5 #include <cstddef>
6 #include <cstdint>
7 #include <string>
8 #include <tuple>
9 #include <vector>
10
11 #include "task/include/task.hpp"
12
13 namespace sabirov_s_linear_filtering_block_partitioning {
14
15 // Структура для хранения данных изображения
16
7/15
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 50 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
255 struct ImageData {
17 std::vector<uint8_t> pixels; // Пиксели в формате RGB
18 int width{0};
19 int height{0};
20 int channels{3}; // RGB = 3 канала
21
22
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
100 ImageData() = default;
23
1/2
✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
105 ImageData(int w, int h, int ch = 3) : width(w), height(h), channels(ch) {
24
1/2
✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
105 pixels.resize(static_cast<std::size_t>(w) * static_cast<std::size_t>(h) * static_cast<std::size_t>(ch));
25 105 }
26
27 [[nodiscard]] std::size_t Size() const {
28 return pixels.size();
29 }
30
31 [[nodiscard]] bool Empty() const {
32 return pixels.empty();
33 }
34 };
35
36 using InType = ImageData;
37 using OutType = ImageData;
38 using TestType = std::tuple<int, std::string>;
39 using BaseTask = ppc::task::Task<InType, OutType>;
40
41 // Ядро Гаусса 3x3 с использованием std::array
42 inline constexpr std::array<std::array<float, 3>, 3> kGaussianKernel = {{{1.0F / 16.0F, 2.0F / 16.0F, 1.0F / 16.0F},
43 {2.0F / 16.0F, 4.0F / 16.0F, 2.0F / 16.0F},
44 {1.0F / 16.0F, 2.0F / 16.0F, 1.0F / 16.0F}}};
45
46 // Вспомогательная функция для применения ядра Гаусса к одному пикселю
47 37206 inline float ApplyGaussianKernel(const ImageData &input, int row, int col, int channel) {
48 37206 const int width = input.width;
49 37206 const int height = input.height;
50 37206 const int channels = input.channels;
51
52 float sum = 0.0F;
53
54
2/2
✓ Branch 0 taken 111618 times.
✓ Branch 1 taken 37206 times.
148824 for (int ky = 0; ky < 3; ky++) {
55
2/2
✓ Branch 0 taken 334854 times.
✓ Branch 1 taken 111618 times.
446472 for (int kx = 0; kx < 3; kx++) {
56 334854 int ny = row + ky - 1;
57 334854 int nx = col + kx - 1;
58
59 // Обрабатываем граничные пиксели методом ограничения координат
60 ny = std::max(ny, 0);
61 334854 ny = std::min(ny, height - 1);
62 nx = std::max(nx, 0);
63 334854 nx = std::min(nx, width - 1);
64
65 334854 auto input_idx =
66 334854 ((static_cast<std::size_t>(ny) * static_cast<std::size_t>(width) + static_cast<std::size_t>(nx)) *
67 334854 static_cast<std::size_t>(channels)) +
68 334854 static_cast<std::size_t>(channel);
69 334854 sum += static_cast<float>(input.pixels[input_idx]) *
70 334854 kGaussianKernel.at(static_cast<std::size_t>(ky)).at(static_cast<std::size_t>(kx));
71 }
72 }
73
74 37206 return sum;
75 }
76
77 } // namespace sabirov_s_linear_filtering_block_partitioning
78