KleidiCV Coverage Report


Directory: ./
File: kleidicv/src/filters/median_blur_sorting_network_sc.h
Date: 2025-09-25 14:13:34
Exec Total Coverage
Lines: 56 56 100.0%
Functions: 140 140 100.0%
Branches: 28 28 100.0%

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 35814366 static void compare_and_swap(SourceVectorType& left, SourceVectorType& right,
34 svbool_t& pg) KLEIDICV_STREAMING {
35 35814366 SourceVectorType max_value = svmax_m(pg, left, right);
36 35814366 SourceVectorType min_value = svmin_m(pg, left, right);
37 35814366 left = min_value;
38 35814366 right = max_value;
39 35814366 }
40
41 3878204 static void min(SourceVectorType& left, SourceVectorType& right,
42 svbool_t& pg) KLEIDICV_STREAMING {
43 3878204 left = svmin_m(pg, left, right);
44 3878204 }
45
46 3756304 static void max(SourceVectorType& left, SourceVectorType& right,
47 svbool_t& pg) KLEIDICV_STREAMING {
48 3756304 right = svmax_m(pg, left, right);
49 3756304 }
50 77968 static SourceVectorType get_min(SourceVectorType& left,
51 SourceVectorType& right,
52 svbool_t& pg) KLEIDICV_STREAMING {
53 77968 return svmin_m(pg, left, right);
54 }
55 77968 static SourceVectorType get_max(SourceVectorType& left,
56 SourceVectorType& right,
57 svbool_t& pg) KLEIDICV_STREAMING {
58 77968 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 3708 void vector_path(svbool_t& pg, KernelWindowFunctor& KernelWindow,
73 DestinationVectorType& output_vec) const KLEIDICV_STREAMING {
74 7416 sorting_network3x3_single_row<VectorComparator<ScalarType>>(KernelWindow,
75 3708 output_vec, pg);
76 3708 }
77
78 template <typename KernelWindowFunctor>
79 17638 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 17638 sorting_network3x3_dual_rows<VectorComparator<ScalarType>>(
84 17638 KernelWindow, output_vec_0, output_vec_1, pg);
85 17638 }
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 75826 void vector_path(svbool_t& pg, KernelWindowFunctor& KernelWindow,
101 DestinationVectorType& output_vec) const KLEIDICV_STREAMING {
102 151652 sorting_network5x5<VectorComparator<ScalarType>>(KernelWindow, output_vec,
103 75826 pg);
104 75826 }
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 121900 void vector_path(svbool_t& pg, KernelWindowFunctor& KernelWindow,
121 DestinationVectorType& output_vec) const KLEIDICV_STREAMING {
122 243800 sorting_network7x7<VectorComparator<ScalarType>>(KernelWindow, output_vec,
123 121900 pg);
124 121900 }
125 }; // end of class MedianBlurSortingNetworkSortingNetwork<ScalarType, 7>
126
127 template <typename T>
128 3220 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 3220 Rectangle rect{width, height};
134 3220 Rows<const T> src_rows{src, src_stride, channels};
135 3220 Rows<T> dst_rows{dst, dst_stride, channels};
136
137
14/14
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 260 times.
✓ Branch 2 taken 196 times.
✓ Branch 3 taken 318 times.
✓ Branch 4 taken 196 times.
✓ Branch 5 taken 318 times.
✓ Branch 6 taken 196 times.
✓ Branch 7 taken 318 times.
✓ Branch 8 taken 128 times.
✓ Branch 9 taken 260 times.
✓ Branch 10 taken 128 times.
✓ Branch 11 taken 260 times.
✓ Branch 12 taken 196 times.
✓ Branch 13 taken 318 times.
3220 if (kernel_width == 3) {
138 1168 MedianBlurSortingNetwork<T, 3> median_filter;
139 1168 Filter2D3x3<MedianBlurSortingNetwork<T, 3>> filter{median_filter};
140 2336 process_filter2d_by_dual_rows(rect, y_begin, y_end, src_rows, dst_rows,
141 1168 border_type, filter);
142 1168 return KLEIDICV_OK;
143 1168 }
144
145
14/14
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 150 times.
✓ Branch 4 taken 168 times.
✓ Branch 5 taken 150 times.
✓ Branch 6 taken 168 times.
✓ Branch 7 taken 150 times.
✓ Branch 8 taken 132 times.
✓ Branch 9 taken 128 times.
✓ Branch 10 taken 132 times.
✓ Branch 11 taken 128 times.
✓ Branch 12 taken 168 times.
✓ Branch 13 taken 150 times.
2052 if (kernel_width == 5) {
146 1068 MedianBlurSortingNetwork<T, 5> median_filter;
147 1068 Filter2D5x5<MedianBlurSortingNetwork<T, 5>> filter{median_filter};
148 2136 process_filter2d(rect, y_begin, y_end, src_rows, dst_rows, border_type,
149 1068 filter);
150 1068 return KLEIDICV_OK;
151 1068 }
152
153 984 MedianBlurSortingNetwork<T, 7> median_filter;
154 984 Filter2D7x7<MedianBlurSortingNetwork<T, 7>> filter{median_filter};
155 1968 process_filter2d(rect, y_begin, y_end, src_rows, dst_rows, border_type,
156 984 filter);
157 984 return KLEIDICV_OK;
158 3220 }
159
160 } // namespace KLEIDICV_TARGET_NAMESPACE
161
162 #endif // KLEIDICV_MEDIAN_BLUR_SC_H
163