From b0abe20d4b05e9e1e0800b8be64df15fa1660367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 2 Nov 2015 10:49:17 +0100 Subject: Darwin: Add QImage::toCGImage() conversion function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (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 Reviewed-by: Gabriel de Dietrich --- tests/auto/gui/image/qimage/tst_qimage.cpp | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests/auto/gui/image/qimage/tst_qimage.cpp') 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 #include +#ifdef Q_OS_DARWIN +#include +#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("format"); + QTest::addColumn("supported"); + + // Populate test data with supported status for all QImage formats. + QSet 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" -- cgit v1.2.3