summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/image/qimage
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/image/qimage')
-rw-r--r--tests/auto/gui/image/qimage/images/jpeg_exif_utf8_comment.jpgbin0 -> 705 bytes
-rw-r--r--tests/auto/gui/image/qimage/qimage.pro3
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp224
3 files changed, 197 insertions, 30 deletions
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_utf8_comment.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_utf8_comment.jpg
new file mode 100644
index 0000000000..42b305f5b8
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/jpeg_exif_utf8_comment.jpg
Binary files differ
diff --git a/tests/auto/gui/image/qimage/qimage.pro b/tests/auto/gui/image/qimage/qimage.pro
index 56618e0bfa..b40866892e 100644
--- a/tests/auto/gui/image/qimage/qimage.pro
+++ b/tests/auto/gui/image/qimage/qimage.pro
@@ -7,4 +7,7 @@ qtConfig(c++11): CONFIG += c++11
android:!android-embedded: RESOURCES += qimage.qrc
+win32:!winrt: LIBS += -lgdi32 -luser32
+darwin: LIBS += -framework CoreGraphics
+
TESTDATA += images/*
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 34b20a5cca..5ffd75f931 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -44,6 +44,10 @@
#include <CoreGraphics/CoreGraphics.h>
#endif
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+# include <qt_windows.h>
+#endif
+
Q_DECLARE_METATYPE(QImage::Format)
Q_DECLARE_METATYPE(Qt::GlobalColor)
@@ -116,6 +120,7 @@ private slots:
void smoothScale2();
void smoothScale3_data();
void smoothScale3();
+ void smoothScale4_data();
void smoothScale4();
void smoothScaleBig();
@@ -192,6 +197,7 @@ private slots:
void exif_QTBUG45865();
void exifInvalidData_data();
void exifInvalidData();
+ void exifReadComments();
void cleanupFunctions();
@@ -224,6 +230,11 @@ private slots:
void convertColorTable();
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+ void toWinHBITMAP_data();
+ void toWinHBITMAP();
+#endif // Q_OS_WIN && !Q_OS_WINRT
+
private:
const QString m_prefix;
};
@@ -281,6 +292,12 @@ static QLatin1String formatToString(QImage::Format format)
return QLatin1String("Alpha8");
case QImage::Format_Grayscale8:
return QLatin1String("Grayscale8");
+ case QImage::Format_RGBX64:
+ return QLatin1String("RGBx64");
+ case QImage::Format_RGBA64:
+ return QLatin1String("RGBA64");
+ case QImage::Format_RGBA64_Premultiplied:
+ return QLatin1String("RGBA64pm");
default:
break;
};
@@ -1665,29 +1682,30 @@ void tst_QImage::smoothScale()
// test area sampling
void tst_QImage::smoothScale2_data()
{
- QTest::addColumn<int>("format");
+ QTest::addColumn<QImage::Format>("format");
QTest::addColumn<int>("size");
int sizes[] = { 2, 3, 4, 6, 7, 8, 10, 16, 20, 32, 40, 64, 100, 101, 128, 0 };
- QImage::Format formats[] = { QImage::Format_RGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_Invalid };
+ QImage::Format formats[] = { QImage::Format_RGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_RGBX64, QImage::Format_RGBA64_Premultiplied, QImage::Format_Invalid };
for (int j = 0; formats[j] != QImage::Format_Invalid; ++j) {
- QByteArray formatstr = formats[j] == QImage::Format_RGB32 ? QByteArrayLiteral("rgb32") : QByteArrayLiteral("argb32pm");
+ QString formatstr = formatToString(formats[j]);
for (int i = 0; sizes[i] != 0; ++i) {
const QByteArray sizeB = QByteArray::number(sizes[i]);
- QTest::newRow((formatstr + ' ' + sizeB + 'x' + sizeB).constData())
- << (int)formats[j] << sizes[i];
+ QTest::newRow(QString("%1 %2x%2").arg(formatstr).arg(sizes[i]).toUtf8()) << formats[j] << sizes[i];
}
}
}
void tst_QImage::smoothScale2()
{
- QFETCH(int, format);
+ QFETCH(QImage::Format, format);
QFETCH(int, size);
- QRgb expected = format == QImage::Format_RGB32 ? qRgb(63, 127, 255) : qRgba(31, 63, 127, 127);
+ bool opaque = (format == QImage::Format_RGB32 || format == QImage::Format_RGBX64);
- QImage img(size, size, (QImage::Format)format);
+ QRgb expected = opaque ? qRgb(63, 127, 255) : qRgba(31, 63, 127, 127);
+
+ QImage img(size, size, format);
img.fill(expected);
// scale x down, y down
@@ -1824,21 +1842,31 @@ void tst_QImage::smoothScale3()
}
// Tests smooth upscale is smooth
+void tst_QImage::smoothScale4_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+
+ QTest::newRow("RGB32") << QImage::Format_RGB32;
+ QTest::newRow("RGBx64") << QImage::Format_RGBX64;
+}
+
void tst_QImage::smoothScale4()
{
- QImage img(4, 4, QImage::Format_RGB32);
+ QFETCH(QImage::Format, format);
+ QImage img(4, 4, format);
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
img.setPixel(x, y, qRgb(x * 255 / 3, y * 255 / 3, 0));
}
}
QImage scaled = img.scaled(37, 23, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ QCOMPARE(scaled.format(), format);
for (int y = 0; y < scaled.height(); ++y) {
for (int x = 0; x < scaled.width(); ++x) {
if (x > 0)
- QVERIFY(qRed(scaled.pixel(x, y)) >= qRed(scaled.pixel(x - 1, y)));
+ QVERIFY(scaled.pixelColor(x, y).redF() >= scaled.pixelColor(x - 1, y).redF());
if (y > 0)
- QVERIFY(qGreen(scaled.pixel(x, y)) >= qGreen(scaled.pixel(x, y - 1)));
+ QVERIFY(scaled.pixelColor(x, y).greenF() >= scaled.pixelColor(x, y - 1).greenF());
}
}
}
@@ -2337,7 +2365,9 @@ void tst_QImage::rgbSwapped_data()
{
QTest::addColumn<QImage::Format>("format");
- for (int i = QImage::Format_Indexed8; i < QImage::Format_Alpha8; ++i) {
+ for (int i = QImage::Format_Indexed8; i < QImage::NImageFormats; ++i) {
+ if (i == QImage::Format_Alpha8 || i == QImage::Format_Grayscale8)
+ continue;
QTest::addRow("%s", formatToString(QImage::Format(i)).data()) << QImage::Format(i);
}
}
@@ -2505,14 +2535,7 @@ void tst_QImage::mirrored()
void tst_QImage::inplaceRgbSwapped_data()
{
- QTest::addColumn<QImage::Format>("format");
-
- QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied;
- QTest::newRow("Format_RGBA8888") << QImage::Format_RGBA8888;
- QTest::newRow("Format_A2RGB30_Premultiplied") << QImage::Format_A2RGB30_Premultiplied;
- QTest::newRow("Format_RGB888") << QImage::Format_RGB888;
- QTest::newRow("Format_RGB16") << QImage::Format_RGB16;
- QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8;
+ rgbSwapped_data();
}
void tst_QImage::inplaceRgbSwapped()
@@ -2543,9 +2566,9 @@ void tst_QImage::inplaceRgbSwapped()
for (int i = 0; i < imageSwapped.width(); ++i) {
QRgb referenceColor = testColor[i];
QRgb swappedColor = imageSwapped.pixel(i, 0);
- QCOMPARE(qRed(swappedColor) & 0xf8, qBlue(referenceColor) & 0xf8);
- QCOMPARE(qGreen(swappedColor) & 0xf8, qGreen(referenceColor) & 0xf8);
- QCOMPARE(qBlue(swappedColor) & 0xf8, qRed(referenceColor) & 0xf8);
+ QCOMPARE(qRed(swappedColor) & 0xf0, qBlue(referenceColor) & 0xf0);
+ QCOMPARE(qGreen(swappedColor) & 0xf0, qGreen(referenceColor) & 0xf0);
+ QCOMPARE(qBlue(swappedColor) & 0xf0, qRed(referenceColor) & 0xf0);
}
QCOMPARE(imageSwapped.constScanLine(0), orginalPtr);
@@ -2761,9 +2784,13 @@ void tst_QImage::genericRgbConversion_data()
QTest::addColumn<QImage::Format>("format");
QTest::addColumn<QImage::Format>("dest_format");
- for (int i = QImage::Format_RGB32; i < QImage::Format_Alpha8; ++i) {
+ for (int i = QImage::Format_RGB32; i < QImage::NImageFormats; ++i) {
+ if (i == QImage::Format_Alpha8 || i == QImage::Format_Grayscale8)
+ continue;
const QLatin1String formatI = formatToString(QImage::Format(i));
- for (int j = QImage::Format_RGB32; j < QImage::Format_Alpha8; ++j) {
+ for (int j = QImage::Format_RGB32; j < QImage::NImageFormats; ++j) {
+ if (j == QImage::Format_Alpha8 || j == QImage::Format_Grayscale8)
+ continue;
if (i == j)
continue;
QTest::addRow("%s -> %s", formatI.data(), formatToString(QImage::Format(j)).data())
@@ -2800,8 +2827,12 @@ void tst_QImage::inplaceRgbConversion_data()
QTest::addColumn<QImage::Format>("format");
QTest::addColumn<QImage::Format>("dest_format");
- for (int i = QImage::Format_RGB32; i < QImage::Format_Alpha8; ++i) {
- for (int j = QImage::Format_RGB32; j < QImage::Format_Alpha8; ++j) {
+ for (int i = QImage::Format_RGB32; i < QImage::NImageFormats; ++i) {
+ if (i == QImage::Format_Alpha8 || i == QImage::Format_Grayscale8)
+ continue;
+ for (int j = QImage::Format_RGB32; j < QImage::NImageFormats; ++j) {
+ if (j == QImage::Format_Alpha8 || j == QImage::Format_Grayscale8)
+ continue;
if (i == j)
continue;
QTest::addRow("%s -> %s", formatToString(QImage::Format(i)).data(), formatToString(QImage::Format(j)).data())
@@ -2834,10 +2865,10 @@ void tst_QImage::inplaceRgbConversion()
QCOMPARE(qGreen(convertedColor) & 0xF0, i * 16);
}
}
- if (image.depth() == imageConverted.depth())
+ if (qt_depthForFormat(format) == qt_depthForFormat(dest_format))
QCOMPARE(imageConverted.constScanLine(0), originalPtr);
- {
+ if (qt_depthForFormat(format) <= 32) {
// Test attempted inplace conversion of images created on existing buffer
static const quint32 readOnlyData[] = { 0xff0102ffU, 0xff0506ffU, 0xff0910ffU, 0xff1314ffU };
quint32 readWriteData[] = { 0xff0102ffU, 0xff0506ffU, 0xff0910ffU, 0xff1314ffU };
@@ -2970,7 +3001,9 @@ void tst_QImage::invertPixelsRGB_data()
{
QTest::addColumn<QImage::Format>("image_format");
- for (int i = QImage::Format_RGB32; i < QImage::Format_Alpha8; ++i) {
+ for (int i = QImage::Format_RGB32; i < QImage::NImageFormats; ++i) {
+ if (i == QImage::Format_Alpha8 || i == QImage::Format_Grayscale8)
+ continue;
QTest::addRow("%s", formatToString(QImage::Format(i)).data()) << QImage::Format(i);
}
}
@@ -3068,6 +3101,34 @@ void tst_QImage::exifInvalidData()
QVERIFY(!image.isNull());
}
+void tst_QImage::exifReadComments()
+{
+ QImage image;
+ QVERIFY(image.load(m_prefix + "jpeg_exif_utf8_comment.jpg"));
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.textKeys().size(), 1);
+ QCOMPARE(image.textKeys().first(), "Description");
+ // check if exif comment is read as utf-8
+ QCOMPARE(image.text("Description"), QString::fromUtf8("some unicode chars: ÖÄÜ€@"));
+
+ QByteArray ba;
+ {
+ QBuffer buf(&ba);
+ QVERIFY(buf.open(QIODevice::WriteOnly));
+ QVERIFY(image.save(&buf, "JPG"));
+ }
+ QVERIFY(!ba.isEmpty());
+ image = QImage();
+ QCOMPARE(image.textKeys().size(), 0);
+ {
+ QBuffer buf(&ba);
+ QVERIFY(buf.open(QIODevice::ReadOnly));
+ QVERIFY(image.load(&buf, "JPG"));
+ }
+ // compare written (and reread) description text
+ QCOMPARE(image.text("Description"), QString::fromUtf8("some unicode chars: ÖÄÜ€@"));
+}
+
static void cleanupFunction(void* info)
{
bool *called = static_cast<bool*>(info);
@@ -3473,5 +3534,108 @@ void tst_QImage::convertColorTable()
QCOMPARE(rgb32.pixel(0,0), 0xffffffff);
}
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+QT_BEGIN_NAMESPACE
+Q_GUI_EXPORT HBITMAP qt_imageToWinHBITMAP(const QImage &p, int hbitmapFormat = 0);
+Q_GUI_EXPORT QImage qt_imageFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0);
+QT_END_NAMESPACE
+
+static inline QColor COLORREFToQColor(COLORREF cr)
+{
+ return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr));
+}
+
+void tst_QImage::toWinHBITMAP_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<QColor>("color");
+ QTest::addColumn<QColor>("bottomRightColor");
+
+ const QColor red(Qt::red);
+ const QColor green(Qt::green);
+ const QColor blue(Qt::blue);
+ const QColor gray(Qt::gray);
+ const QColor gray555(0x5a, 0x5a, 0x5a); // Note: Interpolation 8<->5 bit occurs.
+ const QColor white(Qt::white);
+ const QColor black(Qt::black);
+
+ QTest::newRow("argb32p-red") << QImage::Format_ARGB32_Premultiplied << red << gray;
+ QTest::newRow("argb32p-green") << QImage::Format_ARGB32_Premultiplied << green << gray;
+ QTest::newRow("argb32p-blue") << QImage::Format_ARGB32_Premultiplied << blue << gray;
+ QTest::newRow("rgb888-red") << QImage::Format_RGB888 << red << gray;
+ QTest::newRow("rgb888-green") << QImage::Format_RGB888 << green << gray;
+ QTest::newRow("rgb888-blue") << QImage::Format_RGB888 << blue << gray;
+ QTest::newRow("indexed8-red") << QImage::Format_Indexed8 << red << gray;
+ QTest::newRow("indexed8-green") << QImage::Format_Indexed8 << green << gray;
+ QTest::newRow("indexed8-blue") << QImage::Format_Indexed8 << blue << gray;
+ QTest::newRow("rgb555-red") << QImage::Format_RGB555 << red << gray555;
+ QTest::newRow("rgb555-green") << QImage::Format_RGB555 << green << gray555;
+ QTest::newRow("rgb555-blue") << QImage::Format_RGB555 << blue << gray555;
+ QTest::newRow("mono") << QImage::Format_Mono << white << black;
+}
+
+// Test image filled with color, black pixel at botttom right corner.
+static inline QImage createTestImage(QImage::Format format, int width, int height,
+ const QColor &fillColor, const QColor &bottomRightColor)
+{
+ QImage image(QSize(width, height), format);
+ image.fill(fillColor);
+ QPainter painter(&image);
+ QPen pen = painter.pen();
+ pen.setColor(bottomRightColor);
+ painter.setPen(pen);
+ painter.drawPoint(width -1, height - 1);
+ return image;
+}
+
+void tst_QImage::toWinHBITMAP()
+{
+ static const int width = 73;
+ static const int height = 57;
+
+ QFETCH(QImage::Format, format);
+ QFETCH(QColor, color);
+ QFETCH(QColor, bottomRightColor);
+
+ // Cannot paint on indexed/mono images.
+ const QImage image = format == QImage::Format_Indexed8 || format == QImage::Format_Mono
+ ? createTestImage(QImage::Format_RGB32, width, height, color, bottomRightColor).convertToFormat(format)
+ : createTestImage(format, width, height, color, bottomRightColor);
+
+ const HBITMAP bitmap = qt_imageToWinHBITMAP(image);
+
+ QVERIFY(bitmap != 0);
+
+ // Verify size
+ BITMAP bitmapInfo;
+ memset(&bitmapInfo, 0, sizeof(BITMAP));
+
+ const int res = GetObject(bitmap, sizeof(BITMAP), &bitmapInfo);
+ QVERIFY(res);
+ QCOMPARE(width, int(bitmapInfo.bmWidth));
+ QCOMPARE(height, int(bitmapInfo.bmHeight));
+
+ const HDC displayDc = GetDC(0);
+ const HDC bitmapDc = CreateCompatibleDC(displayDc);
+
+ const HBITMAP nullBitmap = static_cast<HBITMAP>(SelectObject(bitmapDc, bitmap));
+
+ QCOMPARE(COLORREFToQColor(GetPixel(bitmapDc, 0, 0)), color);
+ QCOMPARE(COLORREFToQColor(GetPixel(bitmapDc, width - 1, 3)), color);
+ QCOMPARE(COLORREFToQColor(GetPixel(bitmapDc, 3, height - 1)), color);
+ QCOMPARE(COLORREFToQColor(GetPixel(bitmapDc, width - 1, height - 1)), bottomRightColor);
+
+ const QImage convertedBack = qt_imageFromWinHBITMAP(bitmap);
+ QCOMPARE(convertedBack.convertToFormat(QImage::Format_ARGB32_Premultiplied),
+ image.convertToFormat(QImage::Format_ARGB32_Premultiplied));
+
+ // Clean up
+ SelectObject(bitmapDc, nullBitmap);
+ DeleteObject(bitmap);
+ DeleteDC(bitmapDc);
+ ReleaseDC(0, displayDc);
+}
+#endif // Q_OS_WIN && !Q_OS_WINRT
+
QTEST_GUILESS_MAIN(tst_QImage)
#include "tst_qimage.moc"