KleidiCV Coverage Report


Directory: ./
File: kleidicv/src/conversions/yuv420sp_to_rgb_sc.h
Date: 2026-01-20 20:58:59
Exec Total Coverage
Lines: 67 67 100.0%
Functions: 34 34 100.0%
Branches: 81 81 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_YUV420SP_TO_RGB_SC_H
6 #define KLEIDICV_YUV420SP_TO_RGB_SC_H
7
8 #include "kleidicv/conversions/yuv_to_rgb.h"
9 #include "kleidicv/kleidicv.h"
10 #include "kleidicv/sve2.h"
11 #include "yuv420_to_rgb_sc.h"
12
13 namespace KLEIDICV_TARGET_NAMESPACE {
14
15 template <bool BGR, bool kAlpha>
16 class YUVSpToRGBxOrBGRx final : public YUV420XToRGBxOrBGRx<BGR, kAlpha> {
17 public:
18 using ContextType = Context;
19 using VecTraits = KLEIDICV_TARGET_NAMESPACE::VecTraits<uint8_t>;
20 using YUV420XToRGBxOrBGRx<BGR, kAlpha>::yuv420x_to_rgb;
21
22 2272 explicit YUVSpToRGBxOrBGRx(bool v_first) KLEIDICV_STREAMING
23 2272 : YUV420XToRGBxOrBGRx<BGR, kAlpha>(v_first) {}
24
25 // Returns the number of channels in the output image.
26 1568 static constexpr size_t output_channels() KLEIDICV_STREAMING {
27 1568 return kAlpha ? /* RGBA */ 4 : /* RGB */ 3;
28 }
29
30 // Processes 2 * 16 bytes (even and odd rows) of the input YUV data, and
31 // outputs 2 * 3 (or 4) * 16 bytes of RGB (or RGBA) data per loop iteration.
32 KLEIDICV_FORCE_INLINE
33 3008 void vector_path(ContextType ctx, const uint8_t *y_row_0,
34 const uint8_t *y_row_1, const uint8_t *uv_row,
35 uint8_t *rgbx_row_0,
36 uint8_t *rgbx_row_1) KLEIDICV_STREAMING {
37 3008 auto pg = ctx.predicate();
38 // Load channels: y0 and y1 are two adjacent rows.
39 3008 svuint8_t y0 = svld1(pg, y_row_0);
40 3008 svuint8_t y1 = svld1(pg, y_row_1);
41 3008 svuint8_t uv = svld1(pg, uv_row);
42 // Widen U and V to 32 bits.
43 3008 svint16_t u = svreinterpret_s16(svmovlb(uv));
44 3008 svint16_t v = svreinterpret_s16(svmovlt(uv));
45 3008 yuv420x_to_rgb(pg, y0, y1, u, v, rgbx_row_0, rgbx_row_1);
46 3008 }
47 }; // end of class YUVSpToRGBxOrBGRx<bool, bool>
48
49 using YUVSpToRGB = YUVSpToRGBxOrBGRx<false, false>;
50 using YUVSpToRGBA = YUVSpToRGBxOrBGRx<false, true>;
51 using YUVSpToBGR = YUVSpToRGBxOrBGRx<true, false>;
52 using YUVSpToBGRA = YUVSpToRGBxOrBGRx<true, true>;
53
54 template <typename OperationType, typename ScalarType>
55 2272 KLEIDICV_FORCE_INLINE kleidicv_error_t yuv2rgbx_operation(
56 OperationType &operation, const ScalarType *src_y, size_t src_y_stride,
57 const ScalarType *src_uv, size_t src_uv_stride, ScalarType *dst,
58 size_t dst_stride, size_t width, size_t height) KLEIDICV_STREAMING {
59
16/16
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 536 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 536 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 536 times.
✓ Branch 6 taken 32 times.
✓ Branch 7 taken 536 times.
✓ Branch 8 taken 32 times.
✓ Branch 9 taken 536 times.
✓ Branch 10 taken 32 times.
✓ Branch 11 taken 536 times.
✓ Branch 12 taken 32 times.
✓ Branch 13 taken 536 times.
✓ Branch 14 taken 32 times.
✓ Branch 15 taken 536 times.
2272 CHECK_POINTER_AND_STRIDE(src_y, src_y_stride, height);
60
16/16
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 504 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 504 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 504 times.
✓ Branch 6 taken 32 times.
✓ Branch 7 taken 504 times.
✓ Branch 8 taken 32 times.
✓ Branch 9 taken 504 times.
✓ Branch 10 taken 32 times.
✓ Branch 11 taken 504 times.
✓ Branch 12 taken 32 times.
✓ Branch 13 taken 504 times.
✓ Branch 14 taken 32 times.
✓ Branch 15 taken 504 times.
2144 CHECK_POINTER_AND_STRIDE(src_uv, src_uv_stride, (height + 1) / 2);
61
16/16
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 472 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 472 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 472 times.
✓ Branch 6 taken 32 times.
✓ Branch 7 taken 472 times.
✓ Branch 8 taken 32 times.
✓ Branch 9 taken 472 times.
✓ Branch 10 taken 32 times.
✓ Branch 11 taken 472 times.
✓ Branch 12 taken 32 times.
✓ Branch 13 taken 472 times.
✓ Branch 14 taken 32 times.
✓ Branch 15 taken 472 times.
2016 CHECK_POINTER_AND_STRIDE(dst, dst_stride, height);
62
24/24
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 432 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 392 times.
✓ Branch 4 taken 80 times.
✓ Branch 5 taken 392 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 432 times.
✓ Branch 8 taken 40 times.
✓ Branch 9 taken 392 times.
✓ Branch 10 taken 80 times.
✓ Branch 11 taken 392 times.
✓ Branch 12 taken 40 times.
✓ Branch 13 taken 432 times.
✓ Branch 14 taken 40 times.
✓ Branch 15 taken 392 times.
✓ Branch 16 taken 80 times.
✓ Branch 17 taken 392 times.
✓ Branch 18 taken 40 times.
✓ Branch 19 taken 432 times.
✓ Branch 20 taken 40 times.
✓ Branch 21 taken 392 times.
✓ Branch 22 taken 80 times.
✓ Branch 23 taken 392 times.
1888 CHECK_IMAGE_SIZE(width, height);
63
64 1568 Rectangle rect{width, height};
65 1568 ParallelRows y_rows{src_y, src_y_stride};
66 1568 Rows uv_rows{src_uv, src_uv_stride};
67 1568 ParallelRows rgbx_rows{dst, dst_stride, operation.output_channels()};
68
69 1568 ForwardingOperation forwarding_operation{operation};
70 1568 OperationAdapter operation_adapter{forwarding_operation};
71 1568 RemainingPathAdapter remaining_path_adapter{operation_adapter};
72 1568 OperationContextAdapter context_adapter{remaining_path_adapter};
73 1568 ParallelRowsAdapter parallel_rows_adapter{context_adapter};
74 1568 RowBasedOperation row_based_operation{parallel_rows_adapter};
75 1568 zip_parallel_rows(row_based_operation, rect, y_rows, uv_rows, rgbx_rows);
76 1568 return KLEIDICV_OK;
77 2272 }
78
79 KLEIDICV_TARGET_FN_ATTRS
80 2656 static kleidicv_error_t yuv420sp_to_rgb_u8_sc(
81 const uint8_t *src_y, size_t src_y_stride, const uint8_t *src_uv,
82 size_t src_uv_stride, uint8_t *dst, size_t dst_stride, size_t width,
83 size_t height,
84 kleidicv_color_conversion_t color_format) KLEIDICV_STREAMING {
85
9/9
✓ Branch 0 taken 284 times.
✓ Branch 1 taken 284 times.
✓ Branch 2 taken 284 times.
✓ Branch 3 taken 284 times.
✓ Branch 4 taken 284 times.
✓ Branch 5 taken 284 times.
✓ Branch 6 taken 284 times.
✓ Branch 7 taken 384 times.
✓ Branch 8 taken 284 times.
2656 switch (color_format) {
86 case KLEIDICV_NV21_TO_BGR: {
87 284 YUVSpToBGR operation{true};
88 568 return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv,
89 284 src_uv_stride, dst, dst_stride, width, height);
90 284 }
91
92 case KLEIDICV_NV21_TO_RGB: {
93 284 YUVSpToRGB operation{true};
94 568 return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv,
95 284 src_uv_stride, dst, dst_stride, width, height);
96 284 }
97
98 case KLEIDICV_NV21_TO_BGRA: {
99 284 YUVSpToBGRA operation{true};
100 568 return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv,
101 284 src_uv_stride, dst, dst_stride, width, height);
102 284 }
103
104 case KLEIDICV_NV21_TO_RGBA: {
105 284 YUVSpToRGBA operation{true};
106 568 return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv,
107 284 src_uv_stride, dst, dst_stride, width, height);
108 284 }
109
110 case KLEIDICV_NV12_TO_BGR: {
111 284 YUVSpToBGR operation{false};
112 568 return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv,
113 284 src_uv_stride, dst, dst_stride, width, height);
114 284 }
115
116 case KLEIDICV_NV12_TO_RGB: {
117 284 YUVSpToRGB operation{false};
118 568 return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv,
119 284 src_uv_stride, dst, dst_stride, width, height);
120 284 }
121
122 case KLEIDICV_NV12_TO_BGRA: {
123 284 YUVSpToBGRA operation{false};
124 568 return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv,
125 284 src_uv_stride, dst, dst_stride, width, height);
126 284 }
127
128 case KLEIDICV_NV12_TO_RGBA: {
129 284 YUVSpToRGBA operation{false};
130 568 return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv,
131 284 src_uv_stride, dst, dst_stride, width, height);
132 284 }
133
134 default:
135 384 return KLEIDICV_ERROR_NOT_IMPLEMENTED;
136 }
137
138 return KLEIDICV_ERROR_NOT_IMPLEMENTED;
139 2656 }
140
141 } // namespace KLEIDICV_TARGET_NAMESPACE
142
143 #endif // KLEIDICV_YUV420SP_TO_RGB_SC_H
144