Skip to content

Commit

Permalink
Readd heif tests and ensure nclx gets added to heif.
Browse files Browse the repository at this point in the history
  • Loading branch information
therahedwig committed Mar 1, 2021
1 parent f585d30 commit 95fc6f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/impex/heif/HeifExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions plugins/impex/heif/tests/KisHeifTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,13 @@ void KisHeifTest::testLoadHDR()
doc_png->setFileBatchMode(true);
QScopedPointer<KisDocument> doc_avif_pq(KisPart::instance()->createDocument());
doc_avif_pq->setFileBatchMode(true);
QScopedPointer<KisDocument> doc_heif_pq(KisPart::instance()->createDocument());
doc_heif_pq->setFileBatchMode(true);

QScopedPointer<KisDocument> doc_avif_hlg(KisPart::instance()->createDocument());
doc_avif_hlg->setFileBatchMode(true);
QScopedPointer<KisDocument> doc_heif_hlg(KisPart::instance()->createDocument());
doc_heif_hlg->setFileBatchMode(true);

KisImportExportManager manager(doc_png.data());

Expand All @@ -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(
Expand All @@ -253,15 +261,26 @@ void KisHeifTest::testLoadHDR()
doc_png->image()->waitForDone();

KoColor pngColor(cs);
KoColor heifColor(cs);
KoColor avifColor(cs);

for (int y = 0; y<doc_png->image()->height(); y++) {
for (int x = 0; x<doc_png->image()->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());
}
}
}
Expand Down

0 comments on commit 95fc6f7

Please sign in to comment.