qimage_ssse3.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qimage_ssse3.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include <qimage.h>-
41#include <private/qimage_p.h>-
42#include <private/qsimd_p.h>-
43-
44#ifdef QT_COMPILER_SUPPORTS_SSSE3-
45-
46QT_BEGIN_NAMESPACE-
47-
48// Convert a scanline of RGB888 (src) to RGB32 (dst)-
49// src must be at least len * 3 bytes-
50// dst must be at least len * 4 bytes-
51Q_GUI_EXPORT void QT_FASTCALL qt_convert_rgb888_to_rgb32_ssse3(quint32 *dst, const uchar *src, int len)-
52{-
53 quint32 *const end = dst + len;-
54-
55 // Prologue, align dst to 16 bytes. The alignment is done on dst because it has 4 store()-
56 // for each 3 load() of src.-
57 const int offsetToAlignOn16Bytes = (4 - ((reinterpret_cast<quintptr>(dst) >> 2) & 0x3)) & 0x3;-
58 const int prologLength = qMin(len, offsetToAlignOn16Bytes);-
59-
60 for (int i = 0; i < prologLength; ++i) {
i < prologLengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
61 *dst++ = qRgb(src[0], src[1], src[2]);-
62 src += 3;-
63 }
never executed: end of block
0
64-
65 // Mask the 4 first colors of the RGB888 vector-
66 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);-
67-
68 // Mask the 4 last colors of a RGB888 vector with an offset of 1 (so the last 3 bytes are RGB)-
69 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);-
70-
71 // Mask to have alpha = 0xff-
72 const __m128i alphaMask = _mm_set1_epi32(0xff000000);-
73-
74 const __m128i *inVectorPtr = (const __m128i *)src;-
75 __m128i *dstVectorPtr = (__m128i *)dst;-
76-
77 const int simdRoundCount = (len - prologLength) / 16; // one iteration in the loop converts 16 pixels-
78 for (int i = 0; i < simdRoundCount; ++i) {
i < simdRoundCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
79 /*-
80 RGB888 has 5 pixels per vector, + 1 byte from the next pixel. The idea here is-
81 to load vectors of RGB888 and use palignr to select a vector out of two vectors.-
82-
83 After 3 loads of RGB888 and 3 stores of RGB32, we have 4 pixels left in the last-
84 vector of RGB888, we can mask it directly to get a last store or RGB32. After that,-
85 the first next byte is a R, and we can loop for the next 16 pixels.-
86-
87 The conversion itself is done with a byte permutation (pshufb).-
88 */-
89 __m128i firstSrcVector = _mm_lddqu_si128(inVectorPtr);-
90 __m128i outputVector = _mm_shuffle_epi8(firstSrcVector, shuffleMask);-
91 _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));-
92 ++inVectorPtr;-
93 ++dstVectorPtr;-
94-
95 // There are 4 unused bytes left in srcVector, we need to load the next 16 bytes-
96 // and load the next input with palignr-
97 __m128i secondSrcVector = _mm_lddqu_si128(inVectorPtr);-
98 __m128i srcVector = _mm_alignr_epi8(secondSrcVector, firstSrcVector, 12);-
99 outputVector = _mm_shuffle_epi8(srcVector, shuffleMask);-
100 _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));-
101 ++inVectorPtr;-
102 ++dstVectorPtr;-
103 firstSrcVector = secondSrcVector;-
104-
105 // We now have 8 unused bytes left in firstSrcVector-
106 secondSrcVector = _mm_lddqu_si128(inVectorPtr);-
107 srcVector = _mm_alignr_epi8(secondSrcVector, firstSrcVector, 8);-
108 outputVector = _mm_shuffle_epi8(srcVector, shuffleMask);-
109 _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));-
110 ++inVectorPtr;-
111 ++dstVectorPtr;-
112-
113 // There are now 12 unused bytes in firstSrcVector.-
114 // We can mask them directly, almost there.-
115 outputVector = _mm_shuffle_epi8(secondSrcVector, shuffleMaskEnd);-
116 _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));-
117 ++dstVectorPtr;-
118 }
never executed: end of block
0
119 src = (const uchar *)inVectorPtr;-
120 dst = (quint32 *)dstVectorPtr;-
121-
122 while (dst != end) {
dst != endDescription
TRUEnever evaluated
FALSEnever evaluated
0
123 *dst++ = qRgb(src[0], src[1], src[2]);-
124 src += 3;-
125 }
never executed: end of block
0
126}
never executed: end of block
0
127-
128void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)-
129{-
130 Q_ASSERT(src->format == QImage::Format_RGB888);-
131 Q_ASSERT(dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied);-
132 Q_ASSERT(src->width == dest->width);-
133 Q_ASSERT(src->height == dest->height);-
134-
135 const uchar *src_data = (uchar *) src->data;-
136 quint32 *dest_data = (quint32 *) dest->data;-
137-
138 for (int i = 0; i < src->height; ++i) {
i < src->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
139 qt_convert_rgb888_to_rgb32_ssse3(dest_data, src_data, src->width);-
140 src_data += src->bytes_per_line;-
141 dest_data = (quint32 *)((uchar*)dest_data + dest->bytes_per_line);-
142 }
never executed: end of block
0
143}
never executed: end of block
0
144-
145QT_END_NAMESPACE-
146-
147#endif // QT_COMPILER_SUPPORTS_SSSE3-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9