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/qicoimageformat/qicoimageformat.pro9
-rw-r--r--tests/auto/gui/image/qicon/tst_qicon.cpp8
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp157
-rw-r--r--tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp6
-rw-r--r--tests/auto/gui/image/qmovie/qmovie.pro4
-rw-r--r--tests/auto/gui/image/qpixmap/qpixmap.pro4
-rw-r--r--tests/auto/gui/image/qpixmap/tst_qpixmap.cpp33
7 files changed, 134 insertions, 87 deletions
diff --git a/tests/auto/gui/image/qicoimageformat/qicoimageformat.pro b/tests/auto/gui/image/qicoimageformat/qicoimageformat.pro
index 485472c70c..46bfb2a586 100644
--- a/tests/auto/gui/image/qicoimageformat/qicoimageformat.pro
+++ b/tests/auto/gui/image/qicoimageformat/qicoimageformat.pro
@@ -3,14 +3,5 @@ TARGET = tst_qicoimageformat
SOURCES+= tst_qicoimageformat.cpp
QT += testlib
-wince {
- CONFIG(debug, debug|release):{
- addPlugins.files = $$QT_BUILD_TREE/plugins/imageformats/qico4d.dll
- } else {
- addPlugins.files = $$QT_BUILD_TREE/plugins/imageformats/qico4.dll
- }
- addPlugins.path = imageformats
- DEPLOYMENT += addPlugins
-}
TESTDATA += icons/*
android:RESOURCES+=qicoimageformat.qrc
diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp
index a0914b7700..4218d0751f 100644
--- a/tests/auto/gui/image/qicon/tst_qicon.cpp
+++ b/tests/auto/gui/image/qicon/tst_qicon.cpp
@@ -393,7 +393,6 @@ void tst_QIcon::addFile()
icon.addFile(QLatin1String(":/styles/commonstyle/images/standardbutton-save-32.png"), QSize(), QIcon::Selected);
icon.addFile(QLatin1String(":/styles/commonstyle/images/standardbutton-save-128.png"), QSize(), QIcon::Selected);
-#ifndef Q_OS_WINCE
QVERIFY(icon.pixmap(16, QIcon::Normal).toImage() ==
QPixmap(QLatin1String(":/styles/commonstyle/images/standardbutton-open-16.png")).toImage());
QVERIFY(icon.pixmap(32, QIcon::Normal).toImage() ==
@@ -406,13 +405,6 @@ void tst_QIcon::addFile()
QPixmap(QLatin1String(":/styles/commonstyle/images/standardbutton-save-32.png")).toImage());
QVERIFY(icon.pixmap(128, QIcon::Selected).toImage() ==
QPixmap(QLatin1String(":/styles/commonstyle/images/standardbutton-save-128.png")).toImage());
-#else
- // WinCE only includes the 16x16 images for size reasons
- QVERIFY(icon.pixmap(16, QIcon::Normal).toImage() ==
- QPixmap(QLatin1String(":/styles/commonstyle/images/standardbutton-open-16.png")).toImage());
- QVERIFY(icon.pixmap(16, QIcon::Selected).toImage() ==
- QPixmap(QLatin1String(":/styles/commonstyle/images/standardbutton-save-16.png")).toImage());
-#endif
}
static bool sizeLess(const QSize &a, const QSize &b)
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 85d258de5b..18812fd090 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -108,6 +108,7 @@ private slots:
void smoothScale();
void smoothScale2_data();
void smoothScale2();
+ void smoothScale3_data();
void smoothScale3();
void smoothScale4();
@@ -197,6 +198,9 @@ private slots:
void pixelColor();
void pixel();
+ void ditherGradient_data();
+ void ditherGradient();
+
private:
const QString m_prefix;
};
@@ -292,17 +296,13 @@ void tst_QImage::swap()
void tst_QImage::create()
{
bool cr = true;
-#if !defined(Q_OS_WINCE)
QT_TRY {
-#endif
//QImage image(7000000, 7000000, 8, 256, QImage::IgnoreEndian);
QImage image(7000000, 7000000, QImage::Format_Indexed8);
image.setColorCount(256);
cr = !image.isNull();
-#if !defined(Q_OS_WINCE)
} QT_CATCH (...) {
}
-#endif
QVERIFY( !cr );
}
@@ -1750,9 +1750,12 @@ static inline int rand8()
return int(256. * (qrand() / (RAND_MAX + 1.0)));
}
-// compares img.scale against the bilinear filtering used by QPainter
-void tst_QImage::smoothScale3()
+void tst_QImage::smoothScale3_data()
{
+ QTest::addColumn<QImage>("img");
+ QTest::addColumn<qreal>("scale_x");
+ QTest::addColumn<qreal>("scale_y");
+
QImage img(128, 128, QImage::Format_RGB32);
for (int y = 0; y < img.height(); ++y) {
for (int x = 0; x < img.width(); ++x) {
@@ -1765,36 +1768,49 @@ void tst_QImage::smoothScale3()
}
}
- qreal scales[2] = { .5, 2 };
+ QTest::newRow("(0.5, 0.5)") << img << qreal(0.5) << qreal(0.5);
+ QTest::newRow("(0.5, 1.0)") << img << qreal(0.5) << qreal(1.0);
+ QTest::newRow("(1.0, 0.5)") << img << qreal(1.0) << qreal(0.5);
+ QTest::newRow("(0.5, 2.0)") << img << qreal(0.5) << qreal(2.0);
+ QTest::newRow("(1.0, 2.0)") << img << qreal(1.0) << qreal(2.0);
+ QTest::newRow("(2.0, 0.5)") << img << qreal(2.0) << qreal(0.5);
+ QTest::newRow("(2.0, 1.0)") << img << qreal(2.0) << qreal(1.0);
+ QTest::newRow("(2.0, 2.0)") << img << qreal(2) << qreal(2);
+}
+// compares img.scale against the bilinear filtering used by QPainter
+void tst_QImage::smoothScale3()
+{
+ QFETCH(QImage, img);
+ QFETCH(qreal, scale_x);
+ QFETCH(qreal, scale_y);
- for (int i = 0; i < 2; ++i) {
- QImage a = img.scaled(img.size() * scales[i], Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- QImage b(a.size(), a.format());
- b.fill(0x0);
+ QImage a = img.scaled(img.width() * scale_x, img.height() * scale_y, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ QImage b(a.size(), a.format());
+ b.fill(0x0);
- QPainter p(&b);
- p.setRenderHint(QPainter::SmoothPixmapTransform);
- p.scale(scales[i], scales[i]);
- p.drawImage(0, 0, img);
- p.end();
- int err = 0;
-
- for (int y = 0; y < a.height(); ++y) {
- for (int x = 0; x < a.width(); ++x) {
- QRgb ca = a.pixel(x, y);
- QRgb cb = b.pixel(x, y);
-
- // tolerate a little bit of rounding errors
- bool r = true;
- r &= qAbs(qRed(ca) - qRed(cb)) <= 18;
- r &= qAbs(qGreen(ca) - qGreen(cb)) <= 18;
- r &= qAbs(qBlue(ca) - qBlue(cb)) <= 18;
- if (!r)
- err++;
- }
+ QPainter p(&b);
+ p.setRenderHint(QPainter::SmoothPixmapTransform);
+ p.scale(scale_x, scale_y);
+ p.drawImage(0, 0, img);
+ p.end();
+ int err = 0;
+
+ for (int y = 0; y < a.height(); ++y) {
+ for (int x = 0; x < a.width(); ++x) {
+ QRgb ca = a.pixel(x, y);
+ QRgb cb = b.pixel(x, y);
+
+ // tolerate a little bit of rounding errors
+ int tolerance = 3;
+ bool r = true;
+ r &= qAbs(qRed(ca) - qRed(cb)) <= tolerance;
+ r &= qAbs(qGreen(ca) - qGreen(cb)) <= tolerance;
+ r &= qAbs(qBlue(ca) - qBlue(cb)) <= tolerance;
+ if (!r)
+ err++;
}
- QCOMPARE(err, 0);
}
+ QCOMPARE(err, 0);
}
// Tests smooth upscale is smooth
@@ -1819,11 +1835,7 @@ void tst_QImage::smoothScale4()
void tst_QImage::smoothScaleBig()
{
-#if defined(Q_OS_WINCE)
- int bigValue = 2000;
-#else
int bigValue = 200000;
-#endif
QImage tall(4, bigValue, QImage::Format_ARGB32);
tall.fill(0x0);
@@ -3222,5 +3234,78 @@ void tst_QImage::pixel()
}
}
+void tst_QImage::ditherGradient_data()
+{
+ QTest::addColumn<QImage>("image");
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<int>("flags");
+ QTest::addColumn<int>("minimumExpectedGradient");
+
+ QImage rgb32(256, 16, QImage::Format_RGB32);
+ QLinearGradient gradient(QRectF(rgb32.rect()).topLeft(), QRectF(rgb32.rect()).topRight());
+ gradient.setColorAt(0.0, QColor(0, 0, 0));
+ gradient.setColorAt(1.0, QColor(255, 255, 255));
+ QPainter p;
+ p.begin(&rgb32);
+ p.fillRect(rgb32.rect(), gradient);
+ p.end();
+
+ QTest::newRow("rgb32 -> rgb444 (no dither)") << rgb32 << QImage::Format_RGB444 << 0 << 16;
+ QTest::newRow("rgb32 -> rgb444 (dithering)") << rgb32 << QImage::Format_RGB444 << int(Qt::PreferDither | Qt::OrderedDither) << 33;
+ QTest::newRow("rgb32 -> argb4444pm (dithering)") << rgb32 << QImage::Format_ARGB4444_Premultiplied << int(Qt::PreferDither | Qt::OrderedDither) << 33;
+ QTest::newRow("rgb32 -> rgb16 (no dither)") << rgb32 << QImage::Format_RGB16 << 0 << 32;
+ QTest::newRow("rgb32 -> rgb16 (dithering)") << rgb32 << QImage::Format_RGB16 << int(Qt::PreferDither | Qt::OrderedDither) << 65;
+ QTest::newRow("rgb32 -> rgb666 (no dither)") << rgb32 << QImage::Format_RGB666 << 0 << 64;
+ QTest::newRow("rgb32 -> rgb666 (dithering)") << rgb32 << QImage::Format_RGB666 << int(Qt::PreferDither | Qt::OrderedDither) << 129;
+
+ // Test we get the same results for opaque input in the ARGBPM implementation.
+ rgb32 = qMove(rgb32).convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ QTest::newRow("argb32pm -> argb4444pm (no dither)") << rgb32 << QImage::Format_ARGB4444_Premultiplied << 0 << 16;
+ QTest::newRow("argb32pm -> rgb444 (dithering)") << rgb32 << QImage::Format_RGB444 << int(Qt::PreferDither | Qt::OrderedDither) << 33;
+ QTest::newRow("argb32pm -> argb4444pm (dithering)") << rgb32 << QImage::Format_ARGB4444_Premultiplied << int(Qt::PreferDither | Qt::OrderedDither) << 33;
+ QTest::newRow("argb32pm -> argb8565pm (no dither)") << rgb32 << QImage::Format_ARGB8565_Premultiplied << 0 << 32;
+ QTest::newRow("argb32pm -> argb8565pm (dithering)") << rgb32 << QImage::Format_ARGB8565_Premultiplied << int(Qt::PreferDither | Qt::OrderedDither) << 65;
+ QTest::newRow("argb32pm -> argb6666pm (no dither)") << rgb32 << QImage::Format_ARGB6666_Premultiplied << 0 << 64;
+ QTest::newRow("argb32pm -> argb6666pm (dithering)") << rgb32 << QImage::Format_ARGB6666_Premultiplied << int(Qt::PreferDither | Qt::OrderedDither) << 129;
+
+ QImage rgb30(1024, 16, QImage::Format_RGB30);
+ QLinearGradient gradient30(QRectF(rgb30.rect()).topLeft(), QRectF(rgb30.rect()).topRight());
+ gradient30.setColorAt(0.0, QColor(0, 0, 0));
+ gradient30.setColorAt(1.0, QColor(255, 255, 255));
+ p.begin(&rgb30);
+ p.fillRect(rgb30.rect(), gradient30);
+ p.end();
+
+ QTest::newRow("rgb30 -> rgb32 (no dither)") << rgb30 << QImage::Format_RGB32 << 0 << 256;
+ QTest::newRow("rgb30 -> rgb32 (dithering)") << rgb30 << QImage::Format_RGB32 << int(Qt::PreferDither | Qt::OrderedDither) << 513;
+ QTest::newRow("rgb30 -> rgb888 (no dither)") << rgb30 << QImage::Format_RGB888 << 0 << 256;
+ QTest::newRow("rgb30 -> rgb888 (dithering)") << rgb30 << QImage::Format_RGB888 << int(Qt::PreferDither | Qt::OrderedDither) << 513;
+}
+
+void tst_QImage::ditherGradient()
+{
+ QFETCH(QImage, image);
+ QFETCH(QImage::Format, format);
+ QFETCH(int, flags);
+ QFETCH(int, minimumExpectedGradient);
+
+ QImage converted = image.convertToFormat(format, (Qt::ImageConversionFlags)flags);
+ int observedGradientSteps = 0;
+ int lastTotal = -1;
+ for (int i = 0; i < converted.width(); ++i) {
+ int total = 0;
+ for (int j = 0; j < converted.height(); ++j) {
+ uint c = converted.pixel(i, j);
+ QCOMPARE(qAlpha(c), 255);
+ total += qRed(c);
+ }
+ if (total > lastTotal) {
+ observedGradientSteps++;
+ lastTotal = total;
+ }
+ }
+ QVERIFY(observedGradientSteps >= minimumExpectedGradient);
+}
+
QTEST_GUILESS_MAIN(tst_QImage)
#include "tst_qimage.moc"
diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
index 4bf79cab05..9e747f8b11 100644
--- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
+++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
@@ -509,9 +509,6 @@ void tst_QImageWriter::saveToTemporaryFile()
QVERIFY(writer.write(image));
else
qWarning() << file.errorString();
-#if defined(Q_OS_WINCE)
- file.reset();
-#endif
QCOMPARE(QImage(writer.fileName()), image);
}
{
@@ -530,9 +527,6 @@ void tst_QImageWriter::saveToTemporaryFile()
QVERIFY2(file.open(), qPrintable(file.errorString()));
QImageWriter writer(&file, "PNG");
QVERIFY(writer.write(image));
-#if defined(Q_OS_WINCE)
- file.reset();
-#endif
QCOMPARE(QImage(writer.fileName()), image);
}
{
diff --git a/tests/auto/gui/image/qmovie/qmovie.pro b/tests/auto/gui/image/qmovie/qmovie.pro
index a04ad73b80..4a741ec154 100644
--- a/tests/auto/gui/image/qmovie/qmovie.pro
+++ b/tests/auto/gui/image/qmovie/qmovie.pro
@@ -5,8 +5,8 @@ qtHaveModule(widgets): QT += widgets
SOURCES += tst_qmovie.cpp
MOC_DIR=tmp
-!contains(QT_CONFIG, no-gif):DEFINES += QTEST_HAVE_GIF
-!contains(QT_CONFIG, no-jpeg):DEFINES += QTEST_HAVE_JPEG
+contains(QT_CONFIG, gif):DEFINES += QTEST_HAVE_GIF
+contains(QT_CONFIG, jpeg):DEFINES += QTEST_HAVE_JPEG
RESOURCES += resources.qrc
TESTDATA += animations/*
diff --git a/tests/auto/gui/image/qpixmap/qpixmap.pro b/tests/auto/gui/image/qpixmap/qpixmap.pro
index 5a4656998a..e6a020af1a 100644
--- a/tests/auto/gui/image/qpixmap/qpixmap.pro
+++ b/tests/auto/gui/image/qpixmap/qpixmap.pro
@@ -5,9 +5,7 @@ QT += core-private gui-private testlib
qtHaveModule(widgets): QT += widgets widgets-private
SOURCES += tst_qpixmap.cpp
-!wince:!winrt {
- win32:LIBS += -lgdi32 -luser32
-}
+win32:!winrt:LIBS += -lgdi32 -luser32
RESOURCES += qpixmap.qrc
TESTDATA += convertFromImage/* convertFromToHICON/* loadFromData/* images/*
diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
index 6adfe05fb0..79d3a57d73 100644
--- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
@@ -442,22 +442,16 @@ void tst_QPixmap::fill_data()
QTest::newRow(("syscolor_" + QByteArray::number(color)).constData())
<< uint(color) << true << false;
-#if defined (Q_OS_WINCE)
- QPixmap pixmap(1,1);
- if (QApplication::desktop()->grab().depth() >= 24) {
-#else
- QPixmap pixmap(1, 1); {
-#endif
- QTest::newRow("alpha_7f_red") << 0x7fff0000u << false << false;
- QTest::newRow("alpha_3f_blue") << 0x3f0000ffu << false << false;
- QTest::newRow("alpha_b7_green") << 0xbf00ff00u << false << false;
- QTest::newRow("alpha_7f_white") << 0x7fffffffu << false << false;
- QTest::newRow("alpha_3f_white") << 0x3fffffffu << false << false;
- QTest::newRow("alpha_b7_white") << 0xb7ffffffu << false << false;
- QTest::newRow("alpha_7f_black") << 0x7f000000u << false << false;
- QTest::newRow("alpha_3f_black") << 0x3f000000u << false << false;
- QTest::newRow("alpha_b7_black") << 0xbf000000u << false << false;
- }
+ QPixmap pixmap(1, 1);
+ QTest::newRow("alpha_7f_red") << 0x7fff0000u << false << false;
+ QTest::newRow("alpha_3f_blue") << 0x3f0000ffu << false << false;
+ QTest::newRow("alpha_b7_green") << 0xbf00ff00u << false << false;
+ QTest::newRow("alpha_7f_white") << 0x7fffffffu << false << false;
+ QTest::newRow("alpha_3f_white") << 0x3fffffffu << false << false;
+ QTest::newRow("alpha_b7_white") << 0xb7ffffffu << false << false;
+ QTest::newRow("alpha_7f_black") << 0x7f000000u << false << false;
+ QTest::newRow("alpha_3f_black") << 0x3f000000u << false << false;
+ QTest::newRow("alpha_b7_black") << 0xbf000000u << false << false;
QTest::newRow("bitmap_color0") << uint(Qt::color0) << true << true;
QTest::newRow("bitmap_color1") << uint(Qt::color1) << true << true;
@@ -891,9 +885,6 @@ void tst_QPixmap::fromWinHBITMAP()
HGDIOBJ old_brush = SelectObject(bitmap_dc, CreateSolidBrush(RGB(red, green, blue)));
Rectangle(bitmap_dc, 0, 0, 100, 100);
-#ifdef Q_OS_WINCE //the device context has to be deleted before QPixmap::fromWinHBITMAP()
- DeleteDC(bitmap_dc);
-#endif
QPixmap pixmap = qt_pixmapFromWinHBITMAP(bitmap);
QCOMPARE(pixmap.width(), 100);
QCOMPARE(pixmap.height(), 100);
@@ -906,9 +897,7 @@ void tst_QPixmap::fromWinHBITMAP()
DeleteObject(SelectObject(bitmap_dc, old_brush));
DeleteObject(SelectObject(bitmap_dc, bitmap));
-#ifndef Q_OS_WINCE
DeleteDC(bitmap_dc);
-#endif
ReleaseDC(0, display_dc);
}
@@ -1010,7 +999,6 @@ void tst_QPixmap::fromWinHICON_data()
void tst_QPixmap::fromWinHICON()
{
-#ifndef Q_OS_WINCE
QFETCH(int, width);
QFETCH(int, height);
QFETCH(QString, image);
@@ -1028,7 +1016,6 @@ void tst_QPixmap::fromWinHICON()
// between QImage::Format_ARGB32 and QImage::Format_ARGB32_Premultiplied, or elsewhere
QVERIFY(compareImages(imageFromHICON, imageFromFile));
-#endif // Q_OS_WINCE
}
#endif // Q_OS_WIN && !Q_OS_WINRT