| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gasenin_l_image_smooth/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <cstdint> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "gasenin_l_image_smooth/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace gasenin_l_image_smooth { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
112 | GaseninLImageSmoothSEQ::GaseninLImageSmoothSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 | GetInput() = in; | ||
| 14 | 112 | } | |
| 15 | |||
| 16 | 112 | bool GaseninLImageSmoothSEQ::ValidationImpl() { | |
| 17 |
3/6✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 112 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 112 times.
|
112 | return GetInput().width > 0 && GetInput().height > 0 && GetInput().kernel_size > 0 && |
| 18 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
|
112 | GetInput().data.size() == static_cast<size_t>(GetInput().width) * static_cast<size_t>(GetInput().height); |
| 19 | } | ||
| 20 | |||
| 21 | 112 | bool GaseninLImageSmoothSEQ::PreProcessingImpl() { | |
| 22 | GetOutput() = GetInput(); | ||
| 23 | 112 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 | namespace { | ||
| 27 | |||
| 28 | 194832 | void ProcessInteriorPixelSeq(int row, int col, int width, int kernel_size, const uint8_t *src, uint8_t *dst) { | |
| 29 | 194832 | const int kernel_sq = kernel_size * kernel_size; | |
| 30 | 194832 | const int radius = kernel_size / 2; | |
| 31 | |||
| 32 | 194832 | const auto *row_ptr = src + (static_cast<ptrdiff_t>(row - radius) * width) + (col - radius); | |
| 33 | int sum = 0; | ||
| 34 | |||
| 35 |
2/2✓ Branch 0 taken 955728 times.
✓ Branch 1 taken 194832 times.
|
1150560 | for (int kernel_y = 0; kernel_y < kernel_size; ++kernel_y) { |
| 36 |
2/2✓ Branch 0 taken 5210064 times.
✓ Branch 1 taken 955728 times.
|
6165792 | for (int kernel_x = 0; kernel_x < kernel_size; ++kernel_x) { |
| 37 | 5210064 | sum += row_ptr[kernel_x]; | |
| 38 | } | ||
| 39 | 955728 | row_ptr += width; | |
| 40 | } | ||
| 41 | 194832 | dst[(row * width) + col] = static_cast<uint8_t>(sum / kernel_sq); | |
| 42 | 194832 | } | |
| 43 | |||
| 44 | 27110 | void ProcessBorderPixelSeq(int row, int col, int width, int height, int kernel_radius, const uint8_t *src, | |
| 45 | uint8_t *dst) { | ||
| 46 | int sum = 0; | ||
| 47 | int count = 0; | ||
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 151890 times.
✓ Branch 1 taken 27110 times.
|
179000 | for (int kernel_y = -kernel_radius; kernel_y <= kernel_radius; ++kernel_y) { |
| 50 |
2/2✓ Branch 0 taken 140080 times.
✓ Branch 1 taken 11810 times.
|
151890 | const int neighbor_row = Clamp(row + kernel_y, 0, height - 1); |
| 51 | 151890 | const int row_offset = neighbor_row * width; | |
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 913878 times.
✓ Branch 1 taken 151890 times.
|
1065768 | for (int kernel_x = -kernel_radius; kernel_x <= kernel_radius; ++kernel_x) { |
| 54 |
2/2✓ Branch 0 taken 844584 times.
✓ Branch 1 taken 69294 times.
|
913878 | const int neighbor_col = Clamp(col + kernel_x, 0, width - 1); |
| 55 | 913878 | sum += src[row_offset + neighbor_col]; | |
| 56 | 913878 | ++count; | |
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | 27110 | const int index = (row * width) + col; | |
| 61 |
1/2✓ Branch 0 taken 27110 times.
✗ Branch 1 not taken.
|
27110 | if (count > 0) { |
| 62 | 27110 | dst[index] = static_cast<uint8_t>(sum / count); | |
| 63 | } else { | ||
| 64 | ✗ | dst[index] = src[index]; | |
| 65 | } | ||
| 66 | 27110 | } | |
| 67 | |||
| 68 | } // namespace | ||
| 69 | |||
| 70 | 112 | bool GaseninLImageSmoothSEQ::RunImpl() { | |
| 71 | const auto &in = GetInput(); | ||
| 72 | auto &out = GetOutput(); | ||
| 73 | |||
| 74 | 112 | const int width = in.width; | |
| 75 | 112 | const int height = in.height; | |
| 76 | 112 | const int kernel_size = in.kernel_size; | |
| 77 | 112 | const int kernel_radius = kernel_size / 2; | |
| 78 | const uint8_t *src = in.data.data(); | ||
| 79 | uint8_t *dst = out.data.data(); | ||
| 80 | |||
| 81 |
2/2✓ Branch 0 taken 3586 times.
✓ Branch 1 taken 112 times.
|
3698 | for (int row = 0; row < height; ++row) { |
| 82 |
4/4✓ Branch 0 taken 3438 times.
✓ Branch 1 taken 148 times.
✓ Branch 2 taken 126 times.
✓ Branch 3 taken 3312 times.
|
3586 | const bool is_border_row = (row < kernel_radius) || (row >= height - kernel_radius); |
| 83 | |||
| 84 |
2/2✓ Branch 0 taken 221942 times.
✓ Branch 1 taken 3586 times.
|
225528 | for (int col = 0; col < width; ++col) { |
| 85 |
4/4✓ Branch 0 taken 214972 times.
✓ Branch 1 taken 6970 times.
✓ Branch 2 taken 208002 times.
✓ Branch 3 taken 6970 times.
|
221942 | const bool is_border_col = (col < kernel_radius) || (col >= width - kernel_radius); |
| 86 | |||
| 87 |
2/2✓ Branch 0 taken 194832 times.
✓ Branch 1 taken 13170 times.
|
208002 | if (!is_border_row && !is_border_col) { |
| 88 | 194832 | ProcessInteriorPixelSeq(row, col, width, kernel_size, src, dst); | |
| 89 | } else { | ||
| 90 | 27110 | ProcessBorderPixelSeq(row, col, width, height, kernel_radius, src, dst); | |
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | 112 | return true; | |
| 95 | } | ||
| 96 | |||
| 97 | 112 | bool GaseninLImageSmoothSEQ::PostProcessingImpl() { | |
| 98 | 112 | return true; | |
| 99 | } | ||
| 100 | |||
| 101 | } // namespace gasenin_l_image_smooth | ||
| 102 |