When the AVIF container does not contain a color profile, fallback to the color OBU's nclx
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ea4974..06b1280 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
### Added
- new helper function `avifPeekCompatibleFileType()`
- expose ioStats on avifDecoder again (currently only interesting when reading items)
+- When the AVIF container does not contain a color profile, fallback to the color OBU's nclx
### Changed
- Fixed some warnings (removed unused variables and a bad cast)
diff --git a/src/codec_aom.c b/src/codec_aom.c
index 6fc32a0..262bd36 100644
--- a/src/codec_aom.c
+++ b/src/codec_aom.c
@@ -152,6 +152,16 @@
image->yuvFormat = yuvFormat;
image->yuvRange = (codec->internal->image->range == AOM_CR_STUDIO_RANGE) ? AVIF_RANGE_LIMITED : AVIF_RANGE_FULL;
+ if (image->profileFormat == AVIF_PROFILE_FORMAT_NONE) {
+ // If the AVIF container doesn't provide a color profile, allow the AV1 OBU to provide one as a fallback
+ avifNclxColorProfile nclx;
+ nclx.colourPrimaries = (uint16_t)codec->internal->image->cp;
+ nclx.transferCharacteristics = (uint16_t)codec->internal->image->tc;
+ nclx.matrixCoefficients = (uint16_t)codec->internal->image->mc;
+ nclx.fullRangeFlag = image->yuvRange;
+ avifImageSetProfileNCLX(image, &nclx);
+ }
+
avifPixelFormatInfo formatInfo;
avifGetPixelFormatInfo(yuvFormat, &formatInfo);
diff --git a/src/codec_dav1d.c b/src/codec_dav1d.c
index eb45bef..a2f3cf0 100644
--- a/src/codec_dav1d.c
+++ b/src/codec_dav1d.c
@@ -145,6 +145,16 @@
image->yuvFormat = yuvFormat;
image->yuvRange = codec->internal->colorRange;
+ if (image->profileFormat == AVIF_PROFILE_FORMAT_NONE) {
+ // If the AVIF container doesn't provide a color profile, allow the AV1 OBU to provide one as a fallback
+ avifNclxColorProfile nclx;
+ nclx.colourPrimaries = (uint16_t)dav1dImage->seq_hdr->pri;
+ nclx.transferCharacteristics = (uint16_t)dav1dImage->seq_hdr->trc;
+ nclx.matrixCoefficients = (uint16_t)dav1dImage->seq_hdr->mtrx;
+ nclx.fullRangeFlag = image->yuvRange;
+ avifImageSetProfileNCLX(image, &nclx);
+ }
+
avifPixelFormatInfo formatInfo;
avifGetPixelFormatInfo(yuvFormat, &formatInfo);