| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "kondrashova_v_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 "kondrashova_v_gauss_filter_vertical_split/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace kondrashova_v_gauss_filter_vertical_split { | ||
| 12 | |||
| 13 | const std::array<std::array<int, 3>, 3> KondrashovaVGaussFilterVerticalSplitSEQ::kGaussKernel = { | ||
| 14 | {{{1, 2, 1}}, {{2, 4, 2}}, {{1, 2, 1}}}}; | ||
| 15 | const int KondrashovaVGaussFilterVerticalSplitSEQ::kGaussKernelSum = 16; | ||
| 16 | |||
| 17 | ✗ | uint8_t KondrashovaVGaussFilterVerticalSplitSEQ::ApplyGaussToPixel(const std::vector<uint8_t> &pixels, int width, | |
| 18 | int height, int channels, int px, int py, | ||
| 19 | int channel) { | ||
| 20 | int sum = 0; | ||
| 21 | |||
| 22 | ✗ | for (int ky = -1; ky <= 1; ++ky) { | |
| 23 | ✗ | for (int kx = -1; kx <= 1; ++kx) { | |
| 24 | ✗ | int nx = std::clamp(px + kx, 0, width - 1); | |
| 25 | ✗ | int ny = std::clamp(py + ky, 0, height - 1); | |
| 26 | |||
| 27 | ✗ | int idx = (((ny * width) + nx) * channels) + channel; | |
| 28 | ✗ | auto kernel_row = static_cast<size_t>(ky) + 1; | |
| 29 | ✗ | auto kernel_col = static_cast<size_t>(kx) + 1; | |
| 30 | ✗ | sum += pixels[idx] * kGaussKernel.at(kernel_row).at(kernel_col); | |
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | ✗ | return static_cast<uint8_t>(std::clamp(sum / kGaussKernelSum, 0, 255)); | |
| 35 | } | ||
| 36 | |||
| 37 | ✗ | KondrashovaVGaussFilterVerticalSplitSEQ::KondrashovaVGaussFilterVerticalSplitSEQ(const InType &in) { | |
| 38 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 39 | GetInput() = in; | ||
| 40 | ✗ | } | |
| 41 | |||
| 42 | ✗ | bool KondrashovaVGaussFilterVerticalSplitSEQ::ValidationImpl() { | |
| 43 | const auto &input = GetInput(); | ||
| 44 | |||
| 45 | ✗ | auto expected_size = static_cast<size_t>(input.width) * input.height * input.channels; | |
| 46 | ✗ | return input.pixels.size() == expected_size && input.width >= 3 && input.height >= 3 && input.channels >= 1 && | |
| 47 | ✗ | input.channels <= 4; | |
| 48 | } | ||
| 49 | |||
| 50 | ✗ | bool KondrashovaVGaussFilterVerticalSplitSEQ::PreProcessingImpl() { | |
| 51 | const auto &input = GetInput(); | ||
| 52 | auto &output = GetOutput(); | ||
| 53 | |||
| 54 | ✗ | output.width = input.width; | |
| 55 | ✗ | output.height = input.height; | |
| 56 | ✗ | output.channels = input.channels; | |
| 57 | ✗ | output.pixels.resize(input.pixels.size()); | |
| 58 | |||
| 59 | ✗ | return true; | |
| 60 | } | ||
| 61 | |||
| 62 | ✗ | bool KondrashovaVGaussFilterVerticalSplitSEQ::RunImpl() { | |
| 63 | const auto &input = GetInput(); | ||
| 64 | auto &output = GetOutput(); | ||
| 65 | |||
| 66 | ✗ | int width = input.width; | |
| 67 | ✗ | int height = input.height; | |
| 68 | ✗ | int channels = input.channels; | |
| 69 | |||
| 70 | ✗ | for (int row = 0; row < height; ++row) { | |
| 71 | ✗ | for (int col = 0; col < width; ++col) { | |
| 72 | ✗ | for (int ch = 0; ch < channels; ++ch) { | |
| 73 | ✗ | int idx = (((row * width) + col) * channels) + ch; | |
| 74 | ✗ | output.pixels[idx] = ApplyGaussToPixel(input.pixels, width, height, channels, col, row, ch); | |
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | ✗ | return true; | |
| 80 | } | ||
| 81 | |||
| 82 | ✗ | bool KondrashovaVGaussFilterVerticalSplitSEQ::PostProcessingImpl() { | |
| 83 | ✗ | return true; | |
| 84 | } | ||
| 85 | |||
| 86 | } // namespace kondrashova_v_gauss_filter_vertical_split | ||
| 87 |