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
4#include <qimage.h>
5#include <private/qimage_p.h>
6#include <private/qsimd_p.h>
7
8#if defined(__ARM_NEON__)
9
10QT_BEGIN_NAMESPACE
11
12Q_GUI_EXPORT void QT_FASTCALL qt_convert_rgb888_to_rgb32_neon(quint32 *dst, const uchar *src, int len)
13{
14 if (!len)
15 return;
16
17 const quint32 *const end = dst + len;
18
19 // align dst on 128 bits
20 const int offsetToAlignOn16Bytes = (reinterpret_cast<quintptr>(dst) >> 2) & 0x3;
21 for (int i = 0; i < qMin(len, offsetToAlignOn16Bytes); ++i) {
22 *dst++ = qRgb(src[0], src[1], src[2]);
23 src += 3;
24 }
25
26 if ((len - offsetToAlignOn16Bytes) >= 16) {
27 const quint32 *const simdEnd = end - 15;
28 uint8x16x4_t dstVector;
29#if Q_BYTE_ORDER == Q_BIG_ENDIAN
30 dstVector.val[0] = vdupq_n_u8(0xff);
31#else
32 dstVector.val[3] = vdupq_n_u8(0xff);
33#endif
34 do {
35 uint8x16x3_t srcVector = vld3q_u8(src);
36 src += 3 * 16;
37#if Q_BYTE_ORDER == Q_BIG_ENDIAN
38 dstVector.val[1] = srcVector.val[0];
39 dstVector.val[2] = srcVector.val[1];
40 dstVector.val[3] = srcVector.val[2];
41#else
42 dstVector.val[0] = srcVector.val[2];
43 dstVector.val[1] = srcVector.val[1];
44 dstVector.val[2] = srcVector.val[0];
45#endif
46 vst4q_u8(reinterpret_cast<uint8_t*>(dst), dstVector);
47 dst += 16;
48 } while (dst < simdEnd);
49 }
50
51 int i = 0;
52 int length = end - dst;
53 SIMD_EPILOGUE(i, length, 15) {
54 *dst++ = qRgb(src[0], src[1], src[2]);
55 src += 3;
56 }
57}
58
59void convert_RGB888_to_RGB32_neon(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
60{
61 Q_ASSERT(src->format == QImage::Format_RGB888);
62 Q_ASSERT(dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied);
63 Q_ASSERT(src->width == dest->width);
64 Q_ASSERT(src->height == dest->height);
65
66 const uchar *src_data = (uchar *) src->data;
67 quint32 *dest_data = (quint32 *) dest->data;
68
69 for (int i = 0; i < src->height; ++i) {
70 qt_convert_rgb888_to_rgb32_neon(dest_data, src_data, src->width);
71 src_data += src->bytes_per_line;
72 dest_data = (quint32 *)((uchar*)dest_data + dest->bytes_per_line);
73 }
74}
75
76QT_END_NAMESPACE
77
78#endif // defined(__ARM_NEON__)