Skip to content

Commit 8e5dbc0

Browse files
authored
Merge pull request opencv#26298 from sturkmen72:avif
Proposed solution for the issue 26297 opencv#26298 closes opencv#26297 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
1 parent 1909ac8 commit 8e5dbc0

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ OCV_OPTION(WITH_1394 "Include IEEE1394 support" OFF
216216
OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/visionOS/Mac)" ON
217217
VISIBLE_IF APPLE
218218
VERIFY HAVE_AVFOUNDATION)
219-
OCV_OPTION(WITH_AVIF "Enable AVIF support" OFF
219+
OCV_OPTION(WITH_AVIF "Enable AVIF support" ON
220220
VERIFY HAVE_AVIF)
221221
OCV_OPTION(WITH_CAP_IOS "Enable iOS video capture" ON
222222
VISIBLE_IF IOS

modules/imgcodecs/src/grfmt_avif.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ static constexpr size_t kAvifSignatureSize = 500;
142142
AvifDecoder::AvifDecoder() {
143143
m_buf_supported = true;
144144
channels_ = 0;
145-
decoder_ = avifDecoderCreate();
146-
decoder_->strictFlags = AVIF_STRICT_DISABLED;
145+
decoder_ = nullptr;
147146
}
148147

149148
AvifDecoder::~AvifDecoder() {
@@ -181,6 +180,11 @@ bool AvifDecoder::checkSignature(const String &signature) const {
181180
ImageDecoder AvifDecoder::newDecoder() const { return makePtr<AvifDecoder>(); }
182181

183182
bool AvifDecoder::readHeader() {
183+
if (decoder_)
184+
return true;
185+
186+
decoder_ = avifDecoderCreate();
187+
decoder_->strictFlags = AVIF_STRICT_DISABLED;
184188
if (!m_buf.empty()) {
185189
CV_Assert(m_buf.type() == CV_8UC1);
186190
CV_Assert(m_buf.rows == 1);

modules/imgcodecs/test/test_avif.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,20 @@ TEST_P(Imgcodecs_Avif_Animation_WriteDecodeSuite, encode_decode) {
337337
std::vector<unsigned char> buf(size);
338338
EXPECT_TRUE(file.read(reinterpret_cast<char*>(buf.data()), size));
339339
file.close();
340-
EXPECT_EQ(0, remove(output.c_str()));
341340
std::vector<cv::Mat> anim;
342341
ASSERT_TRUE(cv::imdecodemulti(buf, imread_mode_, anim));
343342

344343
ValidateRead(anim_original, anim);
344+
345+
if (imread_mode_ == IMREAD_UNCHANGED) {
346+
ImageCollection collection(output, IMREAD_UNCHANGED);
347+
anim.clear();
348+
for (auto&& i : collection)
349+
anim.push_back(i);
350+
ValidateRead(anim_original, anim);
351+
}
352+
353+
EXPECT_EQ(0, remove(output.c_str()));
345354
}
346355

347356
INSTANTIATE_TEST_CASE_P(

0 commit comments

Comments
 (0)