summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/image
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/image')
-rw-r--r--tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro2
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp169
-rw-r--r--tests/auto/gui/image/qimagereader/tst_qimagereader.cpp40
-rw-r--r--tests/auto/gui/image/qpixmap/tst_qpixmap.cpp1
4 files changed, 185 insertions, 27 deletions
diff --git a/tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro b/tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro
index 17553158bc..49c615721b 100644
--- a/tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro
+++ b/tests/auto/gui/image/qiconhighdpi/qiconhighdpi.pro
@@ -1,5 +1,5 @@
CONFIG += testcase
-TARGET = tst_qicon
+TARGET = tst_qiconhighdpi
QT += testlib
SOURCES += tst_qiconhighdpi.cpp
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index e9aa9aad30..fe998c7d92 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -32,7 +32,7 @@
#include <qimage.h>
#include <qimagereader.h>
#include <qlist.h>
-#include <qmatrix.h>
+#include <qtransform.h>
#include <qrandom.h>
#include <stdio.h>
@@ -177,6 +177,12 @@ private slots:
void inplaceRgbConversion_data();
void inplaceRgbConversion();
+ void largeGenericRgbConversion_data();
+ void largeGenericRgbConversion();
+
+ void largeInplaceRgbConversion_data();
+ void largeInplaceRgbConversion();
+
void deepCopyWhenPaintingActive();
void scaled_QTBUG19157();
@@ -191,6 +197,8 @@ private slots:
void invertPixelsRGB_data();
void invertPixelsRGB();
+ void invertPixelsIndexed();
+
void exifOrientation_data();
void exifOrientation();
@@ -1202,7 +1210,7 @@ void tst_QImage::rotate()
// original.save("rotated90_original.png", "png");
// Initialize the matrix manually (do not use rotate) to avoid rounding errors
- QMatrix matRotate90;
+ QTransform matRotate90;
matRotate90.rotate(degrees);
QImage dest = original;
// And rotate it 4 times, then the image should be identical to the original
@@ -1216,7 +1224,7 @@ void tst_QImage::rotate()
// dest.save("rotated90_result.png","png");
QCOMPARE(original, dest);
- // Test with QMatrix::rotate 90 also, since we trust that now
+ // Test with QTransform::rotate 90 also, since we trust that now
matRotate90.rotate(degrees);
dest = original;
// And rotate it 4 times, then the image should be identical to the original
@@ -2894,16 +2902,15 @@ void tst_QImage::inplaceRgbConversion_data()
}
if (i == j)
continue;
- QTest::addRow("%s -> %s", formatToString(QImage::Format(i)).data(), formatToString(QImage::Format(j)).data())
- << QImage::Format(i) << QImage::Format(j);
+ if (qt_depthForFormat(QImage::Format(i)) >= qt_depthForFormat(QImage::Format(j)))
+ QTest::addRow("%s -> %s", formatToString(QImage::Format(i)).data(), formatToString(QImage::Format(j)).data())
+ << QImage::Format(i) << QImage::Format(j);
}
}
}
void tst_QImage::inplaceRgbConversion()
{
- // 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);
@@ -2952,7 +2959,123 @@ void tst_QImage::inplaceRgbConversion()
QVERIFY(rwInplaceConverted.constBits() != (const uchar *)readWriteData);
QCOMPARE(normalConverted, rwInplaceConverted);
}
-#endif
+}
+
+void tst_QImage::largeGenericRgbConversion_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<QImage::Format>("dest_format");
+
+ QImage::Format formats[] = {
+ QImage::Format_RGB32,
+ QImage::Format_ARGB32,
+ QImage::Format_ARGB32_Premultiplied,
+ QImage::Format_RGB16,
+ QImage::Format_RGB888,
+ QImage::Format_RGBA8888,
+ QImage::Format_BGR30,
+ QImage::Format_A2RGB30_Premultiplied,
+ QImage::Format_RGBA64_Premultiplied,
+ };
+
+ for (QImage::Format src_format : formats) {
+ for (QImage::Format dst_format : formats) {
+ if (src_format == dst_format)
+ continue;
+
+ QTest::addRow("%s -> %s", formatToString(src_format).data(), formatToString(dst_format).data())
+ << src_format << dst_format;
+ }
+ }
+}
+
+void tst_QImage::largeGenericRgbConversion()
+{
+ // Also test a larger conversion for a few formats (here the tested precision is also higher)
+ QFETCH(QImage::Format, format);
+ QFETCH(QImage::Format, dest_format);
+
+ // Must have more than 64k pixels to trigger threaded codepath:
+ QImage image(512, 216, format);
+
+ for (int i = 0; i < image.height(); ++i)
+ for (int j = 0; j < image.width(); ++j)
+ image.setPixel(j, i, qRgb(j % 256, i, 0));
+
+ const bool precision_8bit = (format != QImage::Format_RGB16) && (dest_format != QImage::Format_RGB16);
+
+ QImage imageConverted = image.convertToFormat(dest_format);
+ QCOMPARE(imageConverted.format(), dest_format);
+ for (int i = 0; i < imageConverted.height(); ++i) {
+ for (int j = 0; j < imageConverted.width(); ++j) {
+ if (precision_8bit) {
+ QCOMPARE(imageConverted.pixel(j, i), image.pixel(j, i));
+ } else {
+ QRgb convertedColor = imageConverted.pixel(j,i);
+ QCOMPARE(qRed(convertedColor) & 0xF8, (j % 256) & 0xF8);
+ QCOMPARE(qGreen(convertedColor) & 0xFC, i & 0xFC);
+ }
+ }
+ }
+}
+
+void tst_QImage::largeInplaceRgbConversion_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<QImage::Format>("dest_format");
+
+ QImage::Format formats[] = {
+ QImage::Format_RGB32,
+ QImage::Format_ARGB32,
+ QImage::Format_ARGB32_Premultiplied,
+ QImage::Format_RGB16,
+ QImage::Format_RGB888,
+ QImage::Format_RGBA8888,
+ QImage::Format_BGR30,
+ QImage::Format_A2RGB30_Premultiplied,
+ QImage::Format_RGBA64_Premultiplied,
+ };
+
+ for (QImage::Format src_format : formats) {
+ for (QImage::Format dst_format : formats) {
+ if (src_format == dst_format)
+ continue;
+ if (qt_depthForFormat(src_format) < qt_depthForFormat(dst_format))
+ continue;
+ QTest::addRow("%s -> %s", formatToString(src_format).data(), formatToString(dst_format).data())
+ << src_format << dst_format;
+ }
+ }
+}
+
+void tst_QImage::largeInplaceRgbConversion()
+{
+ // Also test a larger conversion for a few formats
+ QFETCH(QImage::Format, format);
+ QFETCH(QImage::Format, dest_format);
+
+ // Must have more than 64k pixels to trigger threaded codepath:
+ QImage image(512, 216, format);
+
+ for (int i = 0; i < image.height(); ++i)
+ for (int j = 0; j < image.width(); ++j)
+ image.setPixel(j, i, qRgb(j % 256, i, 0));
+
+ const bool precision_8bit = (format != QImage::Format_RGB16) && (dest_format != QImage::Format_RGB16);
+
+ image.convertTo(dest_format);
+ QCOMPARE(image.format(), dest_format);
+ for (int i = 0; i < image.height(); ++i) {
+ for (int j = 0; j < image.width(); ++j) {
+ if (precision_8bit) {
+ QCOMPARE(image.pixel(j,i), qRgb(j % 256, i, 0));
+ } else {
+ QRgb convertedColor = image.pixel(j,i);
+ QCOMPARE(qRed(convertedColor) & 0xF8, (j % 256) & 0xF8);
+ QCOMPARE(qGreen(convertedColor) & 0xFC, i & 0xFC);
+ }
+ }
+ }
}
void tst_QImage::deepCopyWhenPaintingActive()
@@ -3086,6 +3209,36 @@ void tst_QImage::invertPixelsRGB()
QCOMPARE(qBlue(pixel) >> 4, (255 - 96) >> 4);
}
+void tst_QImage::invertPixelsIndexed()
+{
+ {
+ QImage image(1, 1, QImage::Format_Mono);
+ image.fill(Qt::color1);
+ image.invertPixels();
+ QCOMPARE(image.pixelIndex(0, 0), 0);
+ }
+ {
+ QImage image(1, 1, QImage::Format_MonoLSB);
+ image.fill(Qt::color0);
+ image.invertPixels();
+ QCOMPARE(image.pixelIndex(0, 0), 1);
+ }
+ {
+ QImage image(1, 1, QImage::Format_Indexed8);
+ image.setColorTable({0xff000000, 0xffffffff});
+ image.fill(Qt::black);
+ image.invertPixels();
+ QCOMPARE(image.pixelIndex(0, 0), 255);
+ }
+ {
+ QImage image(1, 1, QImage::Format_Indexed8);
+ image.setColorTable({0xff000000, 0xffffffff, 0x80000000, 0x80ffffff, 0x00000000});
+ image.fill(Qt::white);
+ image.invertPixels();
+ QCOMPARE(image.pixelIndex(0, 0), 254);
+ }
+}
+
void tst_QImage::exifOrientation_data()
{
QTest::addColumn<QString>("fileName");
diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
index 22d96e76f9..6001829854 100644
--- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
@@ -45,6 +45,8 @@
#include <algorithm>
+// #define DEBUG_WRITE_OUTPUT
+
typedef QMap<QString, QString> QStringMap;
typedef QList<int> QIntList;
Q_DECLARE_METATYPE(QImage::Format)
@@ -462,24 +464,24 @@ void tst_QImageReader::setScaledClipRect_data()
QTest::addColumn<QRect>("newRect");
QTest::addColumn<QByteArray>("format");
- QTest::newRow("BMP: colorful") << "colorful" << QRect(0, 0, 50, 50) << QByteArray("bmp");
- QTest::newRow("BMP: test32bfv4") << "test32bfv4" << QRect(0, 0, 50, 50) << QByteArray("bmp");
- QTest::newRow("BMP: test32v5") << "test32v5" << QRect(0, 0, 50, 50) << QByteArray("bmp");
- QTest::newRow("BMP: font") << "font" << QRect(0, 0, 50, 50) << QByteArray("bmp");
- QTest::newRow("XPM: marble") << "marble" << QRect(0, 0, 50, 50) << QByteArray("xpm");
- QTest::newRow("PNG: kollada") << "kollada" << QRect(0, 0, 50, 50) << QByteArray("png");
- QTest::newRow("PPM: teapot") << "teapot" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("PPM: runners") << "runners.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("PPM: test") << "test.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("XBM: gnus") << "gnus" << QRect(0, 0, 50, 50) << QByteArray("xbm");
+ QTest::newRow("BMP: colorful") << "colorful" << QRect(50, 20, 50, 50) << QByteArray("bmp");
+ QTest::newRow("BMP: test32bfv4") << "test32bfv4" << QRect(50, 20, 50, 50) << QByteArray("bmp");
+ QTest::newRow("BMP: test32v5") << "test32v5" << QRect(50, 20, 50, 50) << QByteArray("bmp");
+ QTest::newRow("BMP: font") << "font" << QRect(50, 20, 50, 50) << QByteArray("bmp");
+ QTest::newRow("XPM: marble") << "marble" << QRect(50, 20, 50, 50) << QByteArray("xpm");
+ QTest::newRow("PNG: kollada") << "kollada" << QRect(50, 20, 50, 50) << QByteArray("png");
+ QTest::newRow("PPM: teapot") << "teapot" << QRect(50, 20, 50, 50) << QByteArray("ppm");
+ QTest::newRow("PPM: runners") << "runners.ppm" << QRect(50, 20, 50, 50) << QByteArray("ppm");
+ QTest::newRow("PPM: test") << "test.ppm" << QRect(50, 20, 50, 50) << QByteArray("ppm");
+ QTest::newRow("XBM: gnus") << "gnus" << QRect(50, 20, 50, 50) << QByteArray("xbm");
- QTest::newRow("JPEG: beavis") << "beavis" << QRect(0, 0, 50, 50) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis") << "beavis" << QRect(50, 20, 50, 50) << QByteArray("jpeg");
- QTest::newRow("GIF: earth") << "earth" << QRect(0, 0, 50, 50) << QByteArray("gif");
- QTest::newRow("GIF: trolltech") << "trolltech" << QRect(0, 0, 50, 50) << QByteArray("gif");
+ QTest::newRow("GIF: earth") << "earth" << QRect(50, 20, 50, 50) << QByteArray("gif");
+ QTest::newRow("GIF: trolltech") << "trolltech" << QRect(50, 20, 50, 50) << QByteArray("gif");
- QTest::newRow("SVG: rect") << "rect" << QRect(0, 0, 50, 50) << QByteArray("svg");
- QTest::newRow("SVGZ: rect") << "rect" << QRect(0, 0, 50, 50) << QByteArray("svgz");
+ QTest::newRow("SVG: rect") << "rect" << QRect(50, 20, 50, 50) << QByteArray("svg");
+ QTest::newRow("SVGZ: rect") << "rect" << QRect(50, 20, 50, 50) << QByteArray("svgz");
}
void tst_QImageReader::setScaledClipRect()
@@ -495,7 +497,11 @@ void tst_QImageReader::setScaledClipRect()
reader.setScaledClipRect(newRect);
QImage image = reader.read();
QVERIFY(!image.isNull());
- QCOMPARE(image.rect(), newRect);
+ QCOMPARE(image.rect().translated(50, 20), newRect);
+#ifdef DEBUG_WRITE_OUTPUT
+ QString tempPath = QDir::temp().filePath(fileName) + QLatin1String(".png");
+ image.save(tempPath);
+#endif
QImageReader originalReader(prefix + fileName);
originalReader.setScaledSize(QSize(300, 300));
@@ -1075,7 +1081,7 @@ private slots:
void acceptNewConnection()
{
serverSocket = server.nextPendingConnection();
- connect(serverSocket, SIGNAL(error(QAbstractSocket::SocketError)),
+ connect(serverSocket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)),
this, SLOT(remoteHostClosed()));
}
diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
index ba5df809f2..1d77f70919 100644
--- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
@@ -32,7 +32,6 @@
#include <qbitmap.h>
#include <qimage.h>
#include <qimagereader.h>
-#include <qmatrix.h>
#ifndef QT_NO_WIDGETS
#include <qdesktopwidget.h>
#include <qsplashscreen.h>