Merge pull request #24718 from asmorkalov/as/system_spng

Add support for external libspng. #24718

Fixes https://github.com/opencv/opencv/issues/24683
Related patch to libspng: https://github.com/randy408/libspng/pull/264

### 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
This commit is contained in:
Alexander Smorkalov 2023-12-20 13:05:09 +03:00 committed by GitHub
parent 3e6dcdc0a4
commit c92815238e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 13 deletions

View File

@ -1399,12 +1399,14 @@ if(WITH_AVIF OR HAVE_AVIF)
endif()
endif()
if(WITH_PNG OR HAVE_PNG OR WITH_SPNG)
if(WITH_SPNG)
if(WITH_SPNG)
if(BUILD_SPNG)
status(" PNG:" "build-${SPNG_LIBRARY} (ver ${SPNG_VERSION})")
else()
status(" PNG:" PNG_FOUND THEN "${PNG_LIBRARY} (ver ${PNG_VERSION})" ELSE "build (ver ${PNG_VERSION})")
elseif(HAVE_SPNG)
status(" PNG:" "${SPNG_LIBRARY} (ver ${SPNG_VERSION})")
endif()
elseif(WITH_PNG OR HAVE_PNG)
status(" PNG:" PNG_FOUND THEN "${PNG_LIBRARY} (ver ${PNG_VERSION})" ELSE "build (ver ${PNG_VERSION})")
endif()
if(WITH_TIFF OR HAVE_TIFF)

View File

@ -232,16 +232,38 @@ if(WITH_JASPER AND NOT HAVE_OPENJPEG)
endif()
if(WITH_SPNG)
set(SPNG_LIBRARY libspng CACHE INTERNAL "")
set(SPNG_LIBRARIES ${SPNG_LIBRARY})
add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libspng")
set(SPNG_INCLUDE_DIR "${${SPNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
set(SPNG_DEFINITIONS "")
ocv_parse_header("${SPNG_INCLUDE_DIR}/spng.h" SPNG_VERSION_LINES SPNG_VERSION_MAJOR SPNG_VERSION_MINOR SPNG_VERSION_PATCH)
if(BUILD_SPNG)
ocv_clear_vars(PNG_FOUND)
else()
# CMakeConfig bug in SPNG, include is missing there in version 0.7.4 and older
# See https://github.com/randy408/libspng/pull/264
include(CMakeFindDependencyMacro)
find_package(SPNG QUIET)
if(SPNG_FOUND)
set(SPNG_LIBRARY "spng::spng" CACHE INTERNAL "")
set(SPNG_LIBRARIES ${SPNG_LIBRARY})
else()
if(PkgConfig_FOUND)
pkg_check_modules(SPNG QUIET spng)
endif()
endif()
if(SPNG_FOUND)
set(HAVE_SPNG YES)
message(STATUS "imgcodecs: PNG codec will use SPNG, version: ${SPNG_VERSION}")
endif()
endif()
if(NOT SPNG_FOUND)
set(SPNG_LIBRARY libspng CACHE INTERNAL "")
set(SPNG_LIBRARIES ${SPNG_LIBRARY})
add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libspng")
set(SPNG_INCLUDE_DIR "${${SPNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
set(SPNG_DEFINITIONS "")
ocv_parse_header("${SPNG_INCLUDE_DIR}/spng.h" SPNG_VERSION_LINES SPNG_VERSION_MAJOR SPNG_VERSION_MINOR SPNG_VERSION_PATCH)
set(HAVE_SPNG YES)
set(SPNG_VERSION "${SPNG_VERSION_MAJOR}.${SPNG_VERSION_MINOR}.${SPNG_VERSION_PATCH}")
message(STATUS "imgcodecs: PNG codec will use SPNG, version: ${SPNG_VERSION} ")
set(HAVE_SPNG YES)
set(SPNG_VERSION "${SPNG_VERSION_MAJOR}.${SPNG_VERSION_MINOR}.${SPNG_VERSION_PATCH}")
message(STATUS "imgcodecs: PNG codec will use SPNG, version: ${SPNG_VERSION} ")
endif()
endif()
# --- libpng (optional, should be searched after zlib) ---