| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2023 - 2025 Arm Limited and/or its affiliates <open-source-office@arm.com> | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: Apache-2.0 | ||
| 4 | |||
| 5 | #ifndef KLEIDICV_MEDIAN_BLUR_SC_H | ||
| 6 | #define KLEIDICV_MEDIAN_BLUR_SC_H | ||
| 7 | |||
| 8 | #include <algorithm> | ||
| 9 | |||
| 10 | #include "kleidicv/ctypes.h" | ||
| 11 | #include "kleidicv/filters/filter_2d_sc.h" | ||
| 12 | #include "kleidicv/filters/median_blur.h" | ||
| 13 | #include "kleidicv/filters/process_filter_2d.h" | ||
| 14 | #include "kleidicv/kleidicv.h" | ||
| 15 | #include "kleidicv/sve2.h" | ||
| 16 | #include "kleidicv/workspace/border_3x3.h" | ||
| 17 | #include "kleidicv/workspace/border_5x5.h" | ||
| 18 | #include "kleidicv/workspace/border_7x7.h" | ||
| 19 | #include "median_blur_sorting_network_3x3.h" | ||
| 20 | #include "median_blur_sorting_network_5x5.h" | ||
| 21 | #include "median_blur_sorting_network_7x7.h" | ||
| 22 | namespace KLEIDICV_TARGET_NAMESPACE { | ||
| 23 | |||
| 24 | // Primary template for Median Blur filters. | ||
| 25 | template <typename ScalarType, size_t KernelSize> | ||
| 26 | class MedianBlurSortingNetwork; | ||
| 27 | |||
| 28 | template <typename ScalarType> | ||
| 29 | class VectorComparator { | ||
| 30 | public: | ||
| 31 | using SourceVectorType = typename VecTraits<ScalarType>::VectorType; | ||
| 32 | |||
| 33 | 52260522 | static void compare_and_swap(SourceVectorType& left, SourceVectorType& right, | |
| 34 | svbool_t& pg) KLEIDICV_STREAMING { | ||
| 35 | 52260522 | SourceVectorType max_value = svmax_m(pg, left, right); | |
| 36 | 52260522 | SourceVectorType min_value = svmin_m(pg, left, right); | |
| 37 | 52260522 | left = min_value; | |
| 38 | 52260522 | right = max_value; | |
| 39 | 52260522 | } | |
| 40 | |||
| 41 | 5655940 | static void min(SourceVectorType& left, SourceVectorType& right, | |
| 42 | svbool_t& pg) KLEIDICV_STREAMING { | ||
| 43 | 5655940 | left = svmin_m(pg, left, right); | |
| 44 | 5655940 | } | |
| 45 | |||
| 46 | 5477768 | static void max(SourceVectorType& left, SourceVectorType& right, | |
| 47 | svbool_t& pg) KLEIDICV_STREAMING { | ||
| 48 | 5477768 | right = svmax_m(pg, left, right); | |
| 49 | 5477768 | } | |
| 50 | 111568 | static SourceVectorType get_min(SourceVectorType& left, | |
| 51 | SourceVectorType& right, | ||
| 52 | svbool_t& pg) KLEIDICV_STREAMING { | ||
| 53 | 111568 | return svmin_m(pg, left, right); | |
| 54 | } | ||
| 55 | 111568 | static SourceVectorType get_max(SourceVectorType& left, | |
| 56 | SourceVectorType& right, | ||
| 57 | svbool_t& pg) KLEIDICV_STREAMING { | ||
| 58 | 111568 | return svmax_m(pg, left, right); | |
| 59 | } | ||
| 60 | }; | ||
| 61 | |||
| 62 | // Template for Median Blur 3x3 filters. | ||
| 63 | template <typename ScalarType> | ||
| 64 | class MedianBlurSortingNetwork<ScalarType, 3> { | ||
| 65 | public: | ||
| 66 | using SourceType = ScalarType; | ||
| 67 | using DestinationType = SourceType; | ||
| 68 | using SourceVectorType = typename VecTraits<SourceType>::VectorType; | ||
| 69 | using DestinationVectorType = typename VecTraits<DestinationType>::VectorType; | ||
| 70 | |||
| 71 | template <typename KernelWindowFunctor> | ||
| 72 | 5180 | void vector_path(svbool_t& pg, KernelWindowFunctor& KernelWindow, | |
| 73 | DestinationVectorType& output_vec) const KLEIDICV_STREAMING { | ||
| 74 | 10360 | sorting_network3x3_single_row<VectorComparator<ScalarType>>(KernelWindow, | |
| 75 | 5180 | output_vec, pg); | |
| 76 | 5180 | } | |
| 77 | |||
| 78 | template <typename KernelWindowFunctor> | ||
| 79 | 25302 | void vector_path_for_dual_row_handling( | |
| 80 | svbool_t& pg, KernelWindowFunctor& KernelWindow, | ||
| 81 | DestinationVectorType& output_vec_0, | ||
| 82 | DestinationVectorType& output_vec_1) const KLEIDICV_STREAMING { | ||
| 83 | 25302 | sorting_network3x3_dual_rows<VectorComparator<ScalarType>>( | |
| 84 | 25302 | KernelWindow, output_vec_0, output_vec_1, pg); | |
| 85 | 25302 | } | |
| 86 | }; // end of class MedianBlurSortingNetwork<ScalarType, 3> | ||
| 87 | |||
| 88 | // Template for Median Blur 5x5 filters. | ||
| 89 | template <typename ScalarType> | ||
| 90 | class MedianBlurSortingNetwork<ScalarType, 5> { | ||
| 91 | public: | ||
| 92 | using SourceType = ScalarType; | ||
| 93 | using DestinationType = SourceType; | ||
| 94 | using SourceVecTraits = | ||
| 95 | typename KLEIDICV_TARGET_NAMESPACE::VecTraits<SourceType>; | ||
| 96 | using SourceVectorType = typename SourceVecTraits::VectorType; | ||
| 97 | using DestinationVectorType = typename KLEIDICV_TARGET_NAMESPACE::VecTraits< | ||
| 98 | DestinationType>::VectorType; | ||
| 99 | template <typename KernelWindowFunctor> | ||
| 100 | 109904 | void vector_path(svbool_t& pg, KernelWindowFunctor& KernelWindow, | |
| 101 | DestinationVectorType& output_vec) const KLEIDICV_STREAMING { | ||
| 102 | 219808 | sorting_network5x5<VectorComparator<ScalarType>>(KernelWindow, output_vec, | |
| 103 | 109904 | pg); | |
| 104 | 109904 | } | |
| 105 | }; // end of class MedianBlurSortingNetworkSortingNetwork<ScalarType, 5> | ||
| 106 | |||
| 107 | // Template for Median Blur 7x7 filters. | ||
| 108 | template <typename ScalarType> | ||
| 109 | class MedianBlurSortingNetwork<ScalarType, 7> { | ||
| 110 | public: | ||
| 111 | using SourceType = ScalarType; | ||
| 112 | using DestinationType = SourceType; | ||
| 113 | using SourceVecTraits = | ||
| 114 | typename KLEIDICV_TARGET_NAMESPACE::VecTraits<SourceType>; | ||
| 115 | using SourceVectorType = typename SourceVecTraits::VectorType; | ||
| 116 | using DestinationVectorType = typename KLEIDICV_TARGET_NAMESPACE::VecTraits< | ||
| 117 | DestinationType>::VectorType; | ||
| 118 | |||
| 119 | template <typename KernelWindowFunctor> | ||
| 120 | 178172 | void vector_path(svbool_t& pg, KernelWindowFunctor& KernelWindow, | |
| 121 | DestinationVectorType& output_vec) const KLEIDICV_STREAMING { | ||
| 122 | 356344 | sorting_network7x7<VectorComparator<ScalarType>>(KernelWindow, output_vec, | |
| 123 | 178172 | pg); | |
| 124 | 178172 | } | |
| 125 | }; // end of class MedianBlurSortingNetworkSortingNetwork<ScalarType, 7> | ||
| 126 | |||
| 127 | template <typename T> | ||
| 128 | 4830 | kleidicv_error_t median_blur_sorting_network_stripe_sc( | |
| 129 | const T* src, size_t src_stride, T* dst, size_t dst_stride, size_t width, | ||
| 130 | size_t height, size_t y_begin, size_t y_end, size_t channels, | ||
| 131 | size_t kernel_width, [[maybe_unused]] size_t kernel_height, | ||
| 132 | FixedBorderType border_type) KLEIDICV_STREAMING { | ||
| 133 | 4830 | Rectangle rect{width, height}; | |
| 134 | 4830 | Rows<const T> src_rows{src, src_stride, channels}; | |
| 135 | 4830 | Rows<T> dst_rows{dst, dst_stride, channels}; | |
| 136 | |||
| 137 |
14/14✓ Branch 0 taken 192 times.
✓ Branch 1 taken 390 times.
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 477 times.
✓ Branch 4 taken 294 times.
✓ Branch 5 taken 477 times.
✓ Branch 6 taken 294 times.
✓ Branch 7 taken 477 times.
✓ Branch 8 taken 192 times.
✓ Branch 9 taken 390 times.
✓ Branch 10 taken 192 times.
✓ Branch 11 taken 390 times.
✓ Branch 12 taken 294 times.
✓ Branch 13 taken 477 times.
|
4830 | if (kernel_width == 3) { |
| 138 | 1752 | MedianBlurSortingNetwork<T, 3> median_filter; | |
| 139 | 1752 | Filter2D3x3<MedianBlurSortingNetwork<T, 3>> filter{median_filter}; | |
| 140 | 3504 | process_filter2d_by_dual_rows(rect, y_begin, y_end, src_rows, dst_rows, | |
| 141 | 1752 | border_type, filter); | |
| 142 | 1752 | return KLEIDICV_OK; | |
| 143 | 1752 | } | |
| 144 | |||
| 145 |
14/14✓ Branch 0 taken 198 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 252 times.
✓ Branch 3 taken 225 times.
✓ Branch 4 taken 252 times.
✓ Branch 5 taken 225 times.
✓ Branch 6 taken 252 times.
✓ Branch 7 taken 225 times.
✓ Branch 8 taken 198 times.
✓ Branch 9 taken 192 times.
✓ Branch 10 taken 198 times.
✓ Branch 11 taken 192 times.
✓ Branch 12 taken 252 times.
✓ Branch 13 taken 225 times.
|
3078 | if (kernel_width == 5) { |
| 146 | 1602 | MedianBlurSortingNetwork<T, 5> median_filter; | |
| 147 | 1602 | Filter2D5x5<MedianBlurSortingNetwork<T, 5>> filter{median_filter}; | |
| 148 | 3204 | process_filter2d(rect, y_begin, y_end, src_rows, dst_rows, border_type, | |
| 149 | 1602 | filter); | |
| 150 | 1602 | return KLEIDICV_OK; | |
| 151 | 1602 | } | |
| 152 | |||
| 153 | 1476 | MedianBlurSortingNetwork<T, 7> median_filter; | |
| 154 | 1476 | Filter2D7x7<MedianBlurSortingNetwork<T, 7>> filter{median_filter}; | |
| 155 | 2952 | process_filter2d(rect, y_begin, y_end, src_rows, dst_rows, border_type, | |
| 156 | 1476 | filter); | |
| 157 | 1476 | return KLEIDICV_OK; | |
| 158 | 4830 | } | |
| 159 | |||
| 160 | } // namespace KLEIDICV_TARGET_NAMESPACE | ||
| 161 | |||
| 162 | #endif // KLEIDICV_MEDIAN_BLUR_SC_H | ||
| 163 |