Skip to content

Commit

Permalink
Merge pull request opencv#24718 from asmorkalov/as/system_spng
Browse files Browse the repository at this point in the history
Add support for external libspng. opencv#24718

Fixes opencv#24683
Related patch to libspng: randy408/libspng#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
  • Loading branch information
asmorkalov authored Dec 20, 2023
1 parent 3e6dcdc commit c928152
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 32 additions & 10 deletions cmake/OpenCVFindLibsGrfmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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} ")
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} ")
endif()
endif()

# --- libpng (optional, should be searched after zlib) ---
Expand Down

0 comments on commit c928152

Please sign in to comment.