Merge pull request #26298 from sturkmen72:avif

Proposed solution for the issue 26297 #26298

closes #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
pull/23467/merge
Suleyman TURKMEN 1 month ago committed by GitHub
parent 1909ac8650
commit 8e5dbc03fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      CMakeLists.txt
  2. 8
      modules/imgcodecs/src/grfmt_avif.cpp
  3. 11
      modules/imgcodecs/test/test_avif.cpp

@ -216,7 +216,7 @@ OCV_OPTION(WITH_1394 "Include IEEE1394 support" OFF
OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/visionOS/Mac)" ON
VISIBLE_IF APPLE
VERIFY HAVE_AVFOUNDATION)
OCV_OPTION(WITH_AVIF "Enable AVIF support" OFF
OCV_OPTION(WITH_AVIF "Enable AVIF support" ON
VERIFY HAVE_AVIF)
OCV_OPTION(WITH_CAP_IOS "Enable iOS video capture" ON
VISIBLE_IF IOS

@ -142,8 +142,7 @@ static constexpr size_t kAvifSignatureSize = 500;
AvifDecoder::AvifDecoder() {
m_buf_supported = true;
channels_ = 0;
decoder_ = avifDecoderCreate();
decoder_->strictFlags = AVIF_STRICT_DISABLED;
decoder_ = nullptr;
}
AvifDecoder::~AvifDecoder() {
@ -181,6 +180,11 @@ bool AvifDecoder::checkSignature(const String &signature) const {
ImageDecoder AvifDecoder::newDecoder() const { return makePtr<AvifDecoder>(); }
bool AvifDecoder::readHeader() {
if (decoder_)
return true;
decoder_ = avifDecoderCreate();
decoder_->strictFlags = AVIF_STRICT_DISABLED;
if (!m_buf.empty()) {
CV_Assert(m_buf.type() == CV_8UC1);
CV_Assert(m_buf.rows == 1);

@ -337,11 +337,20 @@ TEST_P(Imgcodecs_Avif_Animation_WriteDecodeSuite, encode_decode) {
std::vector<unsigned char> buf(size);
EXPECT_TRUE(file.read(reinterpret_cast<char*>(buf.data()), size));
file.close();
EXPECT_EQ(0, remove(output.c_str()));
std::vector<cv::Mat> anim;
ASSERT_TRUE(cv::imdecodemulti(buf, imread_mode_, anim));
ValidateRead(anim_original, anim);
if (imread_mode_ == IMREAD_UNCHANGED) {
ImageCollection collection(output, IMREAD_UNCHANGED);
anim.clear();
for (auto&& i : collection)
anim.push_back(i);
ValidateRead(anim_original, anim);
}
EXPECT_EQ(0, remove(output.c_str()));
}
INSTANTIATE_TEST_CASE_P(

Loading…
Cancel
Save