summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-01-13 12:43:48 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-23 18:20:49 +0100
commitc695543f76715f1f7acef32102c325399d0953cf (patch)
tree5104a7ac9f3f65c2d0151e743089b4afb5dd00ff
parent3d7d710424056a3c8a4062da234821acd91ee0af (diff)
Ref qualified version of QImage::convertToFormat
Add ref qualified versions of QImage::convertToFormat, so that a temporary QImage can be converted in-place to a format of equal depth. [ChangeLog][QtGui][QImage]Added rvalue qualified convertToFormat method for in-place conversion Change-Id: I2eed5ffd63f5aea4ffa1147bf7607b02a49d9c5d Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
-rw-r--r--src/gui/image/qimage.cpp16
-rw-r--r--src/gui/image/qimage.h14
-rw-r--r--src/gui/image/qimage_compat.cpp6
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp48
4 files changed, 81 insertions, 3 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index d6037fb2d6..305595b68e 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -1862,6 +1862,8 @@ QImage::Format QImage::format() const
}
/*!
+ \fn QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags) const
+
Returns a copy of the image in the given \a format.
The specified image conversion \a flags control how the image data
@@ -1869,7 +1871,11 @@ QImage::Format QImage::format() const
\sa {Image Formats}
*/
-QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags) const
+
+/*!
+ \internal
+*/
+QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags flags) const
{
if (!d || d->format == format)
return *this;
@@ -1902,6 +1908,14 @@ QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags) co
return convertToFormat(Format_ARGB32, flags).convertToFormat(format, flags);
}
+/*!
+ \internal
+*/
+bool QImage::convertToFormat_inplace(Format format, Qt::ImageConversionFlags flags)
+{
+ return d && d->convertInPlace(format, flags);
+}
+
static inline int pixel_distance(QRgb p1, QRgb p2) {
int r1 = qRed(p1);
int g1 = qGreen(p1);
diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h
index e8f195c18e..4326d5dbbc 100644
--- a/src/gui/image/qimage.h
+++ b/src/gui/image/qimage.h
@@ -172,7 +172,19 @@ public:
Format format() const;
+#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QIMAGE_COMPAT_CPP)
+ QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const & Q_REQUIRED_RESULT
+ { return convertToFormat_helper(f, flags); }
+ QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) && Q_REQUIRED_RESULT
+ {
+ if (convertToFormat_inplace(f, flags))
+ return std::move(*this);
+ else
+ return convertToFormat_helper(f, flags);
+ }
+#else
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
+#endif
QImage convertToFormat(Format f, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
int width() const;
@@ -313,6 +325,8 @@ protected:
QImage rgbSwapped_helper() const;
void mirrored_inplace(bool horizontal, bool vertical);
void rgbSwapped_inplace();
+ QImage convertToFormat_helper(Format format, Qt::ImageConversionFlags flags) const;
+ bool convertToFormat_inplace(Format format, Qt::ImageConversionFlags flags);
private:
friend class QWSOnScreenSurface;
diff --git a/src/gui/image/qimage_compat.cpp b/src/gui/image/qimage_compat.cpp
index 9886d392fb..9acf5c18fa 100644
--- a/src/gui/image/qimage_compat.cpp
+++ b/src/gui/image/qimage_compat.cpp
@@ -49,6 +49,12 @@
QT_BEGIN_NAMESPACE
// These implementations must be the same as the inline versions in qimage.h
+
+QImage QImage::convertToFormat(Format f, Qt::ImageConversionFlags flags) const
+{
+ return convertToFormat_helper(f, flags);
+}
+
QImage QImage::mirrored(bool horizontally, bool vertically) const
{
return mirrored_helper(horizontally, vertically);
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 254428958e..f7a672ad18 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -158,7 +158,10 @@ private slots:
void inplaceMirrored_data();
void inplaceMirrored();
- void inplaceDoubleConversion();
+ void inplaceRgbMirrored();
+
+ void inplaceConversion_data();
+ void inplaceConversion();
void deepCopyWhenPaintingActive();
void scaled_QTBUG19157();
@@ -2342,7 +2345,7 @@ void tst_QImage::inplaceMirrored()
#endif
}
-void tst_QImage::inplaceDoubleConversion()
+void tst_QImage::inplaceRgbMirrored()
{
#if defined(Q_COMPILER_REF_QUALIFIERS)
QImage image1(32, 32, QImage::Format_ARGB32);
@@ -2357,6 +2360,47 @@ void tst_QImage::inplaceDoubleConversion()
#endif
}
+void tst_QImage::inplaceConversion_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<QImage::Format>("dest_format");
+
+ QTest::newRow("Format_ARGB32 -> Format_RGBA8888") << QImage::Format_ARGB32 << QImage::Format_RGBA8888;
+ QTest::newRow("Format_RGB888 -> Format_ARGB6666_Premultiplied") << QImage::Format_RGB888 << QImage::Format_ARGB6666_Premultiplied;
+ QTest::newRow("Format_RGB16 -> Format_RGB555") << QImage::Format_RGB16 << QImage::Format_RGB555;
+ QTest::newRow("Format_RGB666 -> Format_RGB888") << QImage::Format_RGB666 << QImage::Format_RGB888;
+ QTest::newRow("Format_ARGB8565_Premultiplied, Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8565_Premultiplied << QImage::Format_ARGB8555_Premultiplied;
+ QTest::newRow("Format_ARGB4444_Premultiplied, Format_RGB444") << QImage::Format_ARGB4444_Premultiplied << QImage::Format_RGB444;
+}
+
+void tst_QImage::inplaceConversion()
+{
+ // Test that conversions between RGB formats of the same bitwidth can be done inplace.
+#if defined(Q_COMPILER_REF_QUALIFIERS)
+ QFETCH(QImage::Format, format);
+ QFETCH(QImage::Format, dest_format);
+
+ QImage image(16, 16, format);
+
+ for (int i = 0; i < image.height(); ++i)
+ for (int j = 0; j < image.width(); ++j)
+ image.setPixel(j, i, qRgb(j*16, i*16, 0));
+
+ const uchar* originalPtr = image.constScanLine(0);
+
+ QImage imageConverted = std::move(image).convertToFormat(dest_format);
+ for (int i = 0; i < imageConverted.height(); ++i) {
+ for (int j = 0; j < imageConverted.width(); ++j) {
+ QRgb convertedColor = imageConverted.pixel(j,i);
+ QCOMPARE(qRed(convertedColor) & 0xF0, j * 16);
+ QCOMPARE(qGreen(convertedColor) & 0xF0, i * 16);
+ }
+ }
+
+ QCOMPARE(imageConverted.constScanLine(0), originalPtr);
+#endif
+}
+
void tst_QImage::deepCopyWhenPaintingActive()
{
QImage image(64, 64, QImage::Format_ARGB32_Premultiplied);