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