| 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_YUV_SP_TO_RGB_SC_H | ||
| 6 | #define KLEIDICV_YUV_SP_TO_RGB_SC_H | ||
| 7 | |||
| 8 | #include "kleidicv/conversions/yuv_420_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 | 2016 | explicit YUVSpToRGBxOrBGRx(bool v_first) KLEIDICV_STREAMING | |
| 23 | 2016 | : YUV420XToRGBxOrBGRx<BGR, kAlpha>(v_first) {} | |
| 24 | |||
| 25 | // Returns the number of channels in the output image. | ||
| 26 | 1216 | static constexpr size_t output_channels() KLEIDICV_STREAMING { | |
| 27 | 1216 | 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 | 3008 | void vector_path(ContextType ctx, const uint8_t *y_row_0, | |
| 33 | const uint8_t *y_row_1, const uint8_t *uv_row, | ||
| 34 | uint8_t *rgbx_row_0, | ||
| 35 | uint8_t *rgbx_row_1) KLEIDICV_STREAMING { | ||
| 36 | 3008 | auto pg = ctx.predicate(); | |
| 37 | // Load channels: y0 and y1 are two adjacent rows. | ||
| 38 | 3008 | svuint8_t y0 = svld1(pg, y_row_0); | |
| 39 | 3008 | svuint8_t y1 = svld1(pg, y_row_1); | |
| 40 | 3008 | svuint8_t uv = svld1(pg, uv_row); | |
| 41 | // Widen U and V to 32 bits. | ||
| 42 | 3008 | svint16_t u = svreinterpret_s16(svmovlb(uv)); | |
| 43 | 3008 | svint16_t v = svreinterpret_s16(svmovlt(uv)); | |
| 44 | 3008 | yuv420x_to_rgb(pg, y0, y1, u, v, rgbx_row_0, rgbx_row_1); | |
| 45 | 3008 | } | |
| 46 | }; // end of class YUVSpToRGBxOrBGRx<bool, bool> | ||
| 47 | |||
| 48 | using YUVSpToRGB = YUVSpToRGBxOrBGRx<false, false>; | ||
| 49 | using YUVSpToRGBA = YUVSpToRGBxOrBGRx<false, true>; | ||
| 50 | using YUVSpToBGR = YUVSpToRGBxOrBGRx<true, false>; | ||
| 51 | using YUVSpToBGRA = YUVSpToRGBxOrBGRx<true, true>; | ||
| 52 | |||
| 53 | template <typename OperationType, typename ScalarType> | ||
| 54 | 2016 | kleidicv_error_t yuv2rgbx_operation( | |
| 55 | OperationType &operation, const ScalarType *src_y, size_t src_y_stride, | ||
| 56 | const ScalarType *src_uv, size_t src_uv_stride, ScalarType *dst, | ||
| 57 | size_t dst_stride, size_t width, size_t height) KLEIDICV_STREAMING { | ||
| 58 |
16/16✓ Branch 0 taken 40 times.
✓ Branch 1 taken 464 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 464 times.
✓ Branch 4 taken 40 times.
✓ Branch 5 taken 464 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 464 times.
✓ Branch 8 taken 40 times.
✓ Branch 9 taken 464 times.
✓ Branch 10 taken 40 times.
✓ Branch 11 taken 464 times.
✓ Branch 12 taken 40 times.
✓ Branch 13 taken 464 times.
✓ Branch 14 taken 40 times.
✓ Branch 15 taken 464 times.
|
2016 | CHECK_POINTER_AND_STRIDE(src_y, src_y_stride, height); |
| 59 |
16/16✓ Branch 0 taken 40 times.
✓ Branch 1 taken 424 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 424 times.
✓ Branch 4 taken 40 times.
✓ Branch 5 taken 424 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 424 times.
✓ Branch 8 taken 40 times.
✓ Branch 9 taken 424 times.
✓ Branch 10 taken 40 times.
✓ Branch 11 taken 424 times.
✓ Branch 12 taken 40 times.
✓ Branch 13 taken 424 times.
✓ Branch 14 taken 40 times.
✓ Branch 15 taken 424 times.
|
1856 | CHECK_POINTER_AND_STRIDE(src_uv, src_uv_stride, (height + 1) / 2); |
| 60 |
16/16✓ Branch 0 taken 40 times.
✓ Branch 1 taken 384 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 384 times.
✓ Branch 4 taken 40 times.
✓ Branch 5 taken 384 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 384 times.
✓ Branch 8 taken 40 times.
✓ Branch 9 taken 384 times.
✓ Branch 10 taken 40 times.
✓ Branch 11 taken 384 times.
✓ Branch 12 taken 40 times.
✓ Branch 13 taken 384 times.
✓ Branch 14 taken 40 times.
✓ Branch 15 taken 384 times.
|
1696 | CHECK_POINTER_AND_STRIDE(dst, dst_stride, height); |
| 61 |
24/24✓ Branch 0 taken 40 times.
✓ Branch 1 taken 344 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 304 times.
✓ Branch 4 taken 80 times.
✓ Branch 5 taken 304 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 344 times.
✓ Branch 8 taken 40 times.
✓ Branch 9 taken 304 times.
✓ Branch 10 taken 80 times.
✓ Branch 11 taken 304 times.
✓ Branch 12 taken 40 times.
✓ Branch 13 taken 344 times.
✓ Branch 14 taken 40 times.
✓ Branch 15 taken 304 times.
✓ Branch 16 taken 80 times.
✓ Branch 17 taken 304 times.
✓ Branch 18 taken 40 times.
✓ Branch 19 taken 344 times.
✓ Branch 20 taken 40 times.
✓ Branch 21 taken 304 times.
✓ Branch 22 taken 80 times.
✓ Branch 23 taken 304 times.
|
1536 | CHECK_IMAGE_SIZE(width, height); |
| 62 | |||
| 63 | 1216 | Rectangle rect{width, height}; | |
| 64 | 1216 | ParallelRows y_rows{src_y, src_y_stride}; | |
| 65 | 1216 | Rows uv_rows{src_uv, src_uv_stride}; | |
| 66 | 1216 | ParallelRows rgbx_rows{dst, dst_stride, operation.output_channels()}; | |
| 67 | |||
| 68 | 1216 | ForwardingOperation forwarding_operation{operation}; | |
| 69 | 1216 | OperationAdapter operation_adapter{forwarding_operation}; | |
| 70 | 1216 | RemainingPathAdapter remaining_path_adapter{operation_adapter}; | |
| 71 | 1216 | OperationContextAdapter context_adapter{remaining_path_adapter}; | |
| 72 | 1216 | ParallelRowsAdapter parallel_rows_adapter{context_adapter}; | |
| 73 | 1216 | RowBasedOperation row_based_operation{parallel_rows_adapter}; | |
| 74 | 1216 | zip_parallel_rows(row_based_operation, rect, y_rows, uv_rows, rgbx_rows); | |
| 75 | 1216 | return KLEIDICV_OK; | |
| 76 | 2016 | } | |
| 77 | |||
| 78 | KLEIDICV_TARGET_FN_ATTRS | ||
| 79 | 504 | static kleidicv_error_t yuv_sp_to_rgb_u8_sc( | |
| 80 | const uint8_t *src_y, size_t src_y_stride, const uint8_t *src_uv, | ||
| 81 | size_t src_uv_stride, uint8_t *dst, size_t dst_stride, size_t width, | ||
| 82 | size_t height, bool is_nv21) KLEIDICV_STREAMING { | ||
| 83 | 504 | YUVSpToRGB operation{is_nv21}; | |
| 84 | 1512 | return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv, | |
| 85 | 504 | src_uv_stride, dst, dst_stride, width, height); | |
| 86 | 504 | } | |
| 87 | |||
| 88 | KLEIDICV_TARGET_FN_ATTRS | ||
| 89 | 504 | static kleidicv_error_t yuv_sp_to_rgba_u8_sc( | |
| 90 | const uint8_t *src_y, size_t src_y_stride, const uint8_t *src_uv, | ||
| 91 | size_t src_uv_stride, uint8_t *dst, size_t dst_stride, size_t width, | ||
| 92 | size_t height, bool is_nv21) KLEIDICV_STREAMING { | ||
| 93 | 504 | YUVSpToRGBA operation{is_nv21}; | |
| 94 | 1512 | return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv, | |
| 95 | 504 | src_uv_stride, dst, dst_stride, width, height); | |
| 96 | 504 | } | |
| 97 | |||
| 98 | KLEIDICV_TARGET_FN_ATTRS | ||
| 99 | 504 | static kleidicv_error_t yuv_sp_to_bgr_u8_sc( | |
| 100 | const uint8_t *src_y, size_t src_y_stride, const uint8_t *src_uv, | ||
| 101 | size_t src_uv_stride, uint8_t *dst, size_t dst_stride, size_t width, | ||
| 102 | size_t height, bool is_nv21) KLEIDICV_STREAMING { | ||
| 103 | 504 | YUVSpToBGR operation{is_nv21}; | |
| 104 | 1512 | return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv, | |
| 105 | 504 | src_uv_stride, dst, dst_stride, width, height); | |
| 106 | 504 | } | |
| 107 | |||
| 108 | KLEIDICV_TARGET_FN_ATTRS | ||
| 109 | 504 | static kleidicv_error_t yuv_sp_to_bgra_u8_sc( | |
| 110 | const uint8_t *src_y, size_t src_y_stride, const uint8_t *src_uv, | ||
| 111 | size_t src_uv_stride, uint8_t *dst, size_t dst_stride, size_t width, | ||
| 112 | size_t height, bool is_nv21) KLEIDICV_STREAMING { | ||
| 113 | 504 | YUVSpToBGRA operation{is_nv21}; | |
| 114 | 1512 | return yuv2rgbx_operation(operation, src_y, src_y_stride, src_uv, | |
| 115 | 504 | src_uv_stride, dst, dst_stride, width, height); | |
| 116 | 504 | } | |
| 117 | |||
| 118 | } // namespace KLEIDICV_TARGET_NAMESPACE | ||
| 119 | |||
| 120 | #endif // KLEIDICV_YUV_SP_TO_RGB_SC_H | ||
| 121 |