KleidiCV Coverage Report


Directory: ./
File: kleidicv/src/arithmetics/threshold_neon.cpp
Date: 2025-09-25 14:13:34
Exec Total Coverage
Lines: 23 23 100.0%
Functions: 4 4 100.0%
Branches: 16 16 100.0%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2023 - 2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 #include "kleidicv/kleidicv.h"
6 #include "kleidicv/neon.h"
7
8 namespace kleidicv::neon {
9
10 template <typename ScalarType>
11 class BinaryThreshold final : public UnrollTwice {
12 public:
13 using VecTraits = neon::VecTraits<ScalarType>;
14 using VectorType = typename VecTraits::VectorType;
15
16 71 BinaryThreshold(ScalarType threshold, ScalarType value)
17 71 : threshold_vect_{vdupq_n_u8(threshold)},
18 71 value_vect_{vdupq_n_u8(value)},
19 71 zero_vect_{vdupq_n_u8(0)},
20 71 threshold_{threshold},
21 71 value_{value} {}
22
23 468 VectorType vector_path(VectorType src) {
24 468 VectorType predicate = vcgtq_u8(src, threshold_vect_);
25 936 return vbslq_u8(predicate, value_vect_, zero_vect_);
26 468 }
27
28 673 ScalarType scalar_path(ScalarType src) {
29
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 366 times.
673 return src > threshold_ ? value_ : 0;
30 }
31
32 private:
33 VectorType threshold_vect_;
34 VectorType value_vect_;
35 VectorType zero_vect_;
36 ScalarType threshold_;
37 ScalarType value_;
38 }; // end of class BinaryThreshold<ScalarType>
39
40 template <typename T>
41 75 kleidicv_error_t threshold_binary(const T *src, size_t src_stride, T *dst,
42 size_t dst_stride, size_t width,
43 size_t height, T threshold, T value) {
44
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 74 times.
75 CHECK_POINTER_AND_STRIDE(src, src_stride, height);
45
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 73 times.
74 CHECK_POINTER_AND_STRIDE(dst, dst_stride, height);
46
6/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 71 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 71 times.
73 CHECK_IMAGE_SIZE(width, height);
47
48 71 Rectangle rect{width, height};
49 71 Rows<const T> src_rows{src, src_stride};
50 71 Rows<T> dst_rows{dst, dst_stride};
51 71 BinaryThreshold<T> operation{threshold, value};
52 71 apply_operation_by_rows(operation, rect, src_rows, dst_rows);
53 71 return KLEIDICV_OK;
54 75 }
55
56 #define KLEIDICV_INSTANTIATE_TEMPLATE(type) \
57 template KLEIDICV_TARGET_FN_ATTRS kleidicv_error_t threshold_binary<type>( \
58 const type *src, size_t src_stride, type *dst, size_t dst_stride, \
59 size_t width, size_t height, type threshold, type value)
60
61 KLEIDICV_INSTANTIATE_TEMPLATE(uint8_t);
62
63 } // namespace kleidicv::neon
64