Skip to content

Fixed AVIF linkage on Windows#26762

Merged
asmorkalov merged 2 commits intoopencv:4.xfrom
sturkmen72:avif_cmake
Jan 31, 2025
Merged

Fixed AVIF linkage on Windows#26762
asmorkalov merged 2 commits intoopencv:4.xfrom
sturkmen72:avif_cmake

Conversation

@sturkmen72
Copy link
Copy Markdown
Contributor

Closes #26747

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • 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

@sturkmen72
Copy link
Copy Markdown
Contributor Author

sturkmen72 commented Jan 13, 2025

to test the PR i compiled libavif on windows using

git clone -b v1.1.1 https://github.com/AOMediaCodec/libavif.git
cmake -S libavif -B libavif/build -DBUILD_SHARED_LIBS=ON -DAVIF_CODEC_AOM=LOCAL -DAVIF_LIBYUV=LOCAL -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_JPEG=OFF -DAVIF_ZLIBPNG=OFF -DAVIF_BUILD_APPS=OFF
cmake --build libavif/build --config Release --target install
set PATH=%PATH%;C:\Program Files (x86)\libavif

the output of cmake when compiling OpenCV

--   Media I/O:
--     ZLib-Ng:                     build (zlib ver 1.3.1.zlib-ng, zlib-ng ver 2.2.1)
--     JPEG:                        build-libjpeg-turbo (ver 3.0.3-70)
--       SIMD Support Request:      YES
--       SIMD Support:              YES
--     WEBP:                        build (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
--     AVIF:                        avif (ver 1.1.1)
--     PNG:                         build (ver 1.6.43)
--       SIMD Support Request:      YES
--       SIMD Support:              YES (Intel SSE)
--     JPEG XL:                     NO
--     JPEG 2000:                   build (ver 2.5.0)
--     GIF:                         YES
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
git clone -b v1.1.1 https://github.com/AOMediaCodec/libavif.git
cmake -S libavif -B libavif/build -DBUILD_SHARED_LIBS=OFF -DAVIF_CODEC_AOM=LOCAL -DAVIF_LIBYUV=LOCAL -DAVIF_LIBSHARPYUV=LOCAL -DAVIF_JPEG=OFF -DAVIF_ZLIBPNG=OFF -DAVIF_BUILD_APPS=OFF
cmake --build libavif/build --config Release --target install
set PATH=%PATH%;C:\Program Files (x86)\libavif
--   Media I/O:
--     ZLib-Ng:                     build (zlib ver 1.3.1.zlib-ng, zlib-ng ver 2.2.1)
--     JPEG:                        build-libjpeg-turbo (ver 3.0.3-70)
--       SIMD Support Request:      YES
--       SIMD Support:              YES
--     WEBP:                        build (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
--     AVIF:                        C:/Program Files (x86)/libavif/lib/avif.lib
--     PNG:                         build (ver 1.6.43)
--       SIMD Support Request:      YES
--       SIMD Support:              YES (Intel SSE)
--     JPEG XL:                     NO
--     JPEG 2000:                   build (ver 2.5.0)
--     GIF:                         YES
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES

also tested with with loaded libs by vcpkg

--   Media I/O:
--     ZLib-Ng:                     build (zlib ver 1.3.1.zlib-ng, zlib-ng ver 2.2.1)
--     JPEG:                        build-libjpeg-turbo (ver 3.0.3-70)
--       SIMD Support Request:      YES
--       SIMD Support:              YES
--     WEBP:                        build (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
--     AVIF:                        yuv unofficial::aom $<$<NOT:$<CONFIG:DEBUG>>:C:/GitHub/vcpkg/installed/x64-windows-static/lib/dav1d.lib> $<$<CONFIG:DEBUG>:C:/GitHub/vcpkg/installed/x64-windows-static/debug/lib/dav1d.lib> avif (ver 1.1.1)
--     PNG:                         build (ver 1.6.43)
--       SIMD Support Request:      YES
--       SIMD Support:              YES (Intel SSE)
--     JPEG XL:                     C:/GitHub/vcpkg/installed/x64-windows-static/lib/jxl.lib C:/GitHub/vcpkg/installed/x64-windows-static/lib/jxl_cms.lib C:/GitHub/vcpkg/installed/x64-windows-static/lib/lcms2.lib C:/GitHub/vcpkg/installed/x64-windows-static/lib/jxl_threads.lib C:/GitHub/vcpkg/installed/x64-windows-static/lib/brotlidec.lib C:/GitHub/vcpkg/installed/x64-windows-static/lib/brotlienc.lib C:/GitHub/vcpkg/installed/x64-windows-static/lib/brotlicommon.lib C:/GitHub/vcpkg/installed/x64-windows-static/lib/hwy.lib (ver 0.11.1)
--     JPEG 2000:                   build (ver 2.5.0)
--     GIF:                         YES
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES

@asmorkalov asmorkalov requested a review from vrabaud January 13, 2025 10:03
@asmorkalov asmorkalov added this to the 4.12.0 milestone Jan 13, 2025
Copy link
Copy Markdown
Contributor

@vrabaud vrabaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx !

@asmorkalov
Copy link
Copy Markdown
Contributor

I find the solution as dangerous. In case if I want to use custom libavif instead of system one it may lead to libraries mix. I support Maksim's proposal from the original ticket to use target name if it's avaliable. Also you need to take a look on IMPORTED_LOCATION property: https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_LOCATION.html. Most probably it's right way to go as hot fix.

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@asmorkalov let me work on this a bit more

@sturkmen72 sturkmen72 marked this pull request as draft January 14, 2025 09:16
@sturkmen72 sturkmen72 force-pushed the avif_cmake branch 3 times, most recently from bc5a185 to c6b76bc Compare January 21, 2025 14:43
@sturkmen72 sturkmen72 marked this pull request as ready for review January 26, 2025 21:32
@sturkmen72 sturkmen72 marked this pull request as draft January 27, 2025 13:19
@sturkmen72
Copy link
Copy Markdown
Contributor Author

@asmorkalov please review. I know it's not perfect but it's all I can do.

@sturkmen72 sturkmen72 marked this pull request as ready for review January 29, 2025 05:42
@hmaarrfk
Copy link
Copy Markdown
Contributor

This seems to resolve the issues at conda-forge

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@mshabunin @hmaarrfk what about updating also OpenCVFindWebP.cmake in this PR

#=============================================================================
# Find WebP library
#=============================================================================
# Find the native WebP headers and libraries.
#
#  WEBP_INCLUDE_DIRS - where to find webp/decode.h, etc.
#  WEBP_LIBRARIES    - List of libraries when using webp.
#  WEBP_FOUND        - True if webp is found.
#=============================================================================

# Look for the header file.

unset(WEBP_FOUND)

find_package(WebP QUIET)

if(TARGET WebP::webp AND TARGET WebP::webpdemux AND TARGET WebP::libwebpmux)
    MARK_AS_ADVANCED(WEBP_INCLUDE_DIR)
    MARK_AS_ADVANCED(WEBP_LIBRARY)

    SET(WEBP_FOUND TRUE)
    SET(WEBP_LIBRARY WebP)
    SET(WEBP_INCLUDE_DIR)
else()
    MARK_AS_ADVANCED(WEBP_INCLUDE_DIR)

    # Look for the library.
    FIND_LIBRARY(WEBP_LIBRARY NAMES webp)
    FIND_LIBRARY(WEBP_MUX_LIBRARY NAMES webpmux)
    FIND_LIBRARY(WEBP_DEMUX_LIBRARY NAMES webpdemux)

    # handle the QUIETLY and REQUIRED arguments and set WEBP_FOUND to TRUE if
    # all listed variables are TRUE
    INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
    FIND_PACKAGE_HANDLE_STANDARD_ARGS(WebP DEFAULT_MSG WEBP_LIBRARY WEBP_INCLUDE_DIR)

    SET(WEBP_LIBRARIES ${WEBP_LIBRARY} ${WEBP_MUX_LIBRARY} ${WEBP_DEMUX_LIBRARY})
    SET(WEBP_INCLUDE_DIRS ${WEBP_INCLUDE_DIR})
endif()

@hmaarrfk
Copy link
Copy Markdown
Contributor

hmaarrfk commented Jan 30, 2025

@mshabunin @hmaarrfk what about updating also OpenCVFindWebP.cmake in this PR

I strongly suggest you don't grow the scope of this PR to ensure it gets through.

However, the exact workflow is up to the OpenCV team. I'm just an onlooker.

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@hmaarrfk OK. I noticed that in your build process, only webp was not found

--   Media I/O: 
--     ZLib:                        D:/bld/libopencv_1738263879095/_h_env/Library/lib/z.lib (ver 1.3.1)
--     JPEG:                        D:/bld/libopencv_1738263879095/_h_env/Library/lib/jpeg.lib (ver 80)
--     WEBP:                        build (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
--     AVIF:                        avif (ver 1.1.1)
--     PNG:                         D:/bld/libopencv_1738263879095/_h_env/Library/lib/libpng.lib (ver 1.6.46)
--     TIFF:                        (ver 42 / 4.7.0)
--     JPEG 2000:                   D:/bld/libopencv_1738263879095/_h_env/Library/lib/jasper.lib (ver 4.2.4)
--     OpenEXR:                     OpenEXR::OpenEXR (ver 3.3.2)
--     GIF:                         NO
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES

@hmaarrfk
Copy link
Copy Markdown
Contributor

Thank you. i'll investigate and report back.

hmaarrfk added a commit to hmaarrfk/opencv that referenced this pull request Jan 30, 2025
@sturkmen72  feel free to fold into opencv#26762 but I would just like a dedicated patch to try.
@asmorkalov asmorkalov changed the title Proposed solution for Issue 26747 Fixed AVIF linkage on Windows Jan 31, 2025
@asmorkalov asmorkalov self-assigned this Jan 31, 2025
@asmorkalov asmorkalov merged commit fbd2105 into opencv:4.x Jan 31, 2025
29 of 30 checks passed
@sturkmen72 sturkmen72 deleted the avif_cmake branch January 31, 2025 15:12
@asmorkalov asmorkalov mentioned this pull request Feb 19, 2025
NanQin555 pushed a commit to NanQin555/opencv that referenced this pull request Feb 24, 2025
Fixed AVIF linkage on Windows opencv#26762 

Closes opencv#26747

### 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
- [ ] 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
NanQin555 pushed a commit to NanQin555/opencv that referenced this pull request Feb 24, 2025
@sturkmen72  feel free to fold into opencv#26762 but I would just like a dedicated patch to try.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with Linking avif in Visual Studio

5 participants