From 95fc6f76b23c91ed1c75067a18cb663ce3afc018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolthera=20van=20H=C3=B6vell=20tot=20Westerflier?= Date: Mon, 1 Mar 2021 19:44:43 +0100 Subject: [PATCH] Readd heif tests and ensure nclx gets added to heif. See https://github.com/strukturag/libheif/issues/397 --- plugins/impex/heif/HeifExport.cpp | 6 +++++- plugins/impex/heif/tests/KisHeifTest.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/plugins/impex/heif/HeifExport.cpp b/plugins/impex/heif/HeifExport.cpp index 1016c4e1570..e408a56777d 100644 --- a/plugins/impex/heif/HeifExport.cpp +++ b/plugins/impex/heif/HeifExport.cpp @@ -189,6 +189,7 @@ KisImportExportErrorCode HeifExport::convert(KisDocument *document, QIODevice *i encoder = heif::Encoder(heif_compression_AV1); } + encoder.set_lossy_quality(quality); if (lossless) { //https://invent.kde.org/graphics/krita/-/merge_requests/530#note_169521 @@ -435,7 +436,10 @@ KisImportExportErrorCode HeifExport::convert(KisDocument *document, QIODevice *i // --- encode and write image - heif::ImageHandle handle = ctx.encode_image(img, encoder); + heif::Context::EncodingOptions options; + options.macOS_compatibility_workaround_no_nclx_profile = false; + + heif::ImageHandle handle = ctx.encode_image(img, encoder, options); // --- add Exif / XMP metadata diff --git a/plugins/impex/heif/tests/KisHeifTest.cpp b/plugins/impex/heif/tests/KisHeifTest.cpp index a35ff227133..7775d74faf2 100644 --- a/plugins/impex/heif/tests/KisHeifTest.cpp +++ b/plugins/impex/heif/tests/KisHeifTest.cpp @@ -227,9 +227,13 @@ void KisHeifTest::testLoadHDR() doc_png->setFileBatchMode(true); QScopedPointer doc_avif_pq(KisPart::instance()->createDocument()); doc_avif_pq->setFileBatchMode(true); + QScopedPointer doc_heif_pq(KisPart::instance()->createDocument()); + doc_heif_pq->setFileBatchMode(true); QScopedPointer doc_avif_hlg(KisPart::instance()->createDocument()); doc_avif_hlg->setFileBatchMode(true); + QScopedPointer doc_heif_hlg(KisPart::instance()->createDocument()); + doc_heif_hlg->setFileBatchMode(true); KisImportExportManager manager(doc_png.data()); @@ -238,11 +242,15 @@ void KisHeifTest::testLoadHDR() QVERIFY(loadingStatus.isOk()); KisImportExportManager (doc_avif_pq.data()).importDocument(QString("test_rgba_hdr_pq.avif"), QString()); + KisImportExportManager (doc_heif_pq.data()).importDocument(QString("test_rgba_hdr_pq.heif"), QString()); KisImportExportManager (doc_avif_hlg.data()).importDocument(QString("test_rgba_hdr_hlg.avif"), QString()); + KisImportExportManager (doc_heif_hlg.data()).importDocument(QString("test_rgba_hdr_hlg.heif"), QString()); doc_png->image()->initialRefreshGraph(); doc_avif_pq->image()->initialRefreshGraph(); + doc_heif_pq->image()->initialRefreshGraph(); doc_avif_hlg->image()->initialRefreshGraph(); + doc_heif_hlg->image()->initialRefreshGraph(); const KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace( @@ -253,15 +261,26 @@ void KisHeifTest::testLoadHDR() doc_png->image()->waitForDone(); KoColor pngColor(cs); + KoColor heifColor(cs); KoColor avifColor(cs); for (int y = 0; yimage()->height(); y++) { for (int x = 0; ximage()->width(); x++) { doc_png->image()->projection()->pixel(x, y, &pngColor); + doc_heif_pq->image()->projection()->pixel(x, y, &heifColor); doc_avif_pq->image()->projection()->pixel(x, y, &avifColor); QVERIFY2(cs->difference(pngColor.data(), avifColor.data()) <1, QString("Avif PQ color doesn't match PNG color, (%1, %2) %3 %4") .arg(x).arg(y).arg(pngColor.toXML()).arg(avifColor.toXML()).toLatin1()); + + QVERIFY2(cs->difference(pngColor.data(), heifColor.data()) <1, QString("Heif PQ color doesn't match PNG color, (%1, %2) %3 %4") + .arg(x).arg(y).arg(pngColor.toXML()).arg(heifColor.toXML()).toLatin1()); + + doc_heif_hlg->image()->projection()->pixel(x, y, &heifColor); + doc_avif_hlg->image()->projection()->pixel(x, y, &avifColor); + + QVERIFY2(cs->difference(heifColor.data(), avifColor.data()) <1, QString("Avif HLG color doesn't match heif color, (%1, %2) %3 %4") + .arg(x).arg(y).arg(heifColor.toXML()).arg(avifColor.toXML()).toLatin1()); } } }