diff --git a/src/plugins/imageformats/shared/qiiofhelpers.cpp b/src/plugins/imageformats/shared/qiiofhelpers.cpp index 312f64e8..b96fc079 100644 --- a/src/plugins/imageformats/shared/qiiofhelpers.cpp +++ b/src/plugins/imageformats/shared/qiiofhelpers.cpp @@ -114,8 +114,10 @@ bool QIIOFHelper::initRead() cgImageSource = CGImageSourceCreateWithDataProvider(cgDataProvider, nullptr); - if (cgImageSource) - cfImageDict = CGImageSourceCopyPropertiesAtIndex(cgImageSource, 0, nullptr); + if (cgImageSource) { + auto primaryIndex = CGImageSourceGetPrimaryImageIndex(cgImageSource); + cfImageDict = CGImageSourceCopyPropertiesAtIndex(cgImageSource, primaryIndex, nullptr); + } return (cgImageSource); } @@ -125,7 +127,8 @@ bool QIIOFHelper::readImage(QImage *out) if (!out || !initRead()) return false; - QCFType cgImage = CGImageSourceCreateImageAtIndex(cgImageSource, 0, nullptr); + auto primaryIndex = CGImageSourceGetPrimaryImageIndex(cgImageSource); + QCFType cgImage = CGImageSourceCreateImageAtIndex(cgImageSource, primaryIndex, nullptr); if (!cgImage) return false; diff --git a/tests/auto/heif/CMakeLists.txt b/tests/auto/heif/CMakeLists.txt index 3fc310ee..48e97be1 100644 --- a/tests/auto/heif/CMakeLists.txt +++ b/tests/auto/heif/CMakeLists.txt @@ -16,6 +16,8 @@ qt_internal_add_test(tst_qheif set(heif_resource_files "../../shared/images/heif/col320x480.heic" "../../shared/images/heif/newlogoCCW.heic" + "../../shared/images/heif/primary-index-0.heic" + "../../shared/images/heif/primary-index-1.heic" ) qt_internal_add_resource(tst_qheif "heif" diff --git a/tests/auto/heif/tst_qheif.cpp b/tests/auto/heif/tst_qheif.cpp index 7c90d91f..be0af576 100644 --- a/tests/auto/heif/tst_qheif.cpp +++ b/tests/auto/heif/tst_qheif.cpp @@ -15,6 +15,9 @@ private slots: void readProperties_data(); void readProperties(); void writeImage(); + + void primaryIndex_data(); + void primaryIndex(); }; void tst_qheif::initTestCase() @@ -123,5 +126,22 @@ void tst_qheif::writeImage() } } +void tst_qheif::primaryIndex_data() +{ + QTest::addColumn("primaryIndex"); + + QTest::newRow("0 (first/default)") << 0; + QTest::newRow("1 (second)") << 1; +} + +void tst_qheif::primaryIndex() +{ + QFETCH(int, primaryIndex); + + QImage image(QString(":/heif/primary-index-%1.heic").arg(primaryIndex)); + QVERIFY(!image.isNull()); + QCOMPARE(image.pixelColor(50, 50), QColor(Qt::green)); +} + QTEST_MAIN(tst_qheif) #include "tst_qheif.moc" diff --git a/tests/shared/images/heif/primary-index-0.heic b/tests/shared/images/heif/primary-index-0.heic new file mode 100644 index 00000000..f2a86b9d Binary files /dev/null and b/tests/shared/images/heif/primary-index-0.heic differ diff --git a/tests/shared/images/heif/primary-index-1.heic b/tests/shared/images/heif/primary-index-1.heic new file mode 100644 index 00000000..4014136b Binary files /dev/null and b/tests/shared/images/heif/primary-index-1.heic differ