| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "zenin_a_gauss_filter/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "zenin_a_gauss_filter/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace zenin_a_gauss_filter { | ||
| 12 | |||
| 13 | namespace { | ||
| 14 | int Clamp(const Image &img, int x, int y, int ch) { | ||
| 15 | 931968 | const int h = img.height; | |
| 16 | 931968 | const int w = img.width; | |
| 17 | 931968 | const int c = img.channels; | |
| 18 | 931968 | x = std::clamp(x, 0, w - 1); | |
| 19 | 931968 | y = std::clamp(y, 0, h - 1); | |
| 20 | 931968 | return static_cast<int>(img.pixels[(((y * w) + x) * c) + ch]); | |
| 21 | } | ||
| 22 | } // namespace | ||
| 23 | |||
| 24 |
1/2✓ Branch 1 taken 792 times.
✗ Branch 2 not taken.
|
792 | ZeninAGaussFilterSEQ::ZeninAGaussFilterSEQ(const InType &in) { |
| 25 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 26 | GetInput() = in; | ||
| 27 | 792 | GetOutput() = OutType{}; | |
| 28 | 792 | } | |
| 29 | |||
| 30 | 792 | bool ZeninAGaussFilterSEQ::ValidationImpl() { | |
| 31 | const auto &in = GetInput(); | ||
| 32 | 792 | const std::size_t need = static_cast<std::size_t>(in.width) * in.height * in.channels; | |
| 33 |
4/8✓ Branch 0 taken 792 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 792 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 792 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 792 times.
|
792 | return in.width > 0 && in.height > 0 && (in.channels == 1 || in.channels == 3) && in.pixels.size() == need; |
| 34 | } | ||
| 35 | |||
| 36 | 792 | bool ZeninAGaussFilterSEQ::PreProcessingImpl() { | |
| 37 | const auto &in = GetInput(); | ||
| 38 | auto &out = GetOutput(); | ||
| 39 | |||
| 40 | 792 | out.width = in.width; | |
| 41 | 792 | out.height = in.height; | |
| 42 | 792 | out.channels = in.channels; | |
| 43 | 792 | out.pixels.assign(in.pixels.size(), 0); | |
| 44 | |||
| 45 | 792 | return true; | |
| 46 | } | ||
| 47 | |||
| 48 | 792 | bool ZeninAGaussFilterSEQ::RunImpl() { | |
| 49 | const auto &input_image = GetInput(); | ||
| 50 | auto &output_image = GetOutput(); | ||
| 51 | |||
| 52 | 792 | const int width = input_image.width; | |
| 53 | 792 | const int height = input_image.height; | |
| 54 | 792 | const int channels = input_image.channels; | |
| 55 | |||
| 56 | static constexpr int kKernelSum = 16; | ||
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 17154 times.
✓ Branch 1 taken 792 times.
|
17946 | for (int iy = 0; iy < height; ++iy) { |
| 59 |
2/2✓ Branch 0 taken 599220 times.
✓ Branch 1 taken 17154 times.
|
616374 | for (int ix = 0; ix < width; ++ix) { |
| 60 |
2/2✓ Branch 0 taken 931968 times.
✓ Branch 1 taken 599220 times.
|
1531188 | for (int channel = 0; channel < channels; ++channel) { |
| 61 | 931968 | const int v00 = Clamp(input_image, ix - 1, iy - 1, channel); | |
| 62 | const int v01 = Clamp(input_image, ix, iy - 1, channel); | ||
| 63 | 931968 | const int v02 = Clamp(input_image, ix + 1, iy - 1, channel); | |
| 64 | |||
| 65 | const int v10 = Clamp(input_image, ix - 1, iy, channel); | ||
| 66 | const int v11 = Clamp(input_image, ix, iy, channel); | ||
| 67 | const int v12 = Clamp(input_image, ix + 1, iy, channel); | ||
| 68 | |||
| 69 | 931968 | const int v20 = Clamp(input_image, ix - 1, iy + 1, channel); | |
| 70 | const int v21 = Clamp(input_image, ix, iy + 1, channel); | ||
| 71 | const int v22 = Clamp(input_image, ix + 1, iy + 1, channel); | ||
| 72 | |||
| 73 | int sum = 0; | ||
| 74 | sum += v00 * 1; | ||
| 75 | 931968 | sum += v01 * 2; | |
| 76 | 931968 | sum += v02 * 1; | |
| 77 | 931968 | sum += v10 * 2; | |
| 78 | 931968 | sum += v11 * 4; | |
| 79 | 931968 | sum += v12 * 2; | |
| 80 | 931968 | sum += v20 * 1; | |
| 81 | 931968 | sum += v21 * 2; | |
| 82 | 931968 | sum += v22 * 1; | |
| 83 | |||
| 84 | 931968 | const int res = (sum + (kKernelSum / 2)) / kKernelSum; | |
| 85 | 931968 | output_image.pixels[((iy * width + ix) * channels) + channel] = | |
| 86 | static_cast<std::uint8_t>(std::clamp(res, 0, 255)); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | 792 | return true; | |
| 92 | } | ||
| 93 | |||
| 94 | 792 | bool ZeninAGaussFilterSEQ::PostProcessingImpl() { | |
| 95 | 792 | return true; | |
| 96 | } | ||
| 97 | |||
| 98 | } // namespace zenin_a_gauss_filter | ||
| 99 |