| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2025 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: Apache-2.0 | ||
| 4 | |||
| 5 | #ifndef KLEIDICV_PROCESS_FILTERS_FILTER_2D_H | ||
| 6 | #define KLEIDICV_PROCESS_FILTERS_FILTER_2D_H | ||
| 7 | |||
| 8 | #include "kleidicv/kleidicv.h" | ||
| 9 | #include "kleidicv/types.h" | ||
| 10 | #include "kleidicv/workspace/border_types.h" | ||
| 11 | |||
| 12 | namespace KLEIDICV_TARGET_NAMESPACE { | ||
| 13 | |||
| 14 | // Primary Template for Filter 2D. | ||
| 15 | template <typename InnerFilterType, const size_t S> | ||
| 16 | class Filter2D; | ||
| 17 | |||
| 18 | template <typename FilterType> | ||
| 19 | 6440 | void process_filter2d(Rectangle rect, size_t y_begin, size_t y_end, | |
| 20 | Rows<const typename FilterType::SourceType> src_rows, | ||
| 21 | Rows<typename FilterType::DestinationType> dst_rows, | ||
| 22 | typename FilterType::BorderType border_type, | ||
| 23 | FilterType filter) KLEIDICV_STREAMING { | ||
| 24 | // Border helper which calculates border offsets. | ||
| 25 | 12880 | typename FilterType::BorderInfoType vertical_border{rect.height(), | |
| 26 | 6440 | border_type}; | |
| 27 | 12880 | typename FilterType::BorderInfoType horizontal_border{rect.width(), | |
| 28 | 6440 | border_type}; | |
| 29 | |||
| 30 |
42/42✓ Branch 0 taken 264 times.
✓ Branch 1 taken 1232 times.
✓ Branch 2 taken 256 times.
✓ Branch 3 taken 1664 times.
✓ Branch 4 taken 276 times.
✓ Branch 5 taken 914 times.
✓ Branch 6 taken 327 times.
✓ Branch 7 taken 3202 times.
✓ Branch 8 taken 309 times.
✓ Branch 9 taken 3062 times.
✓ Branch 10 taken 369 times.
✓ Branch 11 taken 856 times.
✓ Branch 12 taken 336 times.
✓ Branch 13 taken 3272 times.
✓ Branch 14 taken 300 times.
✓ Branch 15 taken 2992 times.
✓ Branch 16 taken 360 times.
✓ Branch 17 taken 416 times.
✓ Branch 18 taken 316 times.
✓ Branch 19 taken 2870 times.
✓ Branch 20 taken 291 times.
✓ Branch 21 taken 2552 times.
✓ Branch 22 taken 358 times.
✓ Branch 23 taken 524 times.
✓ Branch 24 taken 282 times.
✓ Branch 25 taken 1742 times.
✓ Branch 26 taken 267 times.
✓ Branch 27 taken 1996 times.
✓ Branch 28 taken 256 times.
✓ Branch 29 taken 128 times.
✓ Branch 30 taken 296 times.
✓ Branch 31 taken 960 times.
✓ Branch 32 taken 290 times.
✓ Branch 33 taken 1284 times.
✓ Branch 34 taken 290 times.
✓ Branch 35 taken 132 times.
✓ Branch 36 taken 316 times.
✓ Branch 37 taken 2486 times.
✓ Branch 38 taken 289 times.
✓ Branch 39 taken 2276 times.
✓ Branch 40 taken 392 times.
✓ Branch 41 taken 144 times.
|
41144 | for (size_t vertical_index = y_begin; vertical_index < y_end; |
| 31 | 34704 | ++vertical_index) { | |
| 32 | 34704 | auto vertical_offsets = vertical_border.offsets_with_border(vertical_index); | |
| 33 | 34704 | constexpr size_t kMargin = filter.kMargin; | |
| 34 | |||
| 35 | // Process data affected by left border. | ||
| 36 | KLEIDICV_FORCE_LOOP_UNROLL | ||
| 37 |
42/42✓ Branch 0 taken 2464 times.
✓ Branch 1 taken 1232 times.
✓ Branch 2 taken 4992 times.
✓ Branch 3 taken 1664 times.
✓ Branch 4 taken 1732 times.
✓ Branch 5 taken 914 times.
✓ Branch 6 taken 7152 times.
✓ Branch 7 taken 3202 times.
✓ Branch 8 taken 8368 times.
✓ Branch 9 taken 3062 times.
✓ Branch 10 taken 2352 times.
✓ Branch 11 taken 856 times.
✓ Branch 12 taken 6544 times.
✓ Branch 13 taken 3272 times.
✓ Branch 14 taken 8976 times.
✓ Branch 15 taken 2992 times.
✓ Branch 16 taken 724 times.
✓ Branch 17 taken 416 times.
✓ Branch 18 taken 6156 times.
✓ Branch 19 taken 2870 times.
✓ Branch 20 taken 7348 times.
✓ Branch 21 taken 2552 times.
✓ Branch 22 taken 1356 times.
✓ Branch 23 taken 524 times.
✓ Branch 24 taken 3484 times.
✓ Branch 25 taken 1742 times.
✓ Branch 26 taken 5988 times.
✓ Branch 27 taken 1996 times.
✓ Branch 28 taken 128 times.
✓ Branch 29 taken 128 times.
✓ Branch 30 taken 1884 times.
✓ Branch 31 taken 960 times.
✓ Branch 32 taken 3780 times.
✓ Branch 33 taken 1284 times.
✓ Branch 34 taken 132 times.
✓ Branch 35 taken 132 times.
✓ Branch 36 taken 4940 times.
✓ Branch 37 taken 2486 times.
✓ Branch 38 taken 6764 times.
✓ Branch 39 taken 2276 times.
✓ Branch 40 taken 144 times.
✓ Branch 41 taken 144 times.
|
120112 | for (size_t horizontal_index = 0; horizontal_index < kMargin; |
| 38 | 85408 | ++horizontal_index) { | |
| 39 | 85408 | auto horizontal_offsets = | |
| 40 | 85408 | horizontal_border.offsets_with_left_border(horizontal_index); | |
| 41 | 85408 | filter.process_one_pixel_with_horizontal_borders( | |
| 42 | 85408 | src_rows.at(vertical_index, horizontal_index), | |
| 43 | 85408 | dst_rows.at(vertical_index, horizontal_index), vertical_offsets, | |
| 44 | 85408 | horizontal_offsets); | |
| 45 | 85408 | } | |
| 46 | |||
| 47 | // Process data which is not affected by any borders in bulk. | ||
| 48 | 34704 | size_t width_without_borders = rect.width() - (2 * kMargin); | |
| 49 | 34704 | auto horizontal_offsets = horizontal_border.offsets_without_border(); | |
| 50 | 34704 | filter.process_pixels_without_horizontal_borders( | |
| 51 | 34704 | width_without_borders, src_rows.at(vertical_index, kMargin), | |
| 52 | 34704 | dst_rows.at(vertical_index, kMargin), vertical_offsets, | |
| 53 | 34704 | horizontal_offsets); | |
| 54 | |||
| 55 | // Process data affected by right border. | ||
| 56 | KLEIDICV_FORCE_LOOP_UNROLL | ||
| 57 |
42/42✓ Branch 0 taken 2464 times.
✓ Branch 1 taken 1232 times.
✓ Branch 2 taken 4992 times.
✓ Branch 3 taken 1664 times.
✓ Branch 4 taken 1732 times.
✓ Branch 5 taken 914 times.
✓ Branch 6 taken 7152 times.
✓ Branch 7 taken 3202 times.
✓ Branch 8 taken 8368 times.
✓ Branch 9 taken 3062 times.
✓ Branch 10 taken 2352 times.
✓ Branch 11 taken 856 times.
✓ Branch 12 taken 6544 times.
✓ Branch 13 taken 3272 times.
✓ Branch 14 taken 8976 times.
✓ Branch 15 taken 2992 times.
✓ Branch 16 taken 724 times.
✓ Branch 17 taken 416 times.
✓ Branch 18 taken 6156 times.
✓ Branch 19 taken 2870 times.
✓ Branch 20 taken 7348 times.
✓ Branch 21 taken 2552 times.
✓ Branch 22 taken 1356 times.
✓ Branch 23 taken 524 times.
✓ Branch 24 taken 3484 times.
✓ Branch 25 taken 1742 times.
✓ Branch 26 taken 5988 times.
✓ Branch 27 taken 1996 times.
✓ Branch 28 taken 128 times.
✓ Branch 29 taken 128 times.
✓ Branch 30 taken 1884 times.
✓ Branch 31 taken 960 times.
✓ Branch 32 taken 3780 times.
✓ Branch 33 taken 1284 times.
✓ Branch 34 taken 132 times.
✓ Branch 35 taken 132 times.
✓ Branch 36 taken 4940 times.
✓ Branch 37 taken 2486 times.
✓ Branch 38 taken 6764 times.
✓ Branch 39 taken 2276 times.
✓ Branch 40 taken 144 times.
✓ Branch 41 taken 144 times.
|
120112 | for (size_t horizontal_index = 0; horizontal_index < kMargin; |
| 58 | 85408 | ++horizontal_index) { | |
| 59 | 85408 | size_t index = rect.width() - kMargin + horizontal_index; | |
| 60 | 85408 | auto horizontal_offsets = | |
| 61 | 85408 | horizontal_border.offsets_with_right_border(index); | |
| 62 | 85408 | filter.process_one_pixel_with_horizontal_borders( | |
| 63 | 85408 | src_rows.at(vertical_index, index), | |
| 64 | 85408 | dst_rows.at(vertical_index, index), vertical_offsets, | |
| 65 | 85408 | horizontal_offsets); | |
| 66 | 85408 | } | |
| 67 | 34704 | } | |
| 68 | 6440 | } | |
| 69 | |||
| 70 | template <typename FilterType> | ||
| 71 | 2336 | void process_filter2d_by_dual_rows( | |
| 72 | Rectangle rect, size_t y_begin, size_t y_end, | ||
| 73 | Rows<const typename FilterType::SourceType> src_rows, | ||
| 74 | Rows<typename FilterType::DestinationType> dst_rows, | ||
| 75 | typename FilterType::BorderType border_type, | ||
| 76 | FilterType filter) KLEIDICV_STREAMING { | ||
| 77 | // Border helper which calculates border offsets. | ||
| 78 | 4672 | typename FilterType::BorderInfoType vertical_border{rect.height(), | |
| 79 | 2336 | border_type}; | |
| 80 | 4672 | typename FilterType::BorderInfoType horizontal_border{rect.width(), | |
| 81 | 2336 | border_type}; | |
| 82 | 2336 | constexpr size_t kMargin = filter.kMargin; | |
| 83 | 2336 | size_t vertical_index = y_begin; | |
| 84 | |||
| 85 |
14/14✓ Branch 0 taken 256 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 2080 times.
✓ Branch 3 taken 392 times.
✓ Branch 4 taken 2080 times.
✓ Branch 5 taken 392 times.
✓ Branch 6 taken 2080 times.
✓ Branch 7 taken 392 times.
✓ Branch 8 taken 256 times.
✓ Branch 9 taken 256 times.
✓ Branch 10 taken 256 times.
✓ Branch 11 taken 256 times.
✓ Branch 12 taken 2080 times.
✓ Branch 13 taken 392 times.
|
11424 | for (; vertical_index < y_end - 1; vertical_index += 2) { |
| 86 | // Recalculate vertical border offsets. | ||
| 87 | 9088 | auto vertical_offsets_0 = | |
| 88 | 9088 | vertical_border.offsets_with_border(vertical_index); | |
| 89 | 9088 | auto vertical_offsets_1 = | |
| 90 | 9088 | vertical_border.offsets_with_border(vertical_index + 1); | |
| 91 | |||
| 92 | // Process data affected by left border. | ||
| 93 | KLEIDICV_FORCE_LOOP_UNROLL | ||
| 94 |
14/14✓ Branch 0 taken 256 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 2080 times.
✓ Branch 3 taken 2080 times.
✓ Branch 4 taken 2080 times.
✓ Branch 5 taken 2080 times.
✓ Branch 6 taken 2080 times.
✓ Branch 7 taken 2080 times.
✓ Branch 8 taken 256 times.
✓ Branch 9 taken 256 times.
✓ Branch 10 taken 256 times.
✓ Branch 11 taken 256 times.
✓ Branch 12 taken 2080 times.
✓ Branch 13 taken 2080 times.
|
18176 | for (size_t horizontal_index = 0; horizontal_index < kMargin; |
| 95 | 9088 | ++horizontal_index) { | |
| 96 | 9088 | auto horizontal_offsets = | |
| 97 | 9088 | horizontal_border.offsets_with_left_border(horizontal_index); | |
| 98 | 9088 | filter.process_two_pixels_with_horizontal_borders( | |
| 99 | 9088 | src_rows.at(vertical_index, horizontal_index), | |
| 100 | 9088 | dst_rows.at(vertical_index, horizontal_index), vertical_offsets_0, | |
| 101 | 9088 | vertical_offsets_1, horizontal_offsets); | |
| 102 | 9088 | } | |
| 103 | |||
| 104 | // Process data which is not affected by any borders in bulk. | ||
| 105 | 9088 | size_t width_without_borders = rect.width() - (2 * kMargin); | |
| 106 | 9088 | auto horizontal_offsets = horizontal_border.offsets_without_border(); | |
| 107 | 9088 | filter.process_pixels_of_dual_rows_without_horizontal_borders( | |
| 108 | 9088 | width_without_borders, src_rows.at(vertical_index, kMargin), | |
| 109 | 9088 | dst_rows.at(vertical_index, kMargin), vertical_offsets_0, | |
| 110 | 9088 | vertical_offsets_1, horizontal_offsets); | |
| 111 | |||
| 112 | // Process data affected by right border. | ||
| 113 | KLEIDICV_FORCE_LOOP_UNROLL | ||
| 114 |
14/14✓ Branch 0 taken 256 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 2080 times.
✓ Branch 3 taken 2080 times.
✓ Branch 4 taken 2080 times.
✓ Branch 5 taken 2080 times.
✓ Branch 6 taken 2080 times.
✓ Branch 7 taken 2080 times.
✓ Branch 8 taken 256 times.
✓ Branch 9 taken 256 times.
✓ Branch 10 taken 256 times.
✓ Branch 11 taken 256 times.
✓ Branch 12 taken 2080 times.
✓ Branch 13 taken 2080 times.
|
18176 | for (size_t horizontal_index = 0; horizontal_index < kMargin; |
| 115 | 9088 | ++horizontal_index) { | |
| 116 | 9088 | size_t index = rect.width() - kMargin + horizontal_index; | |
| 117 | 9088 | auto horizontal_offsets = | |
| 118 | 9088 | horizontal_border.offsets_with_right_border(index); | |
| 119 | |||
| 120 | 9088 | filter.process_two_pixels_with_horizontal_borders( | |
| 121 | 9088 | src_rows.at(vertical_index, index), | |
| 122 | 9088 | dst_rows.at(vertical_index, index), vertical_offsets_0, | |
| 123 | 9088 | vertical_offsets_1, horizontal_offsets); | |
| 124 | 9088 | } | |
| 125 | 9088 | } | |
| 126 | |||
| 127 | 4672 | process_filter2d(rect, vertical_index, y_end, src_rows, dst_rows, border_type, | |
| 128 | 2336 | filter); | |
| 129 | 2336 | } | |
| 130 | |||
| 131 | } // namespace KLEIDICV_TARGET_NAMESPACE | ||
| 132 | |||
| 133 | #endif // KLEIDICV_PROCESS_FILTERS_FILTER_2D_H | ||
| 134 |