Qt 4.8
qimage_sse2.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 #include <private/qdrawhelper_p.h>
46 #include <private/qdrawingprimitive_sse2_p.h>
47 
48 #ifdef QT_HAVE_SSE2
49 
51 
52 bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionFlags)
53 {
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 
104  return true;
105 }
106 
108 
109 #endif // QT_HAVE_SSE2
double d
Definition: qnumeric_p.h:62
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int height
Definition: qimage_p.h:77
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
static const char * data(const QByteArray &arr)
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
static const KeyPair *const end