Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qimage_ssse3.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#ifdef QT_COMPILER_SUPPORTS_SSSE3
9
11
12// Convert a scanline of RGB888 (src) to RGB32 (dst)
13// src must be at least len * 3 bytes
14// dst must be at least len * 4 bytes
16{
17 int i = 0;
18
19 // Prologue, align dst to 16 bytes.
21 dst[i] = qRgb(src[0], src[1], src[2]);
22 src += 3;
23 }
24
25 // Mask the 4 first colors of the RGB888 vector
26 const __m128i shuffleMask = _mm_set_epi8(char(0xff), 9, 10, 11, char(0xff), 6, 7, 8, char(0xff), 3, 4, 5, char(0xff), 0, 1, 2);
27
28 // Mask the 4 last colors of a RGB888 vector with an offset of 1 (so the last 3 bytes are RGB)
29 const __m128i shuffleMaskEnd = _mm_set_epi8(char(0xff), 13, 14, 15, char(0xff), 10, 11, 12, char(0xff), 7, 8, 9, char(0xff), 4, 5, 6);
30
31 // Mask to have alpha = 0xff
32 const __m128i alphaMask = _mm_set1_epi32(0xff000000);
33
34 const __m128i *inVectorPtr = (const __m128i *)src;
35 __m128i *dstVectorPtr = (__m128i *)(dst + i);
36
37 for (; i < (len - 15); i += 16) { // one iteration in the loop converts 16 pixels
38 /*
39 RGB888 has 5 pixels per vector, + 1 byte from the next pixel. The idea here is
40 to load vectors of RGB888 and use palignr to select a vector out of two vectors.
41
42 After 3 loads of RGB888 and 3 stores of RGB32, we have 4 pixels left in the last
43 vector of RGB888, we can mask it directly to get a last store or RGB32. After that,
44 the first next byte is a R, and we can loop for the next 16 pixels.
45
46 The conversion itself is done with a byte permutation (pshufb).
47 */
48 __m128i firstSrcVector = _mm_lddqu_si128(inVectorPtr);
49 __m128i outputVector = _mm_shuffle_epi8(firstSrcVector, shuffleMask);
50 _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));
51 ++inVectorPtr;
52 ++dstVectorPtr;
53
54 // There are 4 unused bytes left in srcVector, we need to load the next 16 bytes
55 // and load the next input with palignr
56 __m128i secondSrcVector = _mm_lddqu_si128(inVectorPtr);
57 __m128i srcVector = _mm_alignr_epi8(secondSrcVector, firstSrcVector, 12);
58 outputVector = _mm_shuffle_epi8(srcVector, shuffleMask);
59 _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));
60 ++inVectorPtr;
61 ++dstVectorPtr;
62 firstSrcVector = secondSrcVector;
63
64 // We now have 8 unused bytes left in firstSrcVector
65 secondSrcVector = _mm_lddqu_si128(inVectorPtr);
66 srcVector = _mm_alignr_epi8(secondSrcVector, firstSrcVector, 8);
67 outputVector = _mm_shuffle_epi8(srcVector, shuffleMask);
68 _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));
69 ++inVectorPtr;
70 ++dstVectorPtr;
71
72 // There are now 12 unused bytes in firstSrcVector.
73 // We can mask them directly, almost there.
74 outputVector = _mm_shuffle_epi8(secondSrcVector, shuffleMaskEnd);
75 _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));
76 ++dstVectorPtr;
77 }
78 src = (const uchar *)inVectorPtr;
79
80 SIMD_EPILOGUE(i, len, 15) {
81 dst[i] = qRgb(src[0], src[1], src[2]);
82 src += 3;
83 }
84}
85
86void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
87{
89 if (src->format == QImage::Format_BGR888)
91 else
93 Q_ASSERT(src->width == dest->width);
94 Q_ASSERT(src->height == dest->height);
95
96 const uchar *src_data = (uchar *) src->data;
97 quint32 *dest_data = (quint32 *) dest->data;
98
99 for (int i = 0; i < src->height; ++i) {
100 qt_convert_rgb888_to_rgb32_ssse3(dest_data, src_data, src->width);
101 src_data += src->bytes_per_line;
102 dest_data = (quint32 *)((uchar*)dest_data + dest->bytes_per_line);
103 }
104}
105
107
108#endif // QT_COMPILER_SUPPORTS_SSSE3
@ Format_RGBA8888
Definition qimage.h:59
@ Format_RGB888
Definition qimage.h:55
@ Format_RGB32
Definition qimage.h:46
@ Format_RGBA8888_Premultiplied
Definition qimage.h:60
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
@ Format_BGR888
Definition qimage.h:71
@ Format_ARGB32
Definition qimage.h:47
@ Format_RGBX8888
Definition qimage.h:58
Combined button and popup list for selecting options.
#define QT_FASTCALL
Q_GUI_EXPORT void QT_FASTCALL qt_convert_rgb888_to_rgb32_ssse3(quint32 *dst, const uchar *src, int len)
GLenum src
GLenum GLenum dst
GLenum GLsizei len
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
constexpr QRgb qRgb(int r, int g, int b)
Definition qrgb.h:30
#define ALIGNMENT_PROLOGUE_16BYTES(ptr, i, length)
Definition qsimd_p.h:27
#define SIMD_EPILOGUE(i, length, max)
Definition qsimd_p.h:33
unsigned int quint32
Definition qtypes.h:50
unsigned char uchar
Definition qtypes.h:32
int height
Definition qimage_p.h:43
uchar * data
Definition qimage_p.h:48
int width
Definition qimage_p.h:42
QImage::Format format
Definition qimage_p.h:49