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 | #include "kleidicv/dispatch.h" | ||
6 | #include "kleidicv/kleidicv.h" | ||
7 | #include "kleidicv/morphology/workspace.h" | ||
8 | |||
9 | namespace kleidicv { | ||
10 | |||
11 | namespace neon { | ||
12 | |||
13 | template <typename T> | ||
14 | kleidicv_error_t dilate(const T *src, size_t src_stride, T *dst, | ||
15 | size_t dst_stride, size_t width, size_t height, | ||
16 | kleidicv_morphology_context_t *context); | ||
17 | |||
18 | template <typename T> | ||
19 | kleidicv_error_t erode(const T *src, size_t src_stride, T *dst, | ||
20 | size_t dst_stride, size_t width, size_t height, | ||
21 | kleidicv_morphology_context_t *context); | ||
22 | |||
23 | } // namespace neon | ||
24 | |||
25 | namespace sve2 { | ||
26 | |||
27 | template <typename T> | ||
28 | kleidicv_error_t dilate(const T *src, size_t src_stride, T *dst, | ||
29 | size_t dst_stride, size_t width, size_t height, | ||
30 | kleidicv_morphology_context_t *context); | ||
31 | |||
32 | template <typename T> | ||
33 | kleidicv_error_t erode(const T *src, size_t src_stride, T *dst, | ||
34 | size_t dst_stride, size_t width, size_t height, | ||
35 | kleidicv_morphology_context_t *context); | ||
36 | |||
37 | } // namespace sve2 | ||
38 | |||
39 | namespace sme { | ||
40 | |||
41 | template <typename T> | ||
42 | kleidicv_error_t dilate(const T *src, size_t src_stride, T *dst, | ||
43 | size_t dst_stride, size_t width, size_t height, | ||
44 | kleidicv_morphology_context_t *context); | ||
45 | |||
46 | template <typename T> | ||
47 | kleidicv_error_t erode(const T *src, size_t src_stride, T *dst, | ||
48 | size_t dst_stride, size_t width, size_t height, | ||
49 | kleidicv_morphology_context_t *context); | ||
50 | |||
51 | } // namespace sme | ||
52 | |||
53 | } // namespace kleidicv | ||
54 | |||
55 | extern "C" { | ||
56 | |||
57 | using KLEIDICV_TARGET_NAMESPACE::MorphologyWorkspace; | ||
58 | |||
59 | 1038 | kleidicv_error_t kleidicv_morphology_create( | |
60 | kleidicv_morphology_context_t **context, kleidicv_rectangle_t kernel, | ||
61 | kleidicv_point_t anchor, kleidicv_border_type_t border_type, | ||
62 | const uint8_t *border_value, size_t channels, size_t iterations, | ||
63 | size_t type_size, kleidicv_rectangle_t image) { | ||
64 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1035 times.
|
1038 | CHECK_POINTERS(context); |
65 | 1035 | *context = nullptr; | |
66 |
6/6✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1032 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1029 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1029 times.
|
1035 | CHECK_RECTANGLE_SIZE(kernel); |
67 |
6/6✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1026 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1023 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1023 times.
|
1029 | CHECK_RECTANGLE_SIZE(image); |
68 | |||
69 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1020 times.
|
1023 | if (type_size > KLEIDICV_MAXIMUM_TYPE_SIZE) { |
70 | 3 | return KLEIDICV_ERROR_RANGE; | |
71 | } | ||
72 | |||
73 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1014 times.
|
1020 | if (channels > KLEIDICV_MAXIMUM_CHANNEL_COUNT) { |
74 | 6 | return KLEIDICV_ERROR_NOT_IMPLEMENTED; | |
75 | } | ||
76 | |||
77 | 1014 | auto morphology_border_type = | |
78 | 1014 | MorphologyWorkspace::get_border_type(border_type); | |
79 | |||
80 |
2/2✓ Branch 0 taken 999 times.
✓ Branch 1 taken 15 times.
|
1014 | if (!morphology_border_type) { |
81 | 15 | return KLEIDICV_ERROR_NOT_IMPLEMENTED; | |
82 | } | ||
83 | |||
84 | 999 | MorphologyWorkspace::Pointer workspace; | |
85 |
6/6✓ Branch 0 taken 18 times.
✓ Branch 1 taken 981 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 981 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 981 times.
|
2016 | if (kleidicv_error_t error = MorphologyWorkspace::create( |
86 | 999 | workspace, kernel, anchor, *morphology_border_type, border_value, | |
87 | 999 | channels, iterations, type_size, image)) { | |
88 | 18 | return error; | |
89 | } | ||
90 | |||
91 | 981 | *context = | |
92 | 981 | reinterpret_cast<kleidicv_morphology_context_t *>(workspace.release()); | |
93 | 981 | return KLEIDICV_OK; | |
94 | 1038 | } | |
95 | |||
96 | 984 | kleidicv_error_t kleidicv_morphology_release( | |
97 | kleidicv_morphology_context_t *context) { | ||
98 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 981 times.
|
984 | CHECK_POINTERS(context); |
99 | |||
100 | // Deliberately create and immediately destroy a unique_ptr to delete the | ||
101 | // workspace. | ||
102 | // NOLINTBEGIN(bugprone-unused-raii) | ||
103 | 981 | MorphologyWorkspace::Pointer{ | |
104 | 981 | reinterpret_cast<MorphologyWorkspace *>(context)}; | |
105 | // NOLINTEND(bugprone-unused-raii) | ||
106 | 981 | return KLEIDICV_OK; | |
107 | 984 | } | |
108 | |||
109 | } // extern "C" | ||
110 | |||
111 | #define KLEIDICV_DEFINE_C_API(name, tname, type) \ | ||
112 | KLEIDICV_MULTIVERSION_C_API( \ | ||
113 | name, &kleidicv::neon::tname<type>, \ | ||
114 | KLEIDICV_SVE2_IMPL_IF(&kleidicv::sve2::tname<type>), \ | ||
115 | &kleidicv::sme::tname<type>, nullptr) | ||
116 | |||
117 |
4/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
|
8 | KLEIDICV_DEFINE_C_API(kleidicv_dilate_u8, dilate, uint8_t); |
118 |
4/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
|
8 | KLEIDICV_DEFINE_C_API(kleidicv_erode_u8, erode, uint8_t); |
119 |