Merge pull request #24754 from FantasqueX:refine-png-version-parsing

Refine logic of parsing PNG version
pull/24771/head
Alexander Smorkalov 1 year ago committed by GitHub
commit d9d402916a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CMakeLists.txt
  2. 18
      cmake/OpenCVFindLibsGrfmt.cmake
  3. 8
      cmake/OpenCVUtils.cmake
  4. 3
      cmake/templates/cvconfig.h.in
  5. 4
      modules/imgcodecs/src/grfmt_png.cpp

@ -1406,7 +1406,7 @@ if(WITH_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})")
status(" PNG:" PNG_FOUND THEN "${PNG_LIBRARY} (ver ${PNG_VERSION_STRING})" ELSE "build (ver ${PNG_VERSION_STRING})")
endif()
if(WITH_TIFF OR HAVE_TIFF)

@ -34,7 +34,7 @@ if(NOT ZLIB_FOUND)
set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
ocv_parse_header_version(ZLIB "${${ZLIB_LIBRARY}_SOURCE_DIR}/zlib.h")
ocv_parse_header_version(ZLIB "${${ZLIB_LIBRARY}_SOURCE_DIR}/zlib.h" ZLIB_VERSION)
endif()
# --- libavif (optional) ---
@ -273,31 +273,21 @@ if(NOT HAVE_SPNG AND WITH_PNG)
ocv_clear_vars(PNG_FOUND)
else()
ocv_clear_internal_cache_vars(PNG_LIBRARY PNG_INCLUDE_DIR)
include(FindPNG)
if(PNG_FOUND)
include(CheckIncludeFile)
check_include_file("${PNG_PNG_INCLUDE_DIR}/libpng/png.h" HAVE_LIBPNG_PNG_H)
if(HAVE_LIBPNG_PNG_H)
ocv_parse_header("${PNG_PNG_INCLUDE_DIR}/libpng/png.h" PNG_VERSION_LINES PNG_LIBPNG_VER_MAJOR PNG_LIBPNG_VER_MINOR PNG_LIBPNG_VER_RELEASE)
else()
ocv_parse_header("${PNG_PNG_INCLUDE_DIR}/png.h" PNG_VERSION_LINES PNG_LIBPNG_VER_MAJOR PNG_LIBPNG_VER_MINOR PNG_LIBPNG_VER_RELEASE)
endif()
endif()
find_package(PNG QUIET)
endif()
if(NOT PNG_FOUND)
ocv_clear_vars(PNG_LIBRARY PNG_LIBRARIES PNG_INCLUDE_DIR PNG_PNG_INCLUDE_DIR HAVE_LIBPNG_PNG_H PNG_DEFINITIONS)
ocv_clear_vars(PNG_LIBRARY PNG_LIBRARIES PNG_INCLUDE_DIR PNG_DEFINITIONS)
set(PNG_LIBRARY libpng CACHE INTERNAL "")
set(PNG_LIBRARIES ${PNG_LIBRARY})
add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/libpng")
set(PNG_INCLUDE_DIR "${${PNG_LIBRARY}_SOURCE_DIR}" CACHE INTERNAL "")
set(PNG_DEFINITIONS "")
ocv_parse_header("${PNG_INCLUDE_DIR}/png.h" PNG_VERSION_LINES PNG_LIBPNG_VER_MAJOR PNG_LIBPNG_VER_MINOR PNG_LIBPNG_VER_RELEASE)
ocv_parse_header_version(PNG "${PNG_INCLUDE_DIR}/png.h" PNG_LIBPNG_VER_STRING)
endif()
set(HAVE_PNG YES)
set(PNG_VERSION "${PNG_LIBPNG_VER_MAJOR}.${PNG_LIBPNG_VER_MINOR}.${PNG_LIBPNG_VER_RELEASE}")
endif()

@ -1430,15 +1430,15 @@ macro(ocv_parse_header2 LIBNAME HDR_PATH VARNAME)
endif()
endmacro()
# set ${LIBNAME}_VERSION_STRING to ${LIBNAME}_VERSION without quotes
macro(ocv_parse_header_version LIBNAME HDR_PATH)
# set ${LIBNAME}_VERSION_STRING to ${LIBVER} without quotes
macro(ocv_parse_header_version LIBNAME HDR_PATH LIBVER)
ocv_clear_vars(${LIBNAME}_VERSION_STRING)
set(${LIBNAME}_H "")
if(EXISTS "${HDR_PATH}")
file(STRINGS "${HDR_PATH}" ${LIBNAME}_H REGEX "^#define[ \t]+${LIBNAME}_VERSION[ \t]+\"[^\"]*\".*$" LIMIT_COUNT 1)
file(STRINGS "${HDR_PATH}" ${LIBNAME}_H REGEX "^#define[ \t]+${LIBVER}[ \t]+\"[^\"]*\".*$" LIMIT_COUNT 1)
endif()
if(${LIBNAME}_H)
string(REGEX REPLACE "^.*[ \t]${LIBNAME}_VERSION[ \t]+\"([0-9\.]+)\"$" "\\1" ${LIBNAME}_VERSION_STRING "${${LIBNAME}_H}")
string(REGEX REPLACE "^.*[ \t]${LIBVER}[ \t]+\"([0-9\.]+)\"$" "\\1" ${LIBNAME}_VERSION_STRING "${${LIBNAME}_H}")
endif()
endmacro()

@ -78,9 +78,6 @@
/* IJG JPEG codec */
#cmakedefine HAVE_JPEG
/* libpng/png.h needs to be included */
#cmakedefine HAVE_LIBPNG_PNG_H
/* GDCM DICOM codec */
#cmakedefine HAVE_GDCM

@ -58,11 +58,7 @@
# define _FILE_OFFSET_BITS 0
#endif
#ifdef HAVE_LIBPNG_PNG_H
#include <libpng/png.h>
#else
#include <png.h>
#endif
#include <zlib.h>
#include "grfmt_png.hpp"

Loading…
Cancel
Save