Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qimage_neon.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include <qimage.h>
6#include <private/qimage_p.h>
7#include <private/qsimd_p.h>
8
9#if defined(__ARM_NEON__)
10
11QT_BEGIN_NAMESPACE
12
13Q_GUI_EXPORT void QT_FASTCALL qt_convert_rgb888_to_rgb32_neon(quint32 *dst, const uchar *src, int len)
14{
15 if (!len)
16 return;
17
18 const quint32 *const end = dst + len;
19
20 // align dst on 128 bits
21 const int offsetToAlignOn16Bytes = (reinterpret_cast<quintptr>(dst) >> 2) & 0x3;
22 for (int i = 0; i < qMin(len, offsetToAlignOn16Bytes); ++i) {
23 *dst++ = qRgb(src[0], src[1], src[2]);
24 src += 3;
25 }
26
27 if ((len - offsetToAlignOn16Bytes) >= 16) {
28 const quint32 *const simdEnd = end - 15;
29 uint8x16x4_t dstVector;
30#if Q_BYTE_ORDER == Q_BIG_ENDIAN
31 dstVector.val[0] = vdupq_n_u8(0xff);
32#else
33 dstVector.val[3] = vdupq_n_u8(0xff);
34#endif
35 do {
36 uint8x16x3_t srcVector = vld3q_u8(src);
37 src += 3 * 16;
38#if Q_BYTE_ORDER == Q_BIG_ENDIAN
39 dstVector.val[1] = srcVector.val[0];
40 dstVector.val[2] = srcVector.val[1];
41 dstVector.val[3] = srcVector.val[2];
42#else
43 dstVector.val[0] = srcVector.val[2];
44 dstVector.val[1] = srcVector.val[1];
45 dstVector.val[2] = srcVector.val[0];
46#endif
47 vst4q_u8(reinterpret_cast<uint8_t*>(dst), dstVector);
48 dst += 16;
49 } while (dst < simdEnd);
50 }
51
52 int i = 0;
53 int length = end - dst;
54 SIMD_EPILOGUE(i, length, 15) {
55 *dst++ = qRgb(src[0], src[1], src[2]);
56 src += 3;
57 }
58}
59
60void convert_RGB888_to_RGB32_neon(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
61{
62 Q_ASSERT(src->format == QImage::Format_RGB888);
63 Q_ASSERT(dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied);
64 Q_ASSERT(src->width == dest->width);
65 Q_ASSERT(src->height == dest->height);
66
67 const uchar *src_data = (uchar *) src->data;
68 quint32 *dest_data = (quint32 *) dest->data;
69
70 for (int i = 0; i < src->height; ++i) {
71 qt_convert_rgb888_to_rgb32_neon(dest_data, src_data, src->width);
72 src_data += src->bytes_per_line;
73 dest_data = (quint32 *)((uchar*)dest_data + dest->bytes_per_line);
74 }
75}
76
77QT_END_NAMESPACE
78
79#endif // defined(__ARM_NEON__)