Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Disable strict mode when reading avif files #26011

@pm-incyan

Description

@pm-incyan

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()),

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions