summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@theqtcompany.com>2015-11-02 10:49:17 +0100
committerMorten Johan Sørvig <morten.sorvig@qt.io>2016-08-11 21:21:05 +0000
commitb0abe20d4b05e9e1e0800b8be64df15fa1660367 (patch)
tree89a5d8ee7f98f7c015ff896f63526ce9904777b6 /tests
parentdfae6a7593a6bb4ad6accc30d6aaf01a98bc2a6f (diff)
Darwin: Add QImage::toCGImage() conversion function
(Move QT_FORWARD_DECLARE_CG to qglobal.h) This function converts to CGImage for supported formats. This is done by creating a CGImageRef that reuses the QImage data. The CGImage and QImage ref counting systems are bridged, implemented by using CGDataProvider that holds a copy of the QImage. Unlike the previous internal implementation this public version does not implicitly convert unsupported formats to ARGB32_Premultiplied. See included documentation for the complete description. Change-Id: Ie3984a7a8331e02a6f1c42943caaf76854e93538 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 18812fd090..a1ab812aaa 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -39,6 +39,10 @@
#include <private/qimage_p.h>
#include <private/qdrawhelper_p.h>
+#ifdef Q_OS_DARWIN
+#include <CoreGraphics/CoreGraphics.h>
+#endif
+
Q_DECLARE_METATYPE(QImage::Format)
Q_DECLARE_METATYPE(Qt::GlobalColor)
@@ -201,6 +205,11 @@ private slots:
void ditherGradient_data();
void ditherGradient();
+#ifdef Q_OS_DARWIN
+ void toCGImage_data();
+ void toCGImage();
+#endif
+
private:
const QString m_prefix;
};
@@ -3307,5 +3316,41 @@ void tst_QImage::ditherGradient()
QVERIFY(observedGradientSteps >= minimumExpectedGradient);
}
+#ifdef Q_OS_DARWIN
+
+void tst_QImage::toCGImage_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<bool>("supported");
+
+ // Populate test data with supported status for all QImage formats.
+ QSet<QImage::Format> supported =
+ { QImage::Format_ARGB32, QImage::Format_RGB32, QImage::Format_RGBA8888_Premultiplied,
+ QImage::Format_RGBA8888, QImage::Format_RGBX8888, QImage::Format_ARGB32_Premultiplied };
+
+ for (int i = QImage::Format_Invalid; i < QImage::Format_Grayscale8; ++i) {
+ QTest::newRow(qPrintable(formatToString(QImage::Format(i))))
+ << QImage::Format(i) << supported.contains(QImage::Format(i));
+ }
+}
+
+// Verify that toCGImage() returns a valid CGImageRef for supported image formats.
+void tst_QImage::toCGImage()
+{
+ QFETCH(QImage::Format, format);
+ QFETCH(bool, supported);
+
+ QImage qimage(64, 64, format);
+ qimage.fill(Qt::red);
+
+ CGImageRef cgimage = qimage.toCGImage();
+ QCOMPARE(cgimage != nullptr, supported);
+
+ CGImageRelease(cgimage);
+}
+
+#endif
+
+
QTEST_GUILESS_MAIN(tst_QImage)
#include "tst_qimage.moc"