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