KleidiCV Coverage Report


Directory: ./
File: kleidicv/src/arithmetics/threshold_neon.cpp
Date: 2026-01-20 20:58:59
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 89 BinaryThreshold(ScalarType threshold, ScalarType value)
17 89 : threshold_vect_{vdupq_n_u8(threshold)},
18 89 value_vect_{vdupq_n_u8(value)},
19 89 zero_vect_{vdupq_n_u8(0)},
20 89 threshold_{threshold},
21 89 value_{value} {}
22
23 444 VectorType vector_path(VectorType src) {
24 444 VectorType predicate = vcgtq_u8(src, threshold_vect_);
25 888 return vbslq_u8(predicate, value_vect_, zero_vect_);
26 444 }
27
28 1057 ScalarType scalar_path(ScalarType src) {
29
2/2
✓ Branch 0 taken 467 times.
✓ Branch 1 taken 590 times.
1057 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 93 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 92 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 92 times.
93 CHECK_POINTER_AND_STRIDE(src, src_stride, height);
45
4/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 91 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 91 times.
92 CHECK_POINTER_AND_STRIDE(dst, dst_stride, height);
46
6/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 90 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 89 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 89 times.
91 CHECK_IMAGE_SIZE(width, height);
47
48 89 Rectangle rect{width, height};
49 89 Rows<const T> src_rows{src, src_stride};
50 89 Rows<T> dst_rows{dst, dst_stride};
51 89 BinaryThreshold<T> operation{threshold, value};
52 89 apply_operation_by_rows(operation, rect, src_rows, dst_rows);
53 89 return KLEIDICV_OK;
54 93 }
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