1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qimage.h"
|
---|
43 | #include <private/qimage_p.h>
|
---|
44 | #include <private/qsimd_p.h>
|
---|
45 | #include <private/qdrawhelper_p.h>
|
---|
46 | #include <private/qdrawingprimitive_sse2_p.h>
|
---|
47 |
|
---|
48 | #ifdef QT_HAVE_SSE2
|
---|
49 |
|
---|
50 | QT_BEGIN_NAMESPACE
|
---|
51 |
|
---|
52 | bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionFlags)
|
---|
53 | {
|
---|
54 | Q_ASSERT(data->format == QImage::Format_ARGB32);
|
---|
55 |
|
---|
56 | // extra pixels on each line
|
---|
57 | const int spare = data->width & 3;
|
---|
58 | // width in pixels of the pad at the end of each line
|
---|
59 | const int pad = (data->bytes_per_line >> 2) - data->width;
|
---|
60 | const int iter = data->width >> 2;
|
---|
61 | int height = data->height;
|
---|
62 |
|
---|
63 | const __m128i alphaMask = _mm_set1_epi32(0xff000000);
|
---|
64 | const __m128i nullVector = _mm_setzero_si128();
|
---|
65 | const __m128i half = _mm_set1_epi16(0x80);
|
---|
66 | const __m128i colorMask = _mm_set1_epi32(0x00ff00ff);
|
---|
67 |
|
---|
68 | __m128i *d = reinterpret_cast<__m128i*>(data->data);
|
---|
69 | while (height--) {
|
---|
70 | const __m128i *end = d + iter;
|
---|
71 |
|
---|
72 | for (; d != end; ++d) {
|
---|
73 | const __m128i srcVector = _mm_loadu_si128(d);
|
---|
74 | const __m128i srcVectorAlpha = _mm_and_si128(srcVector, alphaMask);
|
---|
75 | if (_mm_movemask_epi8(_mm_cmpeq_epi32(srcVectorAlpha, alphaMask)) == 0xffff) {
|
---|
76 | // opaque, data is unchanged
|
---|
77 | } else if (_mm_movemask_epi8(_mm_cmpeq_epi32(srcVectorAlpha, nullVector)) == 0xffff) {
|
---|
78 | // fully transparent
|
---|
79 | _mm_storeu_si128(d, nullVector);
|
---|
80 | } else {
|
---|
81 | __m128i alphaChannel = _mm_srli_epi32(srcVector, 24);
|
---|
82 | alphaChannel = _mm_or_si128(alphaChannel, _mm_slli_epi32(alphaChannel, 16));
|
---|
83 |
|
---|
84 | __m128i result;
|
---|
85 | BYTE_MUL_SSE2(result, srcVector, alphaChannel, colorMask, half);
|
---|
86 | result = _mm_or_si128(_mm_andnot_si128(alphaMask, result), srcVectorAlpha);
|
---|
87 | _mm_storeu_si128(d, result);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | QRgb *p = reinterpret_cast<QRgb*>(d);
|
---|
92 | QRgb *pe = p+spare;
|
---|
93 | for (; p != pe; ++p) {
|
---|
94 | if (*p < 0x00ffffff)
|
---|
95 | *p = 0;
|
---|
96 | else if (*p < 0xff000000)
|
---|
97 | *p = PREMUL(*p);
|
---|
98 | }
|
---|
99 |
|
---|
100 | d = reinterpret_cast<__m128i*>(p+pad);
|
---|
101 | }
|
---|
102 |
|
---|
103 | data->format = QImage::Format_ARGB32_Premultiplied;
|
---|
104 | return true;
|
---|
105 | }
|
---|
106 |
|
---|
107 | QT_END_NAMESPACE
|
---|
108 |
|
---|
109 | #endif // QT_HAVE_SSE2
|
---|