summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/image.pri1
-rw-r--r--src/gui/image/qimage.cpp54
-rw-r--r--src/gui/image/qimage_ssse3.cpp150
-rw-r--r--src/gui/image/qpixmap_s60.cpp20
-rw-r--r--src/gui/image/qpnghandler.cpp2
5 files changed, 208 insertions, 19 deletions
diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri
index ef0c18e..1d89a68 100644
--- a/src/gui/image/image.pri
+++ b/src/gui/image/image.pri
@@ -100,3 +100,4 @@ contains(QT_CONFIG, gif):include($$PWD/qgifhandler.pri)
# SIMD
SSE2_SOURCES += image/qimage_sse2.cpp
+SSSE3_SOURCES += image/qimage_ssse3.cpp
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index e5930ac..30cf758 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -2343,8 +2343,15 @@ static bool convert_indexed8_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConve
data->colortable.resize(256);
for (int i = 0; i < 256; ++i)
data->colortable[i] = qRgb(i, i, i);
+ } else {
+ for (int i = 0; i < data->colortable.size(); ++i)
+ data->colortable[i] = PREMUL(data->colortable.at(i));
+
+ // Fill the rest of the table in case src_data > colortable.size()
+ const int oldSize = data->colortable.size();
+ const QRgb lastColor = data->colortable.at(oldSize - 1);
+ data->colortable.insert(oldSize, 256 - oldSize, lastColor);
}
- const int tableSize = data->colortable.size() - 1;
for (int i = 0; i < data->height; ++i) {
src_data -= src_pad;
@@ -2352,11 +2359,11 @@ static bool convert_indexed8_to_ARGB_PM_inplace(QImageData *data, Qt::ImageConve
for (int pixI = 0; pixI < width; ++pixI) {
--src_data;
--dest_data;
- const uint pixel = data->colortable[qMin<int>(tableSize, *src_data)];
- *dest_data = (quint32) PREMUL(pixel);
+ *dest_data = data->colortable.at(*src_data);
}
}
+ data->colortable = QVector<QRgb>();
data->format = QImage::Format_ARGB32_Premultiplied;
data->bytes_per_line = dst_bytes_per_line;
data->depth = depth;
@@ -2388,8 +2395,12 @@ static bool convert_indexed8_to_RGB_inplace(QImageData *data, Qt::ImageConversio
data->colortable.resize(256);
for (int i = 0; i < 256; ++i)
data->colortable[i] = qRgb(i, i, i);
+ } else {
+ // Fill the rest of the table in case src_data > colortable.size()
+ const int oldSize = data->colortable.size();
+ const QRgb lastColor = data->colortable.at(oldSize - 1);
+ data->colortable.insert(oldSize, 256 - oldSize, lastColor);
}
- const int tableSize = data->colortable.size() - 1;
for (int i = 0; i < data->height; ++i) {
src_data -= src_pad;
@@ -2397,10 +2408,11 @@ static bool convert_indexed8_to_RGB_inplace(QImageData *data, Qt::ImageConversio
for (int pixI = 0; pixI < width; ++pixI) {
--src_data;
--dest_data;
- *dest_data = (quint32) data->colortable[qMin<int>(tableSize, *src_data)];
+ *dest_data = (quint32) data->colortable.at(*src_data);
}
}
+ data->colortable = QVector<QRgb>();
data->format = QImage::Format_RGB32;
data->bytes_per_line = dst_bytes_per_line;
data->depth = depth;
@@ -2428,12 +2440,23 @@ static bool convert_indexed8_to_RGB16_inplace(QImageData *data, Qt::ImageConvers
const int width = data->width;
const int src_pad = data->bytes_per_line - width;
const int dest_pad = (dst_bytes_per_line >> 1) - width;
- if (data->colortable.size() == 0) {
- data->colortable.resize(256);
+
+ quint16 colorTableRGB16[256];
+ if (data->colortable.isEmpty()) {
for (int i = 0; i < 256; ++i)
- data->colortable[i] = qRgb(i, i, i);
+ colorTableRGB16[i] = qt_colorConvert<quint16, quint32>(qRgb(i, i, i), 0);
+ } else {
+ // 1) convert the existing colors to RGB16
+ const int tableSize = data->colortable.size();
+ for (int i = 0; i < tableSize; ++i)
+ colorTableRGB16[i] = qt_colorConvert<quint16, quint32>(data->colortable.at(i), 0);
+ data->colortable = QVector<QRgb>();
+
+ // 2) fill the rest of the table in case src_data > colortable.size()
+ const quint16 lastColor = colorTableRGB16[tableSize - 1];
+ for (int i = tableSize; i < 256; ++i)
+ colorTableRGB16[i] = lastColor;
}
- const int tableSize = data->colortable.size() - 1;
for (int i = 0; i < data->height; ++i) {
src_data -= src_pad;
@@ -2441,8 +2464,7 @@ static bool convert_indexed8_to_RGB16_inplace(QImageData *data, Qt::ImageConvers
for (int pixI = 0; pixI < width; ++pixI) {
--src_data;
--dest_data;
- const uint pixel = data->colortable[qMin<int>(tableSize, *src_data)];
- *dest_data = qt_colorConvert<quint16, quint32>(pixel, 0);
+ *dest_data = colorTableRGB16[*src_data];
}
}
@@ -3332,7 +3354,7 @@ CONVERT_DECL(qargb4444, quint32)
// first index source, second dest
-static const Image_Converter converter_map[QImage::NImageFormats][QImage::NImageFormats] =
+static Image_Converter converter_map[QImage::NImageFormats][QImage::NImageFormats] =
{
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@@ -3739,6 +3761,14 @@ void qInitImageConversions()
inplace_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_inplace_sse2;
}
#endif
+#ifdef QT_HAVE_SSSE3
+ if (features & SSSE3) {
+ extern void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags);
+ converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_ssse3;
+ converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_ssse3;
+ converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_ssse3;
+ }
+#endif
}
/*!
diff --git a/src/gui/image/qimage_ssse3.cpp b/src/gui/image/qimage_ssse3.cpp
new file mode 100644
index 0000000..1c664f2
--- /dev/null
+++ b/src/gui/image/qimage_ssse3.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qimage.h>
+#include <private/qimage_p.h>
+#include <private/qsimd_p.h>
+
+#ifdef QT_HAVE_SSSE3
+
+#include <stdio.h>
+QT_BEGIN_NAMESPACE
+
+// Convert a scanline of RGB888 (src) to RGB32 (dst)
+// src must be at least len * 3 bytes
+// dst must be at least len * 4 bytes
+inline void convert_rgb888_to_rgb32_ssse3(quint32 *dst, const uchar *src, int len)
+{
+ quint32 *const end = dst + len;
+
+ // Prologue, align dst to 16 bytes. The alignement is done on dst because it has 4 store()
+ // for each 3 load() of src.
+ const int offsetToAlignOn16Bytes = (4 - ((reinterpret_cast<quintptr>(dst) >> 2) & 0x3)) & 0x3;
+ const int prologLength = qMin(len, offsetToAlignOn16Bytes);
+
+ for (int i = 0; i < prologLength; ++i) {
+ *dst++ = qRgb(src[0], src[1], src[2]);
+ src += 3;
+ }
+
+ // Mask the 4 first colors of the RGB888 vector
+ const __m128i shuffleMask = _mm_set_epi8(0xff, 9, 10, 11, 0xff, 6, 7, 8, 0xff, 3, 4, 5, 0xff, 0, 1, 2);
+
+ // Mask the 4 last colors of a RGB888 vector with an offset of 1 (so the last 3 bytes are RGB)
+ const __m128i shuffleMaskEnd = _mm_set_epi8(0xff, 13, 14, 15, 0xff, 10, 11, 12, 0xff, 7, 8, 9, 0xff, 4, 5, 6);
+
+ // Mask to have alpha = 0xff
+ const __m128i alphaMask = _mm_set1_epi32(0xff000000);
+
+ __m128i *inVectorPtr = (__m128i *)src;
+ __m128i *dstVectorPtr = (__m128i *)dst;
+
+ const int simdRoundCount = (len - prologLength) / 16; // one iteration in the loop converts 16 pixels
+ for (int i = 0; i < simdRoundCount; ++i) {
+ /*
+ RGB888 has 5 pixels per vector, + 1 byte from the next pixel. The idea here is
+ to load vectors of RGB888 and use palignr to select a vector out of two vectors.
+
+ After 3 loads of RGB888 and 3 stores of RGB32, we have 4 pixels left in the last
+ vector of RGB888, we can mask it directly to get a last store or RGB32. After that,
+ the first next byte is a R, and we can loop for the next 16 pixels.
+
+ The conversion itself is done with a byte permutation (pshufb).
+ */
+ __m128i firstSrcVector = _mm_lddqu_si128(inVectorPtr);
+ __m128i outputVector = _mm_shuffle_epi8(firstSrcVector, shuffleMask);
+ _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));
+ ++inVectorPtr;
+ ++dstVectorPtr;
+
+ // There are 4 unused bytes left in srcVector, we need to load the next 16 bytes
+ // and load the next input with palignr
+ __m128i secondSrcVector = _mm_lddqu_si128(inVectorPtr);
+ __m128i srcVector = _mm_alignr_epi8(secondSrcVector, firstSrcVector, 12);
+ outputVector = _mm_shuffle_epi8(srcVector, shuffleMask);
+ _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));
+ ++inVectorPtr;
+ ++dstVectorPtr;
+ firstSrcVector = secondSrcVector;
+
+ // We now have 8 unused bytes left in firstSrcVector
+ secondSrcVector = _mm_lddqu_si128(inVectorPtr);
+ srcVector = _mm_alignr_epi8(secondSrcVector, firstSrcVector, 8);
+ outputVector = _mm_shuffle_epi8(srcVector, shuffleMask);
+ _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));
+ ++inVectorPtr;
+ ++dstVectorPtr;
+
+ // There are now 12 unused bytes in firstSrcVector.
+ // We can mask them directly, almost there.
+ outputVector = _mm_shuffle_epi8(secondSrcVector, shuffleMaskEnd);
+ _mm_store_si128(dstVectorPtr, _mm_or_si128(outputVector, alphaMask));
+ ++dstVectorPtr;
+ }
+ src = (uchar *)inVectorPtr;
+ dst = (quint32 *)dstVectorPtr;
+
+ while (dst != end) {
+ *dst++ = qRgb(src[0], src[1], src[2]);
+ src += 3;
+ }
+}
+
+void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
+{
+ Q_ASSERT(src->format == QImage::Format_RGB888);
+ Q_ASSERT(dest->format == QImage::Format_RGB32 || dest->format == QImage::Format_ARGB32 || dest->format == QImage::Format_ARGB32_Premultiplied);
+ Q_ASSERT(src->width == dest->width);
+ Q_ASSERT(src->height == dest->height);
+
+ const uchar *src_data = (uchar *) src->data;
+ quint32 *dest_data = (quint32 *) dest->data;
+
+ for (int i = 0; i < src->height; ++i) {
+ convert_rgb888_to_rgb32_ssse3(dest_data, src_data, src->width);
+ src_data += src->bytes_per_line;
+ dest_data = (quint32 *)((uchar*)dest_data + dest->bytes_per_line);
+ }
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_HAVE_SSSE3
diff --git a/src/gui/image/qpixmap_s60.cpp b/src/gui/image/qpixmap_s60.cpp
index a13c8c8..9d571b5 100644
--- a/src/gui/image/qpixmap_s60.cpp
+++ b/src/gui/image/qpixmap_s60.cpp
@@ -157,10 +157,10 @@ class QSymbianBitmapDataAccess
{
public:
- bool heapWasLocked;
+ static int heapRefCount;
QSysInfo::SymbianVersion symbianVersion;
- explicit QSymbianBitmapDataAccess() : heapWasLocked(false)
+ explicit QSymbianBitmapDataAccess()
{
symbianVersion = QSysInfo::symbianVersion();
};
@@ -169,16 +169,22 @@ public:
inline void beginDataAccess(CFbsBitmap *bitmap)
{
- if (symbianVersion == QSysInfo::SV_9_2)
- heapWasLocked = qt_symbianFbsClient()->lockHeap();
- else
+ if (symbianVersion == QSysInfo::SV_9_2) {
+ if (heapRefCount == 0)
+ qt_symbianFbsClient()->lockHeap();
+ } else {
bitmap->LockHeap(ETrue);
+ }
+
+ heapRefCount++;
}
inline void endDataAccess(CFbsBitmap *bitmap)
{
+ heapRefCount--;
+
if (symbianVersion == QSysInfo::SV_9_2) {
- if (!heapWasLocked)
+ if (heapRefCount == 0)
qt_symbianFbsClient()->unlockHeap();
} else {
bitmap->UnlockHeap(ETrue);
@@ -186,6 +192,8 @@ public:
}
};
+int QSymbianBitmapDataAccess::heapRefCount = 0;
+
#define UPDATE_BUFFER() \
{ \
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp
index 2cf8222..dc54313 100644
--- a/src/gui/image/qpnghandler.cpp
+++ b/src/gui/image/qpnghandler.cpp
@@ -389,7 +389,7 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngHeader()
while (num_text--) {
QString key, value;
-#if defined(PNG_iTXt_SUPPORTED)
+#if defined(PNG_iTXt_SUPPORTED) && !defined(QT_NO_TEXTCODEC)
if (text_ptr->lang) {
QTextCodec *codec = QTextCodec::codecForName(text_ptr->lang);
if (codec) {