| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "papulina_y_gauss_filter_block/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <array> | ||
| 5 | #include <cmath> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "papulina_y_gauss_filter_block/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace papulina_y_gauss_filter_block { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 558 times.
✗ Branch 2 not taken.
|
558 | PapulinaYGaussFilterSEQ::PapulinaYGaussFilterSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 558 | GetOutput() = Picture(); | |
| 17 | 558 | } | |
| 18 | |||
| 19 | 558 | bool PapulinaYGaussFilterSEQ::ValidationImpl() { | |
| 20 |
2/4✓ Branch 0 taken 558 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 558 times.
|
558 | return (GetInput().width >= 1 && GetInput().height >= 1); |
| 21 | } | ||
| 22 | |||
| 23 | 558 | bool PapulinaYGaussFilterSEQ::PreProcessingImpl() { | |
| 24 | Pic_ = GetInput(); | ||
| 25 | 558 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | 558 | bool PapulinaYGaussFilterSEQ::RunImpl() { | |
| 29 | 558 | int k = Pic_.channels; | |
| 30 | Picture result(Pic_.width, Pic_.height, Pic_.channels, | ||
| 31 | 558 | std::vector<unsigned char>(static_cast<size_t>(Pic_.width * Pic_.height * k), 0)); | |
| 32 |
2/2✓ Branch 0 taken 9486 times.
✓ Branch 1 taken 558 times.
|
10044 | for (int col = 0; col < Pic_.width; col++) { |
| 33 |
2/2✓ Branch 0 taken 336798 times.
✓ Branch 1 taken 9486 times.
|
346284 | for (int row = 0; row < Pic_.height; row++) { |
| 34 | 336798 | int index = (row * Pic_.width + col) * k; | |
| 35 |
1/2✓ Branch 1 taken 336798 times.
✗ Branch 2 not taken.
|
336798 | std::vector<unsigned char> pixel_new = NewPixel(row, col); |
| 36 |
2/2✓ Branch 0 taken 489654 times.
✓ Branch 1 taken 336798 times.
|
826452 | for (int ch = 0; ch < k; ch++) { |
| 37 | 489654 | result.pixels[index + ch] = pixel_new[ch]; | |
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
| 41 | GetOutput() = result; | ||
| 42 | 558 | return true; | |
| 43 | } | ||
| 44 | 558 | bool PapulinaYGaussFilterSEQ::PostProcessingImpl() { | |
| 45 | 558 | return true; | |
| 46 | } | ||
| 47 | 3031182 | void PapulinaYGaussFilterSEQ::ClampCoordinates(int &n_x, int &n_y) const { | |
| 48 |
4/4✓ Branch 0 taken 2946078 times.
✓ Branch 1 taken 85104 times.
✓ Branch 2 taken 2945808 times.
✓ Branch 3 taken 85374 times.
|
5977260 | n_x = std::max(0, std::min(Pic_.width - 1, n_x)); |
| 49 |
4/4✓ Branch 0 taken 2946078 times.
✓ Branch 1 taken 85104 times.
✓ Branch 2 taken 2945808 times.
✓ Branch 3 taken 85374 times.
|
5977260 | n_y = std::max(0, std::min(Pic_.height - 1, n_y)); |
| 50 | 3031182 | } | |
| 51 | 336798 | std::vector<unsigned char> PapulinaYGaussFilterSEQ::NewPixel(const int &row, const int &col) { | |
| 52 | static constexpr std::array<float, 9> kErnel = {1.0F / 16, 2.0F / 16, 1.0F / 16, 2.0F / 16, 4.0F / 16, | ||
| 53 | 2.0F / 16, 1.0F / 16, 2.0F / 16, 1.0F / 16}; | ||
| 54 | const float *kernel_ptr = kErnel.data(); | ||
| 55 | 336798 | int k = Pic_.channels; | |
| 56 | 336798 | std::vector<float> sums(k, 0); | |
| 57 |
2/2✓ Branch 0 taken 1010394 times.
✓ Branch 1 taken 336798 times.
|
1347192 | for (int dx = -1; dx <= 1; dx++) { |
| 58 |
2/2✓ Branch 0 taken 3031182 times.
✓ Branch 1 taken 1010394 times.
|
4041576 | for (int dy = -1; dy <= 1; dy++) { |
| 59 | 3031182 | int n_x = col + dx; | |
| 60 | 3031182 | int n_y = row + dy; | |
| 61 | 3031182 | ClampCoordinates(n_x, n_y); | |
| 62 | 3031182 | int index = (n_y * Pic_.width + n_x) * k; | |
| 63 |
2/2✓ Branch 0 taken 4406886 times.
✓ Branch 1 taken 3031182 times.
|
7438068 | for (int ch = 0; ch < k; ch++) { |
| 64 | 4406886 | sums[ch] += static_cast<float>(Pic_.pixels[index + ch]) * (*kernel_ptr); | |
| 65 | } | ||
| 66 | 3031182 | ++kernel_ptr; | |
| 67 | } | ||
| 68 | } | ||
| 69 |
1/4✓ Branch 1 taken 336798 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
336798 | std::vector<unsigned char> result(k); |
| 70 |
2/2✓ Branch 0 taken 489654 times.
✓ Branch 1 taken 336798 times.
|
826452 | for (int ch = 0; ch < k; ch++) { |
| 71 |
1/2✓ Branch 0 taken 489654 times.
✗ Branch 1 not taken.
|
489654 | float value = sums[ch]; |
| 72 |
2/4✓ Branch 0 taken 489654 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 489654 times.
✗ Branch 3 not taken.
|
1468962 | value = std::max(0.0F, std::min(255.0F, value)); |
| 73 | 489654 | result[ch] = static_cast<unsigned char>(std::lround(value)); | |
| 74 | } | ||
| 75 | 336798 | return result; | |
| 76 | } | ||
| 77 | } // namespace papulina_y_gauss_filter_block | ||
| 78 |