| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "kopilov_d_vertical_gauss_filter/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <array> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "kopilov_d_vertical_gauss_filter/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace kopilov_d_vertical_gauss_filter { | ||
| 12 | |||
| 13 | namespace { | ||
| 14 | const int kDivConst = 16; | ||
| 15 | const std::array<std::array<int, 3>, 3> kGaussKernel = {{{1, 2, 1}, {2, 4, 2}, {1, 2, 1}}}; | ||
| 16 | const int kNumBands = 1; | ||
| 17 | |||
| 18 | uint8_t KopilovDGetPixelMirrorSeq(const std::vector<uint8_t> &res, int col, int row, int width, int height) { | ||
| 19 | ✗ | if (col < 0) { | |
| 20 | ✗ | col = -col - 1; | |
| 21 | ✗ | } else if (col >= width) { | |
| 22 | ✗ | col = (2 * width) - col - 1; | |
| 23 | } | ||
| 24 | ✗ | if (row < 0) { | |
| 25 | row = -row - 1; | ||
| 26 | ✗ | } else if (row >= height) { | |
| 27 | ✗ | row = (2 * height) - row - 1; | |
| 28 | } | ||
| 29 | ✗ | return res[(row * width) + col]; | |
| 30 | } | ||
| 31 | } // namespace | ||
| 32 | |||
| 33 | ✗ | KopilovDVerticalGaussFilterSEQ::KopilovDVerticalGaussFilterSEQ(const InType &in) { | |
| 34 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 35 | GetInput() = in; | ||
| 36 | ✗ | GetOutput() = OutType{}; | |
| 37 | ✗ | } | |
| 38 | |||
| 39 | ✗ | bool KopilovDVerticalGaussFilterSEQ::ValidationImpl() { | |
| 40 | const auto &in = GetInput(); | ||
| 41 | |||
| 42 | ✗ | if (in.width <= 0 || in.height <= 0) { | |
| 43 | return false; | ||
| 44 | } | ||
| 45 | ✗ | if (in.data.size() != static_cast<size_t>(in.width) * static_cast<size_t>(in.height)) { | |
| 46 | ✗ | return false; | |
| 47 | } | ||
| 48 | return true; | ||
| 49 | } | ||
| 50 | |||
| 51 | ✗ | bool KopilovDVerticalGaussFilterSEQ::PreProcessingImpl() { | |
| 52 | ✗ | return true; | |
| 53 | } | ||
| 54 | |||
| 55 | ✗ | bool KopilovDVerticalGaussFilterSEQ::RunImpl() { | |
| 56 | const auto &in = GetInput(); | ||
| 57 | |||
| 58 | ✗ | int width = in.width; | |
| 59 | ✗ | int height = in.height; | |
| 60 | const std::vector<uint8_t> &matrix = in.data; | ||
| 61 | ✗ | std::vector<uint8_t> result(static_cast<size_t>(width) * static_cast<size_t>(height)); | |
| 62 | |||
| 63 | int band_width = width / kNumBands; | ||
| 64 | int remainder = width % kNumBands; | ||
| 65 | int start_band = 0; | ||
| 66 | |||
| 67 | ✗ | for (int band = 0; band < kNumBands; ++band) { | |
| 68 | ✗ | int cur_band_width = band_width + (band < remainder ? 1 : 0); | |
| 69 | ✗ | int end_band = start_band + cur_band_width; | |
| 70 | |||
| 71 | ✗ | for (int horizontal_band = start_band; horizontal_band < end_band; ++horizontal_band) { | |
| 72 | ✗ | for (int vertical_band = 0; vertical_band < height; ++vertical_band) { | |
| 73 | int sum = 0; | ||
| 74 | |||
| 75 | sum += kGaussKernel[0][0] * | ||
| 76 | ✗ | KopilovDGetPixelMirrorSeq(matrix, horizontal_band - 1, vertical_band - 1, width, height); | |
| 77 | ✗ | sum += | |
| 78 | ✗ | kGaussKernel[0][1] * KopilovDGetPixelMirrorSeq(matrix, horizontal_band, vertical_band - 1, width, height); | |
| 79 | ✗ | sum += kGaussKernel[0][2] * | |
| 80 | ✗ | KopilovDGetPixelMirrorSeq(matrix, horizontal_band + 1, vertical_band - 1, width, height); | |
| 81 | |||
| 82 | ✗ | sum += | |
| 83 | ✗ | kGaussKernel[1][0] * KopilovDGetPixelMirrorSeq(matrix, horizontal_band - 1, vertical_band, width, height); | |
| 84 | ✗ | sum += kGaussKernel[1][1] * KopilovDGetPixelMirrorSeq(matrix, horizontal_band, vertical_band, width, height); | |
| 85 | ✗ | sum += | |
| 86 | ✗ | kGaussKernel[1][2] * KopilovDGetPixelMirrorSeq(matrix, horizontal_band + 1, vertical_band, width, height); | |
| 87 | |||
| 88 | ✗ | sum += kGaussKernel[2][0] * | |
| 89 | ✗ | KopilovDGetPixelMirrorSeq(matrix, horizontal_band - 1, vertical_band + 1, width, height); | |
| 90 | ✗ | sum += | |
| 91 | ✗ | kGaussKernel[2][1] * KopilovDGetPixelMirrorSeq(matrix, horizontal_band, vertical_band + 1, width, height); | |
| 92 | ✗ | sum += kGaussKernel[2][2] * | |
| 93 | ✗ | KopilovDGetPixelMirrorSeq(matrix, horizontal_band + 1, vertical_band + 1, width, height); | |
| 94 | |||
| 95 | ✗ | result[(vertical_band * width) + horizontal_band] = static_cast<uint8_t>(sum / kDivConst); | |
| 96 | } | ||
| 97 | } | ||
| 98 | start_band = end_band; | ||
| 99 | } | ||
| 100 | ✗ | GetOutput().width = width; | |
| 101 | ✗ | GetOutput().height = height; | |
| 102 | ✗ | GetOutput().data = std::move(result); | |
| 103 | ✗ | return true; | |
| 104 | } | ||
| 105 | |||
| 106 | ✗ | bool KopilovDVerticalGaussFilterSEQ::PostProcessingImpl() { | |
| 107 | ✗ | return true; | |
| 108 | } | ||
| 109 | |||
| 110 | } // namespace kopilov_d_vertical_gauss_filter | ||
| 111 |