-
-
Notifications
You must be signed in to change notification settings - Fork 56.4k
Closed
Description
Describe the feature and motivation
Suport for avif files was added to OpenCV a few versions ago, however the default mode for libavif is strict. In the wild there are many avif files which do not adhere to the spec strictly generated by common photo editing tools or CDN networks. We can overcome these limitations by passing an additional parameter to the avif decoder instance within OpenCV, which will yeild better support for avif files overall.
Additional context
This change is trivial any only needs 2 additions, I tested it on verison 4.9.0:
diff --git a/modules/imgcodecs/src/grfmt_avif.cpp b/modules/imgcodecs/src/grfmt_avif.cpp
index 4b39ada..fc5be30 100644
--- a/modules/imgcodecs/src/grfmt_avif.cpp
+++ b/modules/imgcodecs/src/grfmt_avif.cpp
@@ -140,6 +140,7 @@ AvifDecoder::AvifDecoder() {
m_buf_supported = true;
channels_ = 0;
decoder_ = avifDecoderCreate();
+ decoder_->strictFlags = AVIF_STRICT_DISABLED;
}
AvifDecoder::~AvifDecoder() {
@@ -163,6 +164,7 @@ bool AvifDecoder::checkSignature(const String &signature) const {
std::unique_ptr<avifDecoder, decltype(&avifDecoderDestroy)> decoder(
avifDecoderCreate(), avifDecoderDestroy);
if (!decoder) return false;
+ decoder->strictFlags = AVIF_STRICT_DISABLED;
OPENCV_AVIF_CHECK_STATUS(
avifDecoderSetIOMemory(
decoder.get(), reinterpret_cast<const uint8_t *>(signature.c_str()),